Loading analysis/particleAndMeasurement.py +1 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ class Particle(object): self.measurements = [] self.color = None self.shape = None self.wasManuallyEdited = False #useful tag for extracting data that can now be considered reliable and obviously was classfiied wrong before by the algorithms def addMeasurement(self, refToMeasurement): refToMeasurement.assignedParticle = self Loading analysis/particleCharacterization.py +8 −5 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ from copy import deepcopy from .particleClassification.colorClassification import ColorClassifier from .particleClassification.shapeClassification import ShapeClassifier from segmentation import closeHolesOfSubImage from errors import NotConnectedContoursError, InvalidParticleError from errors import InvalidParticleError class ParticleStats(object): longSize = None Loading @@ -46,16 +46,19 @@ def particleIsValid(particle): return True def getParticleStatsWithPixelScale(cnt, pixelscale, fullimage, dataset): newStats = ParticleStats() def getParticleStatsWithPixelScale(cnt, fullimage, dataset): pixelscale = dataset.getPixelScale() newStats = ParticleStats() newStats.longSize, newStats.shortSize, newStats.area = getContourStats(cnt) newStats.longSize *= pixelscale newStats.shortSize *= pixelscale newStats.area *= (pixelscale**2) if 0 in [newStats.longSize, newStats.shortSize, newStats.area]: raise InvalidParticleError newStats.height = getParticleHeight(cnt, dataset) print('newHeight =', newStats.height) newStats.shape = getParticleShape(cnt, newStats.height) partImg = getParticleImageFromFullimage(cnt, fullimage) Loading analysis/particleContainer.py +16 −12 Original line number Diff line number Diff line Loading @@ -98,13 +98,8 @@ class ParticleContainer(object): def setParticleStats(self, particlestats): assert len(self.particles) == len(particlestats) #particlestats is list of [long, short, longellipse, shortellipse, cv2.contourArea(cnt)] for index, particle in enumerate(self.particles): particle.longSize_box = float(particlestats[index][0]) particle.shortSize_box = float(particlestats[index][1]) particle.longSize_ellipse = float(particlestats[index][2]) particle.shortSize_ellipse = float(particlestats[index][3]) particle.area = float(particlestats[index][4]) particle.__dict__.update(particlestats[index].__dict__) def testForInconsistentParticles(self): #i.e., particles that have multiple measurements with different assignments self.inconsistentParticles = [] Loading Loading @@ -146,10 +141,6 @@ class ParticleContainer(object): scanIndex = meas.getScanIndex() meas.setHQI(hqiList[scanIndex]) def reassignParticleToAssignment(self, particleIndex, newAssignment): particle = self.getParticleOfIndex(particleIndex) particle.setAllSpectraToNewAssignment(newAssignment) def getParticleOfIndex(self, index): try: particle = self.particles[index] Loading Loading @@ -248,6 +239,12 @@ class ParticleContainer(object): colors.append(particle.color) return colors def getShapesOfAllParticles(self): shapes = [] for particle in self.particles: shapes.append(particle.shape) return shapes def getParticleColorByIndex(self, particleIndex): particle = self.getParticleOfIndex(particleIndex) return particle.color Loading Loading @@ -289,13 +286,20 @@ class ParticleContainer(object): final_typehistogram = {i[0]: i[1] for i in sorted_typehistogram} return final_typehistogram def reassignParticleToAssignment(self, particleIndex, newAssignment): particle = self.getParticleOfIndex(particleIndex) particle.setAllSpectraToNewAssignment(newAssignment) particle.wasManuallyEdited = True def changeParticleColor(self, index, newColor): particle = self.getParticleOfIndex(index) particle.color = newColor particle.wasManuallyEdited = True def changeParticleShape(self, index, newShape): particle = self.getParticleOfIndex(index) particle.shape = newShape particle.wasManuallyEdited = True def addMergedParticle(self, particleIndices, newContour, newStats, newAssignment=None): newParticle = Particle() Loading @@ -310,7 +314,7 @@ class ParticleContainer(object): newParticle.addMeasurement(meas) newParticle.__dict__.update(newStats.__dict__) newParticle.wasManuallyEdited = True self.particles.append(newParticle) print('added new particle') Loading analysis/particleEditor.py +1 −3 Original line number Diff line number Diff line Loading @@ -227,8 +227,7 @@ class ParticleEditor(QtCore.QObject): self.particlePainter = None def mergeParticlesInParticleContainerAndSampleView(self, indices, newContour, assignment): pixelscale = self.viewparent.dataset.getPixelScale() stats = pc.getParticleStatsWithPixelScale(newContour, pixelscale, self.viewparent.imgdata, self.viewparent.dataset) stats = pc.getParticleStatsWithPixelScale(newContour, self.viewparent.imgdata, self.viewparent.dataset) self.viewparent.addParticleContourToIndex(newContour, len(self.viewparent.contourItems)-1) self.particleContainer.addMergedParticle(indices, newContour, stats, newAssignment=assignment) Loading @@ -240,7 +239,6 @@ class ParticleEditor(QtCore.QObject): self.viewparent.resetContourIndices() self.particleContainer.resetParticleIndices() self.particleAssignmentChanged.emit() #TODO: INCLUDE SANITY CHECK!!!!!!!!! @QtCore.pyqtSlot(list, str) def changeParticleColors(self, contourIndices, newColor): Loading analysis/sqlexport.py +2 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ class SQLExport(QtWidgets.QDialog): self.longSizes = np.round(self.particleContainer.getSizesOfAllParticles()) self.shortSize = np.round(self.particleContainer.getShortSizesOfAllParticles()) self.colors = self.particleContainer.getColorsOfAllParticles() self.shapes = self.particleContainer.getShapesOfAllParticles() self.spectra = self.particleContainer.getSpectraFromDisk() self.particleImages = None Loading Loading @@ -219,6 +220,7 @@ class SQLExport(QtWidgets.QDialog): usedCols['Analyst'] = str(self.analystIndices[self.analystSelector.currentIndex()]) usedCols['Size_fraction'] = self.getSizeFraction(sizeCategories, self.longSizes[polymInd]) usedCols['Colour'] = self.colors[polymInd] usedCols['Shape'] = self.shapes[polymInd] usedCols[sizeCols[0]] = str(self.longSizes[polymInd]) usedCols[sizeCols[1]] = str(self.shortSize[polymInd]) if self.particleImages is not None: Loading Loading
analysis/particleAndMeasurement.py +1 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ class Particle(object): self.measurements = [] self.color = None self.shape = None self.wasManuallyEdited = False #useful tag for extracting data that can now be considered reliable and obviously was classfiied wrong before by the algorithms def addMeasurement(self, refToMeasurement): refToMeasurement.assignedParticle = self Loading
analysis/particleCharacterization.py +8 −5 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ from copy import deepcopy from .particleClassification.colorClassification import ColorClassifier from .particleClassification.shapeClassification import ShapeClassifier from segmentation import closeHolesOfSubImage from errors import NotConnectedContoursError, InvalidParticleError from errors import InvalidParticleError class ParticleStats(object): longSize = None Loading @@ -46,16 +46,19 @@ def particleIsValid(particle): return True def getParticleStatsWithPixelScale(cnt, pixelscale, fullimage, dataset): newStats = ParticleStats() def getParticleStatsWithPixelScale(cnt, fullimage, dataset): pixelscale = dataset.getPixelScale() newStats = ParticleStats() newStats.longSize, newStats.shortSize, newStats.area = getContourStats(cnt) newStats.longSize *= pixelscale newStats.shortSize *= pixelscale newStats.area *= (pixelscale**2) if 0 in [newStats.longSize, newStats.shortSize, newStats.area]: raise InvalidParticleError newStats.height = getParticleHeight(cnt, dataset) print('newHeight =', newStats.height) newStats.shape = getParticleShape(cnt, newStats.height) partImg = getParticleImageFromFullimage(cnt, fullimage) Loading
analysis/particleContainer.py +16 −12 Original line number Diff line number Diff line Loading @@ -98,13 +98,8 @@ class ParticleContainer(object): def setParticleStats(self, particlestats): assert len(self.particles) == len(particlestats) #particlestats is list of [long, short, longellipse, shortellipse, cv2.contourArea(cnt)] for index, particle in enumerate(self.particles): particle.longSize_box = float(particlestats[index][0]) particle.shortSize_box = float(particlestats[index][1]) particle.longSize_ellipse = float(particlestats[index][2]) particle.shortSize_ellipse = float(particlestats[index][3]) particle.area = float(particlestats[index][4]) particle.__dict__.update(particlestats[index].__dict__) def testForInconsistentParticles(self): #i.e., particles that have multiple measurements with different assignments self.inconsistentParticles = [] Loading Loading @@ -146,10 +141,6 @@ class ParticleContainer(object): scanIndex = meas.getScanIndex() meas.setHQI(hqiList[scanIndex]) def reassignParticleToAssignment(self, particleIndex, newAssignment): particle = self.getParticleOfIndex(particleIndex) particle.setAllSpectraToNewAssignment(newAssignment) def getParticleOfIndex(self, index): try: particle = self.particles[index] Loading Loading @@ -248,6 +239,12 @@ class ParticleContainer(object): colors.append(particle.color) return colors def getShapesOfAllParticles(self): shapes = [] for particle in self.particles: shapes.append(particle.shape) return shapes def getParticleColorByIndex(self, particleIndex): particle = self.getParticleOfIndex(particleIndex) return particle.color Loading Loading @@ -289,13 +286,20 @@ class ParticleContainer(object): final_typehistogram = {i[0]: i[1] for i in sorted_typehistogram} return final_typehistogram def reassignParticleToAssignment(self, particleIndex, newAssignment): particle = self.getParticleOfIndex(particleIndex) particle.setAllSpectraToNewAssignment(newAssignment) particle.wasManuallyEdited = True def changeParticleColor(self, index, newColor): particle = self.getParticleOfIndex(index) particle.color = newColor particle.wasManuallyEdited = True def changeParticleShape(self, index, newShape): particle = self.getParticleOfIndex(index) particle.shape = newShape particle.wasManuallyEdited = True def addMergedParticle(self, particleIndices, newContour, newStats, newAssignment=None): newParticle = Particle() Loading @@ -310,7 +314,7 @@ class ParticleContainer(object): newParticle.addMeasurement(meas) newParticle.__dict__.update(newStats.__dict__) newParticle.wasManuallyEdited = True self.particles.append(newParticle) print('added new particle') Loading
analysis/particleEditor.py +1 −3 Original line number Diff line number Diff line Loading @@ -227,8 +227,7 @@ class ParticleEditor(QtCore.QObject): self.particlePainter = None def mergeParticlesInParticleContainerAndSampleView(self, indices, newContour, assignment): pixelscale = self.viewparent.dataset.getPixelScale() stats = pc.getParticleStatsWithPixelScale(newContour, pixelscale, self.viewparent.imgdata, self.viewparent.dataset) stats = pc.getParticleStatsWithPixelScale(newContour, self.viewparent.imgdata, self.viewparent.dataset) self.viewparent.addParticleContourToIndex(newContour, len(self.viewparent.contourItems)-1) self.particleContainer.addMergedParticle(indices, newContour, stats, newAssignment=assignment) Loading @@ -240,7 +239,6 @@ class ParticleEditor(QtCore.QObject): self.viewparent.resetContourIndices() self.particleContainer.resetParticleIndices() self.particleAssignmentChanged.emit() #TODO: INCLUDE SANITY CHECK!!!!!!!!! @QtCore.pyqtSlot(list, str) def changeParticleColors(self, contourIndices, newColor): Loading
analysis/sqlexport.py +2 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ class SQLExport(QtWidgets.QDialog): self.longSizes = np.round(self.particleContainer.getSizesOfAllParticles()) self.shortSize = np.round(self.particleContainer.getShortSizesOfAllParticles()) self.colors = self.particleContainer.getColorsOfAllParticles() self.shapes = self.particleContainer.getShapesOfAllParticles() self.spectra = self.particleContainer.getSpectraFromDisk() self.particleImages = None Loading Loading @@ -219,6 +220,7 @@ class SQLExport(QtWidgets.QDialog): usedCols['Analyst'] = str(self.analystIndices[self.analystSelector.currentIndex()]) usedCols['Size_fraction'] = self.getSizeFraction(sizeCategories, self.longSizes[polymInd]) usedCols['Colour'] = self.colors[polymInd] usedCols['Shape'] = self.shapes[polymInd] usedCols[sizeCols[0]] = str(self.longSizes[polymInd]) usedCols[sizeCols[1]] = str(self.shortSize[polymInd]) if self.particleImages is not None: Loading