Commit d6af372b authored by Josef Brandt's avatar Josef Brandt
Browse files

Merge branch 'Thresholding,Background' into RefactoringAnalysisModules

parents 92f24fb4 48537f7f
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -43,6 +43,12 @@ class ParticleContainer(object):
        indexOfNewMeas = len(self.measurements)-1
        return indexOfNewMeas
    
    def clearParticles(self):
        self.particles = []
    
    def clearMeasurements(self):
        self.measurements = []

    def setMeasurementScanIndex(self, indexOfMeasurment, scanIndex):
        self.measurements[indexOfMeasurment].ramanScanIndex = scanIndex
    
+19 −44
Original line number Diff line number Diff line
@@ -149,6 +149,7 @@ class DataSet(object):
#        self.particlestats = []
#        self.ramanscansortindex = None
        self.particleContainer = ParticleContainer(self)
        self.particleDetectionDone = False
        self.ramanscandone = False
        
#        self.results = {'polymers': None,
@@ -247,34 +248,24 @@ class DataSet(object):
                self.imagedim_df = self.imagedim
                del self.imagedim
            
            
            if not hasattr(self, 'particles2spectra'):
                self.particles2spectra = [[int(np.where(self.ramanscansortindex == i)[0])] for i in range(len(self.ramanscansortindex))]
            
            self.version = 2
        
        if self.version == 2:
            self.particleContainer = ParticleContainer(self)
            def recreateMeasurement2ParticleFromScanIndices():
                measurements2particles = [[int(np.where(self.ramanscansortindex == i)[0])] for i in range(len(self.ramanscansortindex))]
                return measurements2particles

 
            self.particleContainer.initializeParticles(len(self.particlestats))
            self.particleContainer.setParticleContours(self.particlecontours)
            self.particleContainer.setParticleStats(self.particlestats)
            self.particleContainer.applyPixelScaleToParticleStats(self.getPixelScale())
            
            if hasattr(self, 'particles2spectra'):
                if self.particles2spectra is not None:
                    measurements2particles = self.particles2spectra
                else:
                    measurements2particles = recreateMeasurement2ParticleFromScanIndices()
            else:    
                measurements2particles = recreateMeasurement2ParticleFromScanIndices()
                
            for particleIndex, listOfScanIndices in enumerate(measurements2particles):
            if len(self.particlestats) > 0:   #i.e., particle detection was completed and particle data is there 
                for particleIndex, listOfScanIndices in enumerate(self.particles2spectra):
                    curParticle = self.particleContainer.getParticleOfIndex(particleIndex)
                    for scanIndex in listOfScanIndices:
#                    curParticle.addEmptyMeasurement()
#                    curParticle.setMeasurementPixelCoords(measIndex, x, y)
#                    curParticle.setMeasurementScanIndex(measIndex, scanIndex)
                        indexOfNewMeas = self.particleContainer.addEmptyMeasurement()
                        x, y = self.ramanpoints[particleIndex][0], self.ramanpoints[particleIndex][1]
                        self.particleContainer.setMeasurementPixelCoords(indexOfNewMeas, x, y)
@@ -292,8 +283,6 @@ class DataSet(object):
#            self.version = 3
        # add later conversion for higher version numbers here
    
    
    
    def getSubImage(self, img, index, draw=True):
        contour = self.particlecontours[index]
        x0, x1 = contour[:,0,0].min(), contour[:,0,0].max()
@@ -395,29 +384,15 @@ class DataSet(object):
    def getLegacyDetectImageName(self):
        return os.path.join(self.path, "detectimage.png")
    
    def getBackgroundImageName(self):
        return os.path.join(self.path, "background.bmp")
    
    def getDetectImageName(self):
        raise NotImplementedError("No longer implemented due to change in API")
    
    def getTmpImageName(self):
        return os.path.join(self.path, "tmp.bmp")
            
    def saveParticleData(self):
        print('Not saving ParticleData into text file...:\nThe current output format might be wrong, if multiple spectra per particle are present...')
