Exemplo n.º 1
0
    def run(self):

        self.signals.start.emit()
        localCorr = np.zeros(len(self.blocksInput))

        # Single-core code
        for i in np.arange(len(self.blocksInput)):
            rings = False
            block = self.blocksInput[i]
            blockS = self.blocksInputS[i]
            mask = self.blocksMask[i]
            # Block may be excluded from the analysis for two reasons.
            # Firstly, because the intensity for all its pixels may be
            # too low. Secondly, because the part of the block that
            # belongs toa neuron may be below an arbitrary 30% of the
            # block. We apply intensity threshold to smoothed data so we
            # don't catch tiny bright spots outside neurons
            neuronFrac = 1 - np.sum(mask) / np.size(mask)
            thres = self.meanS + self.intThr * self.stdS
            if np.any(blockS > thres) and neuronFrac > 0.25:
                output = tools.corrMethod(block, mask, *self.cArgs)
                angle, corrTheta, corrMax, theta, phase, rings = output
                # Store results
                localCorr[i] = corrMax
            else:
                localCorr[i] = np.nan

        localCorr = localCorr.reshape(*self.n)
        self.signals.done.emit(localCorr)
Exemplo n.º 2
0
    def ringFinder(self, show=True, batch=False):
        """RingFinder handles the input data, and then evaluates every subimg
        using the given algorithm which decides if there are rings or not.
        Subsequently gives the output data and plots it"""

        if self.corrButton.isChecked() or batch:

            self.corrResult.clear()
            self.ringResult.clear()

            # for each subimg, we apply the correlation method for ring finding
            intThr = np.float(self.intThresEdit.text())
            minLen = np.float(self.lineLengthEdit.text()) / self.pxSize
            thetaStep = np.float(self.thetaStepEdit.text())
            deltaTh = np.float(self.deltaThEdit.text())
            wvlen = np.float(self.wvlenEdit.text()) / self.pxSize
            sinPow = np.float(self.sinPowerEdit.text())
            cArgs = minLen, thetaStep, deltaTh, wvlen, sinPow

            # Single-core code
            self.localCorr = np.zeros(len(self.blocksInput))
            thres = self.meanS + intThr * self.stdS
            if not (self.testData):
                thres = thres * np.ones(self.blocksInput.shape)

            for i in np.arange(len(self.blocksInput)):
                block = self.blocksInput[i]
                blockS = self.blocksInputS[i]
                mask = self.blocksMask[i]
                # Block may be excluded from the analysis for two reasons.
                # Firstly, because the intensity for all its pixels may be
                # too low. Secondly, because the part of the block that
                # belongs toa neuron may be below an arbitrary 20% of the
                # block. We apply intensity threshold to smoothed data so we
                # don't catch tiny bright spots outside neurons
                neuronFrac = 1 - np.sum(mask) / np.size(mask)
                areaThres = 0.01 * float(self.minAreaEdit.text())
                if np.any(blockS > thres[i]) and neuronFrac > areaThres:
                    output = tools.corrMethod(block, mask, *cArgs)
                    angle, corrTheta, corrMax, theta, phase = output
                    # Store results
                    self.localCorr[i] = corrMax
                else:
                    self.localCorr[i] = np.nan

            self.localCorr = self.localCorr.reshape(*self.n)
            self.updateGUI(self.localCorr)

        else:
            self.corrResult.clear()
            self.ringResult.clear()
Exemplo n.º 3
0
    def corrMethodGUI(self):

        self.pCorr.clear()

        # We apply intensity threshold to smoothed data so we don't catch
        # tiny bright spots outside neurons
        thr = np.float(self.main.intThresEdit.text())
        if np.any(self.selectedS > self.selectedMean + thr * self.selectedStd):

            self.getDirection()

            # we apply the correlation method for ring finding for the
            # selected subimg
            minLen = np.float(self.main.lineLengthEdit.text()) / self.pxSize
            thStep = np.float(self.main.thetaStepEdit.text())
            deltaTh = np.float(self.main.deltaThEdit.text())
            wvlen = np.float(self.main.wvlenEdit.text()) / self.pxSize
            sinPow = np.float(self.main.sinPowerEdit.text())
            args = [self.selectedMask, minLen, thStep, deltaTh, wvlen, sinPow]
            output = tools.corrMethod(self.selected, *args, developer=True)
            self.th0, corrTheta, corrMax, thetaMax, phaseMax = output

            if np.all([self.th0, corrMax]) is not None:
                self.bestAxon = simAxon(imSize=self.subImgSize,
                                        wvlen=wvlen,
                                        theta=thetaMax,
                                        phase=phaseMax,
                                        b=sinPow).data
                self.bestAxon = np.ma.array(self.bestAxon,
                                            mask=self.selectedMask,
                                            fill_value=0)
                self.img1.setImage(self.bestAxon.filled(0))
                self.img2.setImage(self.selected)

                shape = self.selected.shape
                self.vb4.setLimits(xMin=-0.05 * shape[0],
                                   xMax=1.05 * shape[0],
                                   yMin=-0.05 * shape[1],
                                   yMax=1.05 * shape[1],
                                   minXRange=4,
                                   minYRange=4)
                self.vb4.setRange(xRange=(0, shape[0]), yRange=(0, shape[1]))

                # plot the threshold of correlation chosen by the user
                # phase steps are set to 20, TO DO: explore this parameter
                theta = np.arange(np.min([self.th0 - deltaTh, 0]), 180, thStep)
                pen1 = pg.mkPen(color=(0, 255, 100),
                                width=2,
                                style=QtCore.Qt.SolidLine,
                                antialias=True)
                self.pCorr.plot(theta, corrTheta, pen=pen1)

                # plot the area within deltaTh from the found direction
                if self.th0 is not None:
                    thArea = np.arange(self.th0 - deltaTh, self.th0 + deltaTh)
                    if self.th0 < 0:
                        thArea += 180
                    gap = 0.05 * (np.max(corrTheta) - np.min(corrTheta))
                    brushMax = np.max(corrTheta) * np.ones(len(thArea)) + gap
                    brushMin = np.min(corrTheta) - gap
                    self.pCorr.plot(thArea,
                                    brushMax,
                                    fillLevel=brushMin,
                                    fillBrush=(50, 50, 200, 100),
                                    pen=None)

            corrThres = np.float(self.main.corrThresEdit.text())
            rings = corrMax > corrThres
            if rings and np.abs(self.th0 - thetaMax) <= deltaTh:
                self.main.resultLabel.setText('<strong>MY PRECIOUS!<\strong>')
            else:
                if rings:
                    print('Correlation maximum outside direction theta range')
                self.main.resultLabel.setText('<strong>No rings<\strong>')
        else:
            print('Data below intensity threshold')
            self.main.resultLabel.setText('<strong>No rings<\strong>')