Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
GEPARD
GEPARD
Commits
8b813392
Commit
8b813392
authored
Dec 02, 2019
by
Josef Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Converted particleAreas into particleSize for filtering of components
parent
38f99d4e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
11 deletions
+26
-11
segmentation.py
segmentation.py
+26
-11
No files found.
segmentation.py
View file @
8b813392
...
@@ -82,9 +82,9 @@ class Segmentation(QtCore.QObject):
...
@@ -82,9 +82,9 @@ class Segmentation(QtCore.QObject):
'upThresh'
:
0.5
,
'upThresh'
:
0.5
,
'invertThresh'
:
False
,
'invertThresh'
:
False
,
'maxholebrightness'
:
0.5
,
'maxholebrightness'
:
0.5
,
'minparticle
area
'
:
20
,
'minparticle
size
'
:
20
,
'enableMaxArea'
:
False
,
'enableMaxArea'
:
False
,
'maxparticle
area
'
:
100000
,
'maxparticle
size
'
:
100000
,
'minparticledistance'
:
20
,
'minparticledistance'
:
20
,
'closeBackground'
:
False
,
'closeBackground'
:
False
,
'fuzzycluster'
:
False
,
'fuzzycluster'
:
False
,
...
@@ -113,9 +113,9 @@ class Segmentation(QtCore.QObject):
...
@@ -113,9 +113,9 @@ class Segmentation(QtCore.QObject):
Parameter
(
"activateUpThresh"
,
np
.
bool
,
self
.
detectParams
[
'activateUpThresh'
],
helptext
=
"activate upper threshold"
,
show
=
False
,
linkedParameter
=
'upThresh'
),
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
(
"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
(
"maxholebrightness"
,
float
,
self
.
detectParams
[
'maxholebrightness'
],
0
,
1
,
2
,
0.02
,
helptext
=
"Close holes brighter than.."
,
show
=
True
),
Parameter
(
"minparticle
area
"
,
int
,
self
.
detectParams
[
'minparticle
area
'
],
1
,
1000
,
0
,
50
,
helptext
=
"Min. particle
pixel area
"
,
show
=
False
),
Parameter
(
"minparticle
size
"
,
int
,
self
.
detectParams
[
'minparticle
size
'
],
1
,
1000
,
0
,
50
,
helptext
=
"Min. particle
size (µm)
"
,
show
=
False
),
Parameter
(
"enableMaxArea"
,
np
.
bool
,
self
.
detectParams
[
'enableMaxArea'
],
helptext
=
"enable filtering for maximal p
ixel area
"
,
show
=
False
,
linkedParameter
=
'maxparticlearea'
),
Parameter
(
"enableMaxArea"
,
np
.
bool
,
self
.
detectParams
[
'enableMaxArea'
],
helptext
=
"enable filtering for maximal p
article size
"
,
show
=
False
,
linkedParameter
=
'maxparticlearea'
),
Parameter
(
"maxparticle
area
"
,
int
,
self
.
detectParams
[
'maxparticle
area
'
],
10
,
1E9
,
0
,
50
,
helptext
=
"Max. particle
pixel area
"
,
show
=
False
),
Parameter
(
"maxparticle
size
"
,
int
,
self
.
detectParams
[
'maxparticle
size
'
],
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
(
"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
(
"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
),
Parameter
(
"closeBackground"
,
np
.
bool
,
self
.
detectParams
[
'closeBackground'
],
helptext
=
"close holes in sure background"
,
show
=
False
),
...
@@ -238,10 +238,7 @@ class Segmentation(QtCore.QObject):
...
@@ -238,10 +238,7 @@ class Segmentation(QtCore.QObject):
if
self
.
cancelcomputation
:
if
self
.
cancelcomputation
:
return
None
,
None
return
None
,
None
if
self
.
enableMaxArea
:
minArea
,
maxArea
=
self
.
getMinMaxParticleArea
(
dataset
)
maxArea
=
self
.
maxparticlearea
else
:
maxArea
=
np
.
inf
##get sure_fg
##get sure_fg
'''the peak_local_max function takes the min distance between peaks. Unfortunately, that means that individual
'''the peak_local_max function takes the min distance between peaks. Unfortunately, that means that individual
...
@@ -265,7 +262,7 @@ class Segmentation(QtCore.QObject):
...
@@ -265,7 +262,7 @@ class Segmentation(QtCore.QObject):
for
label
in
range
(
1
,
n
):
for
label
in
range
(
1
,
n
):
area
=
stats
[
label
,
cv2
.
CC_STAT_AREA
]
area
=
stats
[
label
,
cv2
.
CC_STAT_AREA
]
if
self
.
minparticlea
rea
<
area
<
maxArea
:
if
minA
rea
<
area
<
maxArea
:
up
=
stats
[
label
,
cv2
.
CC_STAT_TOP
]
up
=
stats
[
label
,
cv2
.
CC_STAT_TOP
]
left
=
stats
[
label
,
cv2
.
CC_STAT_LEFT
]
left
=
stats
[
label
,
cv2
.
CC_STAT_LEFT
]
width
=
stats
[
label
,
cv2
.
CC_STAT_WIDTH
]
width
=
stats
[
label
,
cv2
.
CC_STAT_WIDTH
]
...
@@ -339,7 +336,7 @@ class Segmentation(QtCore.QObject):
...
@@ -339,7 +336,7 @@ class Segmentation(QtCore.QObject):
for
cnt
in
tmpcontours
:
for
cnt
in
tmpcontours
:
contourArea
=
cv2
.
contourArea
(
cnt
)
*
scaleFactor
**
2
contourArea
=
cv2
.
contourArea
(
cnt
)
*
scaleFactor
**
2
if
contourArea
>=
self
.
minparticlea
rea
:
if
contourArea
>=
minA
rea
:
tmplabel
=
markers
[
cnt
[
0
,
0
,
1
],
cnt
[
0
,
0
,
0
]]
tmplabel
=
markers
[
cnt
[
0
,
0
,
1
],
cnt
[
0
,
0
,
0
]]
if
tmplabel
==
0
:
if
tmplabel
==
0
:
continue
continue
...
@@ -404,6 +401,24 @@ class Segmentation(QtCore.QObject):
...
@@ -404,6 +401,24 @@ class Segmentation(QtCore.QObject):
self
.
detectionState
.
emit
(
f
'finished particle detection after
{
total_time
}
seconds'
)
self
.
detectionState
.
emit
(
f
'finished particle detection after
{
total_time
}
seconds'
)
return
measurementPoints
,
finalcontours
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
):
def
addToPreviewImage
(
self
,
subimg
,
up
,
left
,
previewImage
):
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment