Commit 8b813392 authored by Josef Brandt's avatar Josef Brandt

Converted particleAreas into particleSize for filtering of components

parent 38f99d4e
......@@ -82,9 +82,9 @@ class Segmentation(QtCore.QObject):
'upThresh': 0.5,
'invertThresh': False,
'maxholebrightness': 0.5,
'minparticlearea': 20,
'minparticlesize': 20,
'enableMaxArea': False,
'maxparticlearea': 100000,
'maxparticlesize': 100000,
'minparticledistance': 20,
'closeBackground': False,
'fuzzycluster': False,
......@@ -113,9 +113,9 @@ class Segmentation(QtCore.QObject):
Parameter("activateUpThresh", np.bool, self.detectParams['activateUpThresh'], helptext="activate upper threshold", show=False, linkedParameter='upThresh'),
Parameter("upThresh", float, self.detectParams['upThresh'], .01, 1.0, 2, .02, helptext="Upper threshold", show=False),
Parameter("maxholebrightness", float, self.detectParams['maxholebrightness'], 0, 1, 2, 0.02, helptext="Close holes brighter than..", show = True),
Parameter("minparticlearea", int, self.detectParams['minparticlearea'], 1, 1000, 0, 50, helptext="Min. particle pixel area", show=False),
Parameter("enableMaxArea", np.bool, self.detectParams['enableMaxArea'], helptext="enable filtering for maximal pixel area", show=False, linkedParameter='maxparticlearea'),
Parameter("maxparticlearea", int, self.detectParams['maxparticlearea'], 10, 1E9, 0, 50, helptext="Max. particle pixel area", show=False),
Parameter("minparticlesize", int, self.detectParams['minparticlesize'], 1, 1000, 0, 50, helptext="Min. particle size (µm)", show=False),
Parameter("enableMaxArea", np.bool, self.detectParams['enableMaxArea'], helptext="enable filtering for maximal particle size", show=False, linkedParameter='maxparticlearea'),
Parameter("maxparticlesize", int, self.detectParams['maxparticlesize'], 10, 1E9, 0, 50, helptext="Max. particle size (µm)", show=False),
Parameter("minparticledistance", int, self.detectParams['minparticledistance'], 5, 1000, 0, 5, helptext="Min. distance between particles", show=False),
Parameter("measurefrac", float, self.detectParams['measurefrac'], 0, 1, 2, stepsize = 0.05, helptext="measure fraction of particles", show=False),
Parameter("closeBackground", np.bool, self.detectParams['closeBackground'], helptext="close holes in sure background", show=False),
......@@ -238,10 +238,7 @@ class Segmentation(QtCore.QObject):
if self.cancelcomputation:
return None, None
if self.enableMaxArea:
maxArea = self.maxparticlearea
else:
maxArea = np.inf
minArea, maxArea = self.getMinMaxParticleArea(dataset)
##get sure_fg
'''the peak_local_max function takes the min distance between peaks. Unfortunately, that means that individual
......@@ -265,7 +262,7 @@ class Segmentation(QtCore.QObject):
for label in range(1, n):
area = stats[label, cv2.CC_STAT_AREA]
if self.minparticlearea < area < maxArea:
if minArea < area < maxArea:
up = stats[label, cv2.CC_STAT_TOP]
left = stats[label, cv2.CC_STAT_LEFT]
width = stats[label, cv2.CC_STAT_WIDTH]
......@@ -339,7 +336,7 @@ class Segmentation(QtCore.QObject):
for cnt in tmpcontours:
contourArea = cv2.contourArea(cnt) * scaleFactor**2
if contourArea >= self.minparticlearea:
if contourArea >= minArea:
tmplabel = markers[cnt[0,0,1],cnt[0,0,0]]
if tmplabel ==0:
continue
......@@ -404,6 +401,24 @@ class Segmentation(QtCore.QObject):
self.detectionState.emit(f'finished particle detection after {total_time} seconds')
return measurementPoints, finalcontours
def getMinMaxParticleArea(self, dataset):
"""
Converts specified particle sizes into particle areas that are used for filtering detection results.
Size is interpreted as sphere equivalent diameter.
a = pi*(d/2)²
:return:
"""
pixelscale = dataset.getPixelScale()
minRadius = (self.minparticlesize / pixelscale) / 2
minArea = np.pi * minRadius**2
if self.enableMaxArea:
maxRadius = (self.maxparticlesize / pixelscale) / 2
maxArea = np.pi * maxRadius**2
else:
maxArea = np.inf
return minArea, maxArea
def addToPreviewImage(self, subimg, up, left, previewImage):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment