Beispiel #1
0
    def start(self):

        t0 = time.time()
        for i in np.arange(self.nfiles):

            self.i = i

            # Image loading
            im = Image.open(self.files[i])
            inputData = np.array(im).astype(np.float64)
            inputData = inputData[self.crop:self.bound[0],
                                  self.crop:self.bound[1]]

            inputDataS = ndi.gaussian_filter(inputData, self.gaussSigma)
            meanS = np.mean(inputDataS)
            stdS = np.std(inputDataS)

            # binarization of image
            mask = inputDataS < meanS + self.intThres * stdS
            # shape the data into the subimg that we need for the analysis
            nblocks = np.array(inputData.shape) / self.n
            blocksInput = tools.blockshaped(inputData, *nblocks)
            blocksInputS = tools.blockshaped(inputDataS, *nblocks)
            blocksMask = tools.blockshaped(mask, *nblocks)

            worker = Worker(self.n, blocksInput, blocksInputS, blocksMask,
                            self.intThres, self.cArgs)
            worker.signals.start.connect(self.updateBar)
            worker.signals.done.connect(self.processResult)

            self.pool.start(worker)

        self.pool.waitForDone()
Beispiel #2
0
def loadData(folder, ax, subimgPxSize, technique, mag=None):
    """
    Plot loaded image, blocks grid and numbers
    """

    # Load image
    filename = utils.getFilename('Load ' + technique + ' image',
                                 [('Tiff file', '.tif')], folder)
    newFolder = os.path.split(filename)[0]

    inputData = tiff.imread(filename)
    dataShape = inputData.shape
    fileShape = inputData.shape

    if technique == 'STORM':
        crop = int(3*mag)
        bound = (np.array(dataShape) - crop).astype(np.int)
        inputData = inputData[crop:bound[0], crop:bound[1]]
        dataShape = inputData.shape

    n = np.round(np.array(dataShape)/subimgPxSize).astype(int)

    # If n*subimgPxSize < shape, we crop the image
    inputData = inputData[:n[0]*subimgPxSize, :n[1]*subimgPxSize]
    dataShape = inputData.shape
    plotWithGrid(inputData, ax, subimgPxSize)

    # Segment image in blocks
    nblocks = np.array(dataShape)/n
    blocks = tools.blockshaped(inputData, *nblocks)

    return newFolder, blocks, dataShape, fileShape, n
Beispiel #3
0
    def updateMasks(self):
        """Binarization of image. """

        self.gaussSigma = np.float(self.main.sigmaEdit.text()) / self.pxSize
        thr = np.float(self.main.intThresEdit.text())

        if self.main.testData:
            self.blocksInputS = [
                ndi.gaussian_filter(b, self.gaussSigma)
                for b in self.blocksInput
            ]
            self.blocksInputS = np.array(self.blocksInputS)
            self.meanS = np.mean(self.blocksInputS, (1, 2))
            self.stdS = np.std(self.blocksInputS, (1, 2))
            thresholds = self.meanS + thr * self.stdS
            thresholds = thresholds.reshape(np.prod(self.n), 1, 1)
            mask = self.blocksInputS < thresholds
            self.blocksMask = np.array([
                bI < np.mean(bI) + thr * np.std(bI) for bI in self.blocksInputS
            ])

            self.mask = tools.unblockshaped(mask, *self.inputData.shape)
            self.inputDataS = tools.unblockshaped(self.blocksInputS,
                                                  *self.shape)
        else:
            self.inputDataS = ndi.gaussian_filter(self.inputData,
                                                  self.gaussSigma)
            self.blocksInputS = tools.blockshaped(self.inputDataS,
                                                  *self.nblocks)
            self.meanS = np.mean(self.inputDataS)
            self.stdS = np.std(self.inputDataS)
            self.mask = self.inputDataS < self.meanS + thr * self.stdS
            self.blocksMask = tools.blockshaped(self.mask, *self.nblocks)

        self.showImS = np.fliplr(np.transpose(self.inputDataS))
        self.showMask = np.fliplr(np.transpose(self.mask))

        self.selectedMask = self.roi.getArrayRegion(self.showMask,
                                                    self.inputImg).astype(bool)
Beispiel #4
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():

            # shape the data into the subimg that we need for the analysis
            nblocks = np.array(self.inputData.shape) / self.n
            blocksInput = tools.blockshaped(self.inputData, *nblocks)
            blocksInputS = tools.blockshaped(self.inputDataS, *nblocks)
            blocksMask = tools.blockshaped(self.mask, *nblocks)

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

            args = self.n, blocksInput, blocksInputS, blocksMask, intThr, cArgs
            self.localCorr = np.zeros(len(blocksInput))
            self.singleObj = Single(*args)
            self.updateFileStatus()
            #            self.singleObj.signals.start.connect(self.updateFileStatus)
            self.singleObj.doneSignal.connect(self.updateOutput)
            self.workerThread = QtCore.QThread(self)
            self.singleObj.moveToThread(self.workerThread)
            self.workerThread.started.connect(self.singleObj.start)
            self.workerThread.start()

        else:
            self.corrResult.clear()
            self.ringResult.clear()
Beispiel #5
0
    def loadImage(self, pxSize, tt, crop=0, filename=None):

        try:
            if not (isinstance(filename, str)):
                filetypes = ('Tiff file', '*.tif;*.tiff')
                self.filename = utils.getFilename('Load ' + tt + ' image',
                                                  [filetypes], self.folder)
            else:
                self.filename = filename

            if self.filename is not None:

                self.corrButton.setChecked(False)
                self.analyzed = False

                self.folder = os.path.split(self.filename)[0]
                self.crop = np.int(crop)
                self.pxSize = pxSize
                self.corrVb.clear()
                self.corrResult.clear()
                self.ringVb.clear()
                self.ringResult.clear()

                im = Image.open(self.filename)
                self.inputData = np.array(im).astype(np.float64)
                self.initShape = self.inputData.shape
                bound = (np.array(self.initShape) - self.crop).astype(np.int)
                self.inputData = self.inputData[self.crop:bound[0],
                                                self.crop:bound[1]]
                self.shape = self.inputData.shape

                # We need 1um n-sized subimages
                self.subimgPxSize = int(1000 / self.pxSize)
                self.n = (np.array(self.shape) / self.subimgPxSize).astype(int)

                # If n*subimgPxSize < shape, we crop the image
                self.remanent = np.array(
                    self.shape) - self.n * self.subimgPxSize
                self.inputData = self.inputData[:self.n[0] *
                                                self.subimgPxSize, :self.n[1] *
                                                self.subimgPxSize]
                self.shape = self.inputData.shape

                self.nblocks = np.array(self.inputData.shape) / self.n
                self.blocksInput = tools.blockshaped(self.inputData,
                                                     *self.nblocks)

                self.updateMasks()
                self.corrVb.addItem(self.corrImgItem)
                self.ringVb.addItem(self.ringImgItem)
                showIm = np.fliplr(np.transpose(self.inputData))
                self.corrImgItem.setImage(showIm)
                self.ringImgItem.setImage(showIm)

                self.grid = pyqtsub.Grid(self.corrVb, self.shape, self.n)

                self.corrVb.setLimits(xMin=-0.05 * self.shape[0],
                                      xMax=1.05 * self.shape[0],
                                      minXRange=4,
                                      yMin=-0.05 * self.shape[1],
                                      yMax=1.05 * self.shape[1],
                                      minYRange=4)
                self.ringVb.setLimits(xMin=-0.05 * self.shape[0],
                                      xMax=1.05 * self.shape[0],
                                      minXRange=4,
                                      yMin=-0.05 * self.shape[1],
                                      yMax=1.05 * self.shape[1],
                                      minYRange=4)

                self.dataMean = np.mean(self.inputData)
                self.dataStd = np.std(self.inputData)

                self.corrVb.addItem(self.corrResult)
                self.ringVb.addItem(self.ringResult)

                return True

            else:
                return False

        except OSError:
            self.fileStatus.setText('No file selected!')
Beispiel #6
0
    def loadImage(self, tech, pxSize, crop=0, filename=None):

        try:

            if not (isinstance(filename, str)):
                filetypes = ('Tiff file', '*.tif;*.tiff')
                self.filename = utils.getFilename('Load ' + tech + ' image',
                                                  [filetypes], self.folder)
            else:
                self.filename = filename

            if self.filename is not None:

                self.folder = os.path.split(self.filename)[0]
                self.pxSize = pxSize
                self.inputVb.clear()

                # Image loading
                im = Image.open(self.filename)
                self.inputData = np.array(im).astype(np.float64)
                self.shape = self.inputData.shape
                self.inputData = self.inputData[crop:self.shape[0] - crop,
                                                crop:self.shape[1] - crop]
                self.shape = self.inputData.shape

                # We need 1um n-sized subimages
                self.subimgPxSize = int(np.round(1000 / self.pxSize))
                self.n = (np.array(self.shape) / self.subimgPxSize).astype(int)

                # If n*subimgPxSize < shape, we crop the image
                self.remanent = np.array(
                    self.shape) - self.n * self.subimgPxSize
                self.inputData = self.inputData[:self.n[0] *
                                                self.subimgPxSize, :self.n[1] *
                                                self.subimgPxSize]
                self.shape = self.inputData.shape

                self.nblocks = np.array(self.inputData.shape) / self.n
                self.blocksInput = tools.blockshaped(self.inputData,
                                                     *self.nblocks)

                self.showIm = np.fliplr(np.transpose(self.inputData))

                # Image plotting
                self.inputImg = pg.ImageItem()
                self.inputVb.addItem(self.inputImg)
                self.inputVb.setAspectLocked(True)
                self.inputImg.setImage(self.showIm)
                self.inputImgHist.setImageItem(self.inputImg)
                self.addItem(self.inputImgHist, row=0, col=1)
                self.inputVb.addItem(self.roi)
                self.inputVb.addItem(self.thresBlockIm)
                self.inputVb.addItem(self.thresIm)

                self.updateMasks()

                self.grid = pyqtsub.Grid(self.inputVb, self.shape, self.n)

                self.inputVb.setLimits(xMin=-0.05 * self.shape[0],
                                       xMax=1.05 * self.shape[0],
                                       minXRange=4,
                                       yMin=-0.05 * self.shape[1],
                                       yMax=1.05 * self.shape[1],
                                       minYRange=4)

                self.updateROI()
                self.updatePlot()

                return True

            else:
                return False

        except OSError:
            print('No file selected!')