#        if len(self.ramanscansortindex)>0:
#            data = []
#            pixelscale = (self.pixelscale_df if self.imagescanMode == 'df' else self.pixelscale_bf)
#            for i in self.ramanscansortindex:
#                data.append(list(self.ramanpoints[i])+list(self.particlestats[i]))
#            data = np.array(data)
#            data[:,0], data[:,1], z = self.mapToLengthRaman((data[:,0], data[:,1]), microscopeMode=self.imagescanMode, noz=True)
#            data[:,2:7] *= pixelscale
#            header = "x [µm], y [µm], length [µm], height [µm], length_ellipse [µm], height_ellipse [µm]"
#            if data.shape[1]>6:
#                header = header + ", area [µm^2]"
#                data[:,6] *= pixelscale
#            np.savetxt(os.path.join(self.path, "particledata.txt"), data, 
#                       header=header)
            
    def save(self):
        saveData(self, self.fname)
    
+8 −7
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ If not, see <https://www.gnu.org/licenses/>.
"""
import numpy as np
from PyQt5 import QtCore, QtWidgets, QtGui
from segmentation import Segmentation
from segmentation import Segmentation, MeasurementPoint
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
import matplotlib.pyplot as plt
from threading import Thread
@@ -248,7 +248,9 @@ class ImageView(QtWidgets.QLabel):
            painter.setPen(QtCore.Qt.red)
            painter.setBrush(QtCore.Qt.red)
            for p in self.measpoints:
                painter.drawEllipse(p[0]-2, p[1]-2, 5, 5)
                for point in self.measpoints[p]:
#                painter.drawEllipse(p[0]-2, p[1]-2, 5, 5)
                    painter.drawEllipse(point.x-2, point.y-2, 5, 5)

        if self.showseedpoints:
            painter.setPen(QtCore.Qt.white)
@@ -581,10 +583,9 @@ class ParticleDetectionView(QtWidgets.QWidget):
    @QtCore.pyqtSlot()
    def clearDetection(self):
        if self.dataset is not None:
            self.dataset.ramanpoints = []
            self.dataset.particlecontours = []
            self.dataset.particlestats = []
            self.dataset.ramanscansortindex = []
            self.dataset.particleContainer.clearParticles()
            self.dataset.particleContainer.clearMeasurements()
            self.dataset.particleDetectionDone = False
            self.dataset.ramanscandone = False
            self.dataset.mode = "opticalscan"
            self.dataset.save()
@@ -676,7 +677,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
                    curParticle.addMeasurement(particleContainer.measurements[indexOfNewMeas])
                    
                    
                
            self.dataset.particleDetectionDone = True
#            self.dataset.ramanpoints = measurementPoints    #consider moving that to particleContainer
#            self.dataset.particlecontours = contours
#            self.dataset.particlestats = particlestats
+5 −4
Original line number Diff line number Diff line
@@ -102,12 +102,13 @@ class GEPARDMainWindow(QtWidgets.QMainWindow):
        if fileName:
            isValid, msg = self.testFilename(fileName)
            if isValid:
                self.fname = str(fileName)   #TODO: No spaces for Renishaw Interface!!
                self.fname = str(fileName)
                self.view.new(self.fname)  
                self.scalingChanged(1.)
            else:
                QtWidgets.QMessageBox.critical(self, "Error", msg)
            
    @QtCore.pyqtSlot()  
    def testFilename(self, fileName):
        if self.view.ramanctrl.name == 'RenishawCOM':   #the renishawCom does not allow Spaces within filePath
            if fileName.find(' ') == 0:
+9 −6
Original line number Diff line number Diff line
@@ -48,15 +48,17 @@ def imageStacking(colimgs):
    return im, zval

def combineImages(path, nx, ny, nk, width, height, angle):
    imgs = []
    full = None
    for i in range(nx):
        for j in range(ny):
            if nk > 1:
                colimgs = []
                for k in range(nk):
                    colimgs.append(cv2.imread(path + f'test_{i}_{j}_{k}.bmp'))
                img = imageStacking(colimgs)
            imgs.append(img)
            else:
                img = cv2.imread(path + f'test_{i}_{j}_1.bmp')

            dx = i*.9*img.shape[1]
            dy = j*.8*img.shape[0]
            c, s = np.cos(np.radians(angle)), np.sin(np.radians(angle))
@@ -67,6 +69,7 @@ def combineImages(path, nx, ny, nk, width, height, angle):
                full = dst
            else:
                full = cv2.max(full,dst)

    cv2.imwrite("full_dunkel.png", full)
    
    
Loading