Esempio n. 1
0
    def _analyse_image(self):

        if self._roi is not None:
            try:
                x, y, w, h, = self._roi
                roi_array = self._last_frame[x:x + w, y:y + h]
            except Exception as err:
                roi_array = self._last_frame
                x, y = 0, 0
        else:
            roi_array = self._last_frame
            x, y = 0, 0

        self.sum = np.sum(roi_array)

        try:
            roi_extrema = scipymeasure.extrema(roi_array)
        except Exception as err:
            roi_extrema = (0, 0, (0, 0), (0, 0))
        self.max_i = roi_extrema[1]
        self.max_x = roi_extrema[3][0] + x
        self.max_y = roi_extrema[3][1] + y

        try:
            roi_com = scipymeasure.center_of_mass(roi_array)
        except Exception as err:
            roi_com = (0, 0)

        self.com_x = roi_com[0] + x
        self.com_y = roi_com[1] + y

        self.fwhm_x = FWHM(np.sum(roi_array, axis=0))
        self.fwhm_y = FWHM(np.sum(roi_array, axis=1))
Esempio n. 2
0
 def getLMRectStats(self, rect):
     xx1, xx2, yy1, yy2 = self._lmRectToPix(rect)
     if xx1 is not None:
         subset = self.image.image()[xx1:xx2, yy1:yy2]
         subset, mask = self.image.optimalRavel(subset)
         mmin, mmax = measurements.extrema(subset, labels=mask, index=None if mask is None else False)[:2]
         mean = measurements.mean(subset, labels=mask, index=None if mask is None else False)
         std = measurements.standard_deviation(subset, labels=mask, index=None if mask is None else False)
         ssum = measurements.sum(subset, labels=mask, index=None if mask is None else False)
         return xx1, xx2, yy1, yy2, mmin, mmax, mean, std, ssum, subset.size
     return None
Esempio n. 3
0
 def dataMinMax (self):
   if not self._dataminmax:
     rdata,rmask = self.optimalRavel(self._data);
     dprint(3,"computing data min/max");
     try:
       self._dataminmax = measurements.extrema(rdata,labels=rmask,index=None if rmask is None else False);
     except:
       # when all data is masked, some versions of extrema() throw an exception
       self._dataminmax = numpy.nan,numpy.nan;
     dprint(3,self._dataminmax);
   return self._dataminmax;
Esempio n. 4
0
 def imageMinMax(self):
     if not self._imgminmax:
         dprint(3, "computing image min/max")
         rdata, rmask = self.optimalRavel(self._image)
         try:
             self._imgminmax = measurements.extrema(rdata, labels=rmask, index=None if rmask is None else False)[:2]
         except:
             # when all data is masked, some versions of extrema() throw an exception
             self._imgminmax = numpy.nan, numpy.nan
         dprint(3, self._imgminmax)
     return self._imgminmax
Esempio n. 5
0
 def dataMinMax(self):
     if not self._dataminmax:
         rdata, rmask = self.optimalRavel(self._data)
         dprint(3, "computing data min/max")
         try:
             self._dataminmax = measurements.extrema(rdata, labels=rmask, index=None if rmask is None else False)
         except:
             # when all data is masked, some versions of extrema() throw an exception
             self._dataminmax = numpy.nan, numpy.nan
         dprint(3, self._dataminmax)
     return self._dataminmax
Esempio n. 6
0
 def _resetDisplaySubset (self,subset,desc,range=None,set_display_range=True,write_config=True,subset_type=None):
   dprint(4,"setting display subset");
   self._displaydata = subset;
   self._displaydata_desc = desc;
   self._displaydata_minmax = range = range or measurements.extrema(subset)[:2];
   self._displaydata_type = subset_type;
   dprint(4,"range set");
   self.image.intensityMap().setDataSubset(self._displaydata,minmax=range);
   self.image.setIntensityMap(emit=False);
   self.emit(SIGNAL("dataSubsetChanged"),subset,range,desc,subset_type);
   if set_display_range:
     self.setDisplayRange(write_config=write_config,*range);
