Beispiel #1
0
    def _updateViewRotable(self):
        simg = self.img
        if simg.ndim == 2:
            simg = [simg]

        for img, plot, vplot, rplot in zip(simg, self.plots,
                                           self.stdPlots, self.rmsPlots):

            data, coords = self.getArrayRegion(img.view(np.ndarray),
                                               self.master.imageItem, axes=(
                                                   0, 1),
                                               returnMappedCoords=True)
            dataorig = data  # np.copy(data)
            if data is not None:
                while data.ndim > 1:
                    # average rectangle to line
                    data = data.mean(axis=1)
                while coords.ndim > 2:
                    coords = coords[:, :, 0]
                coords = coords - coords[:, 0, np.newaxis]
                xvals = (coords**2).sum(axis=0) ** 0.5
                plot.setData(y=data, x=xvals)

            if vplot:
                vplot.setData(y=dataorig.var(axis=1),
                              x=xvals,
                              symbol=self.getSymbol())
            if rplot:
                rplot.setData(y=RMS(dataorig, axis=1),
                              x=xvals,
                              symbol=self.getSymbol())

        p = self.boundingRect().bottomLeft() + self.pos()
        self.text.setPos(p)
Beispiel #2
0
    def updateView(self):
        x_vals = self.tool.display.stack.values
        data = []
        # DATA

        def getData(img):
            d = self.getArrayRegion(img.view(np.ndarray),
                                    self.master.imageItem, axes=(0, 1))
            if d is not None:
                data.append(d)

        if self.img.ndim > 2:
            for layer in self.img:
                getData(layer)
        else:
            getData(self.img)

        # MEAN
        mean = [d.mean() for d in data]
        self.plot.setData(y=mean,
                          x=x_vals,
                          symbol=self.getSymbol())
        # STD
        if self.stdPlot:
            self.stdPlot.setData(y=[d.std() for d in data],
                                 x=x_vals,
                                 symbol=self.getSymbol())
        # RMS
        if self.rmsPlot:
            self.rmsPlot.setData(y=[RMS(d) - m for d, m in zip(data, mean)],
                                 x=x_vals,
                                 symbol=self.getSymbol())
Beispiel #3
0
    def _updateViewStatic(self):
        # COORDS
        px, py = self.pos().x(), self.pos().y()
        r = self.boundingRect()
        x0, y0, x1, y1 = r.getCoords()
        x0 = max(0, int(round(x0 + px)))
        x1 = int(round(x1 + px))
        y0 = max(0, int(round(y0 + py)))
        y1 = int(round(y1 + py))
        # TEXT
        #self.text.setText('%s (%s,%s)-(%s,%s)' %(self.name(), x0,y0,x1,y1) )
        self.text.setPos(px, py)

        simg = self.img
        if simg.ndim == 2:
            simg = [simg]

        for img, plot, vplot, rplot in zip(simg, self.plots,
                                           self.stdPlots, self.rmsPlots):
            # DATA
            try:
                dataorig = img[y0:y1, x0:x1]
                if dataorig.dtype.kind == 'f' and np.any(np.sum(dataorig)):
                    mean = np.nanmean
                else:
                    mean = np.mean
                if dataorig.ndim == 3:  # color
                    data = mean(dataorig, axis=(self.av_dir, 2))
                else:
                    data = mean(dataorig,axis=self.av_dir)

                if self.av_dir == 1:
                    xvals = np.linspace(x0, x1, len(data))
                else:
                    xvals = np.linspace(y0, y1, len(data))

                plot.setData(y=data, x=xvals)

                if vplot:
                    vplot.setData(y=dataorig.var(axis=self.av_dir),
                                  x=xvals,
                                  symbol=self.getSymbol())
                if rplot:
                    rplot.setData(y=RMS(dataorig, axis=self.av_dir),
                                  x=xvals,
                                  symbol=self.getSymbol())

            except (IndexError, ValueError):  # out out bounds
                pass
Beispiel #4
0
    def activate(self):
        img = self.display.widget.image

        if self.pLimitRange.value():
            mn, mx = self.pMin.value(), self.pMax.value()
        else:
            mn, mx = np.min(img[0]), np.max(img[0])

        bins = np.linspace(mn, mx, self.pNPlots.value() + 1)
        plots = []
        var_plots = []
        rms_plots = []
        names = []
        xvals = self.display.stack.values
        for start, stop in zip(bins[:-1], bins[1:]):
            # get positions from first image:
            indexes = np.logical_and(img[0] >= start, img[0] <= stop)
            nPx = np.sum(indexes)
            if not nPx:
                # no values found in given range / one one element is True
                continue
            yvals = []
            var_yvals = []
            rms_yvals = []
            names.append(
                '(%s) %s - %s' %
                (nPx, round(
                    start, 2), round(
                    stop, 2)))

            # prevent stack overflow with float16 (with returns inf):
            #dtype = np.float32 if img[0].dtype==np.float16 else None

            for layer in img:
                # CALCULATE PLOT VALUES:
                mean = np.mean(layer[indexes])
                yvals.append(mean)
                if self.pVar.value():
                    var_yvals.append(np.var(layer[indexes]))
                if self.pRMS.value():
                    rms_yvals.append(RMS(layer[indexes]) - mean)
            # APPEND PLOT VALUES:
            plots.append((xvals, yvals))
            var_plots.append((xvals, var_yvals))
            rms_plots.append((xvals, rms_yvals))

        # CREATE DISPLAYS:
        self.display.workspace.addDisplay(
            origin=self.display,
            axes=self.display.axes.copy(('stack', 0)),
            names=names,
            data=plots,
            title='Averaged trend')

        if self.pVar.value():
            self.display.workspace.addDisplay(
                origin=self.display,
                axes=self.display.axes.copy(('stack', 0)),
                names=names,
                data=var_plots,
                title='Variance trend ')

        if self.pRMS.value():
            self.display.workspace.addDisplay(
                origin=self.display,
                axes=self.display.axes.copy(('stack', 0)),
                names=names,
                data=rms_plots,
                title='RMS trend - %s')