Esempio n. 7
0
 def _resetDisplaySubset(self, subset, desc, range=None, set_display_range=True, write_config=True,
                         subset_type=None):
     dprint(4, "setting display subset")
     self._displaydata = subset
     self._displaydata_desc = desc
     self._displaydata_minmax = range = range or measurements.extrema(subset)[:2]
     self._displaydata_type = subset_type
     dprint(4, "range set")
     self.image.intensityMap().setDataSubset(self._displaydata, minmax=range)
     self.image.setIntensityMap(emit=False)
     self.emit(SIGNAL("dataSubsetChanged"), subset, range, desc, subset_type)
     if set_display_range:
         self.setDisplayRange(write_config=write_config, *range)
Esempio n. 8
0
 def _updateHistogram (self,hmin=None,hmax=None):
   """Recomputes histogram. If no arguments, computes full histogram for
   data subset. If hmin/hmax is specified, computes zoomed-in histogram.""";
   busy = BusyIndicator();
   self._prev_range = self._display_range;
   dmin,dmax = self._subset_range;
   hmin0,hmax0 = dmin,dmax;
   if hmin0 >= hmax0:
     hmax0 = hmin0+1;
   subset,mask = self.image.optimalRavel(self._subset);
   # compute full-subset hi-res histogram, if we don't have one (for percentile stats)
   if self._hist_hires is None:
     dprint(1,"computing histogram for full subset range",hmin0,hmax0);
     self._hist_hires = measurements.histogram(subset,hmin0,hmax0,self.NumHistBinsHi,labels=mask,index=None if mask is None else False);
     self._hist_bins_hires = hmin0 + (hmax0-hmin0)*(numpy.arange(self.NumHistBinsHi)+0.5)/float(self.NumHistBinsHi);
     self._hist_binsize_hires =  (hmax0-hmin0)/self.NumHistBins;
   # if hist limits not specified, then compute lo-res histogram based on the hi-res one
   if hmin is None:
     hmin,hmax = hmin0,hmax0;
     # downsample to low-res histogram
     self._hist = self._hist_hires.reshape((self.NumHistBins,self.NumHistBinsHi/self.NumHistBins)).sum(1);
   else:
     # zoomed-in low-res histogram
     # bracket limits at subset range
     hmin,hmax = max(hmin,dmin),min(hmax,dmax);
     if hmin >= hmax:
       hmax = hmin+1;
     dprint(1,"computing histogram for",self._subset.shape,self._subset.dtype,hmin,hmax);
     self._hist = measurements.histogram(subset,hmin,hmax,self.NumHistBins,labels=mask,index=None if mask is None else False);
   dprint(1,"histogram computed");
   # compute bins
   self._itf_bins = hmin + (hmax-hmin)*(numpy.arange(self.NumItfBins))/(float(self.NumItfBins)-1);
   self._hist_bins = hmin + (hmax-hmin)*(numpy.arange(self.NumHistBins)+0.5)/float(self.NumHistBins);
   # histogram range and position of peak
   self._hist_range = hmin,hmax;
   self._hist_min,self._hist_max,self._hist_imin,self._hist_imax = measurements.extrema(self._hist);
   self._hist_peak = self._hist_bins[self._hist_imax];
   # set controls accordingly
   if dmin >= dmax:
     dmax = dmin+1;
   zoom = math.log10((dmax-dmin)/(hmax-hmin));
   self._whistzoom.setValue(zoom);
   self._whistunzoom.setEnabled(zoom>0);
   self._whistzoomout.setEnabled(zoom>0);
   # reset scales
   self._histplot.setAxisScale(QwtPlot.xBottom,hmin,hmax);
   self._histplot.setAxisScale(QwtPlot.yRight,0,1+self.ColorBarHeight);
   # update curves
   # call _setHistLogScale() (with current setting) to update axis scales and set data
   self._setHistLogScale(self._ylogscale,replot=False);
   # set plot lines
   self._line_0.line.setData([0,0],[0,1]);
   self._line_0.marker.setValue(0,0);
   self._line_maxbin.line.setData([self._hist_peak,self._hist_peak],[0,1]);
   self._line_maxbin.marker.setValue(self._hist_peak,0);
   self._line_maxbin.setText(("max bin:"+DataValueFormat)%self._hist_peak);
   # set half-max line
   self._line_halfmax.line.setData(self._hist_range,[self._hist_max/2,self._hist_max/2]);
   self._line_halfmax.marker.setValue(hmin,self._hist_max/2);
   # update ITF
   self._updateITF();
Esempio n. 9
0
 def getDataRange(self, data):
     """Returns the set data range, or uses data min/max if it is not set"""
     # use data min/max if no explicit ranges are set
     return self.range or measurements.extrema(data)[:2]
Esempio n. 10
0
 def _updateHistogram(self, hmin=None, hmax=None):
     """Recomputes histogram. If no arguments, computes full histogram for
     data subset. If hmin/hmax is specified, computes zoomed-in histogram."""
     busy = BusyIndicator()
     self._prev_range = self._display_range
     dmin, dmax = self._subset_range
     hmin0, hmax0 = dmin, dmax
     if hmin0 >= hmax0:
         hmax0 = hmin0 + 1
     subset, mask = self.image.optimalRavel(self._subset)
     # compute full-subset hi-res histogram, if we don't have one (for percentile stats)
     if self._hist_hires is None:
         dprint(1, "computing histogram for full subset range", hmin0, hmax0)
         self._hist_hires = measurements.histogram(subset, hmin0, hmax0, self.NumHistBinsHi, labels=mask,
                                                   index=None if mask is None else False)
         self._hist_bins_hires = hmin0 + (hmax0 - hmin0) * (numpy.arange(self.NumHistBinsHi) + 0.5) / float(
             self.NumHistBinsHi)
         self._hist_binsize_hires = (hmax0 - hmin0) / self.NumHistBins
     # if hist limits not specified, then compute lo-res histogram based on the hi-res one
     if hmin is None:
         hmin, hmax = hmin0, hmax0
         # downsample to low-res histogram
         self._hist = self._hist_hires.reshape((self.NumHistBins, self.NumHistBinsHi / self.NumHistBins)).sum(1)
     else:
         # zoomed-in low-res histogram
         # bracket limits at subset range
         hmin, hmax = max(hmin, dmin), min(hmax, dmax)
         if hmin >= hmax:
             hmax = hmin + 1
         dprint(1, "computing histogram for", self._subset.shape, self._subset.dtype, hmin, hmax)
         self._hist = measurements.histogram(subset, hmin, hmax, self.NumHistBins, labels=mask,
                                             index=None if mask is None else False)
     dprint(1, "histogram computed")
     # compute bins
     self._itf_bins = hmin + (hmax - hmin) * (numpy.arange(self.NumItfBins)) / (float(self.NumItfBins) - 1)
     self._hist_bins = hmin + (hmax - hmin) * (numpy.arange(self.NumHistBins) + 0.5) / float(self.NumHistBins)
     # histogram range and position of peak
     self._hist_range = hmin, hmax
     self._hist_min, self._hist_max, self._hist_imin, self._hist_imax = measurements.extrema(self._hist)
     self._hist_peak = self._hist_bins[self._hist_imax]
     # set controls accordingly
     if dmin >= dmax:
         dmax = dmin + 1
     zoom = math.log10((dmax - dmin) / (hmax - hmin))
     self._whistzoom.setValue(zoom)
     self._whistunzoom.setEnabled(zoom > 0)
     self._whistzoomout.setEnabled(zoom > 0)
     # reset scales
     self._histplot.setAxisScale(QwtPlot.xBottom, hmin, hmax)
     self._histplot.setAxisScale(QwtPlot.yRight, 0, 1 + self.ColorBarHeight)
     # update curves
     # call _setHistLogScale() (with current setting) to update axis scales and set data
     self._setHistLogScale(self._ylogscale, replot=False)
     # set plot lines
     self._line_0.line.setData([0, 0], [0, 1])
     self._line_0.marker.setValue(0, 0)
     self._line_maxbin.line.setData([self._hist_peak, self._hist_peak], [0, 1])
     self._line_maxbin.marker.setValue(self._hist_peak, 0)
     self._line_maxbin.setText(("max bin:" + DataValueFormat) % self._hist_peak)
     # set half-max line
     self._line_halfmax.line.setData(self._hist_range, [self._hist_max / 2, self._hist_max / 2])
     self._line_halfmax.marker.setValue(hmin, self._hist_max / 2)
     # update ITF
     self._updateITF()
Esempio n. 11
0
 def getDataRange (self,data):
   """Returns the set data range, or uses data min/max if it is not set""";
   # use data min/max if no explicit ranges are set
   return self.range or measurements.extrema(data)[:2];