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
79594c9c
Commit
79594c9c
authored
Dec 04, 2019
by
JosefBrandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bugfix in handling invalid particles in detection.
parent
ff9142ea
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
22 deletions
+32
-22
analysis/particleContainer.py
analysis/particleContainer.py
+3
-1
detectionview.py
detectionview.py
+23
-10
segmentation.py
segmentation.py
+6
-11
No files found.
analysis/particleContainer.py
View file @
79594c9c
...
...
@@ -143,11 +143,13 @@ class ParticleContainer(object):
def
getParticleOfIndex
(
self
,
index
):
try
:
particle
=
self
.
particles
[
index
]
assert
particle
.
index
==
index
,
f
'particle.index (
{
particle
.
index
}
) does not match requested index in particleList (
{
index
}
)'
except
:
print
(
'failed getting particle'
)
print
(
'requested Index:'
,
index
)
print
(
'len particles'
,
len
(
self
.
particles
))
assert
particle
.
index
==
index
,
f
'particle.index (
{
particle
.
index
}
) does match requested index in particleList (
{
index
}
)'
raise
return
particle
def
getParticleIndexContainingSpecIndex
(
self
,
index
):
...
...
detectionview.py
View file @
79594c9c
...
...
@@ -264,8 +264,8 @@ class ImageView(QtWidgets.QLabel):
painter
.
drawPolygon
(
c
)
painter
.
setPen
(
QtCore
.
Qt
.
red
)
painter
.
setBrush
(
QtCore
.
Qt
.
red
)
for
p
in
self
.
measpoints
:
for
point
in
self
.
meas
points
[
p
]
:
for
p
oints
in
self
.
measpoints
:
for
point
in
points
:
painter
.
drawEllipse
(
point
.
x
-
2
,
point
.
y
-
2
,
5
,
5
)
if
self
.
showseedpoints
:
...
...
@@ -667,6 +667,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
self
.
dataset
.
mode
=
"opticalscan"
self
.
dataset
.
save
()
self
.
imageUpdate
.
emit
(
self
.
view
.
microscopeMode
)
self
.
view
.
resetParticleContours
()
@
QtCore
.
pyqtSlot
()
def
cancelThread
(
self
):
...
...
@@ -770,17 +771,19 @@ class ParticleDetectionView(QtWidgets.QWidget):
def
applyResultsToDataset
(
self
,
measurementPoints
,
contours
):
self
.
dataset
.
ramanscandone
=
False
particlestats
=
self
.
getParticleStats
(
contours
)
particlestats
,
invalidParticleIndices
=
self
.
getParticleStats
(
contours
)
contours
=
self
.
removeInvalidContours
(
contours
,
invalidParticleIndices
)
measurementPoints
=
self
.
removeInvalidMeasurementPoints
(
measurementPoints
,
invalidParticleIndices
)
particleContainer
=
self
.
dataset
.
particleContainer
numParticles
=
len
(
contours
)
particleContainer
.
initializeParticles
(
numParticles
)
particleContainer
.
setParticleContours
(
contours
)
particleContainer
.
setParticleStats
(
particlestats
)
particleContainer
.
clearMeasurements
()
for
particleIndex
in
measurementPoints
.
keys
():
measPoints
=
measurementPoints
[
particleIndex
]
for
particleIndex
,
measPoints
in
enumerate
(
measurementPoints
):
for
index
,
point
in
enumerate
(
measPoints
):
curParticle
=
particleContainer
.
getParticleOfIndex
(
particleIndex
)
indexOfNewMeas
=
particleContainer
.
addEmptyMeasurement
()
...
...
@@ -794,15 +797,25 @@ class ParticleDetectionView(QtWidgets.QWidget):
def
getParticleStats
(
self
,
contours
):
particlestats
=
[]
zvalimg
=
loadZValImageFromDataset
(
self
.
dataset
)
for
contour
in
contours
:
invalidParticleIndices
=
[]
for
contourIndex
,
contour
in
enumerate
(
contours
):
try
:
stats
=
getParticleStatsWithPixelScale
(
contour
,
self
.
dataset
,
fullimage
=
self
.
img
,
zimg
=
zvalimg
)
particlestats
.
append
(
stats
)
except
InvalidParticleError
:
print
(
'invalid contour in detection, skipping partile. Contour is:'
,
contour
)
print
(
'invalid contour in detection, skipping particle. Contour is:'
,
contour
)
invalidParticleIndices
.
append
(
contourIndex
)
continue
return
particlestats
particlestats
.
append
(
stats
)
return
particlestats
,
invalidParticleIndices
def
removeInvalidContours
(
self
,
contours
,
invalidParticleIndices
):
validContours
=
[
cnt
for
index
,
cnt
in
enumerate
(
contours
)
if
index
not
in
invalidParticleIndices
]
return
validContours
def
removeInvalidMeasurementPoints
(
self
,
measurementPoints
,
invalidParticleIndices
):
validMeasPoints
=
[
points
for
index
,
points
in
enumerate
(
measurementPoints
)
if
index
not
in
invalidParticleIndices
]
return
validMeasPoints
def
updateSeedsInSampleview
(
self
):
self
.
view
.
updateSeedPointMarkers
()
...
...
segmentation.py
View file @
79594c9c
...
...
@@ -30,7 +30,6 @@ import skfuzzy as fuzz
import
random
from
PyQt5
import
QtCore
def
closeHolesOfSubImage
(
subimg
):
subimg
=
cv2
.
copyMakeBorder
(
subimg
,
1
,
1
,
1
,
1
,
0
)
im_floodfill
=
subimg
.
copy
()
...
...
@@ -248,7 +247,7 @@ class Segmentation(QtCore.QObject):
self
.
detectionState
.
emit
(
f
'DO: maxVal=
{
n
-
1
}
'
)
del
thresh
measurementPoints
=
{}
measurementPoints
=
[]
finalcontours
=
[]
particleIndex
=
0
...
...
@@ -262,7 +261,7 @@ class Segmentation(QtCore.QObject):
for
label
in
range
(
1
,
n
):
area
=
stats
[
label
,
cv2
.
CC_STAT_AREA
]
if
minArea
<
area
<
maxArea
:
if
minArea
<
area
:
up
=
stats
[
label
,
cv2
.
CC_STAT_TOP
]
left
=
stats
[
label
,
cv2
.
CC_STAT_LEFT
]
width
=
stats
[
label
,
cv2
.
CC_STAT_WIDTH
]
...
...
@@ -336,7 +335,7 @@ class Segmentation(QtCore.QObject):
for
cnt
in
tmpcontours
:
contourArea
=
cv2
.
contourArea
(
cnt
)
*
scaleFactor
**
2
if
contourArea
>
=
m
in
Area
:
if
minArea
<=
contourArea
<
=
m
ax
Area
:
tmplabel
=
markers
[
cnt
[
0
,
0
,
1
],
cnt
[
0
,
0
,
0
]]
if
tmplabel
==
0
:
continue
...
...
@@ -362,11 +361,11 @@ class Segmentation(QtCore.QObject):
cnt
[
i
][
0
][
1
]
+=
up
finalcontours
.
append
(
cnt
)
measurementPoints
[
particleIndex
]
=
[]
measurementPoints
.
append
(
[]
)
for
index
in
range
(
0
,
len
(
x
)):
newMeasPoint
=
MeasurementPoint
(
particleIndex
,
x
[
index
]
+
x0
+
left
,
y
[
index
]
+
y0
+
up
)
measurementPoints
[
particleIndex
].
append
(
newMeasPoint
)
measurementPoints
[
-
1
].
append
(
newMeasPoint
)
particleIndex
+=
1
...
...
@@ -389,11 +388,7 @@ class Segmentation(QtCore.QObject):
if
self
.
measurefrac
<
1.0
:
nMeasurementsDesired
=
int
(
np
.
round
(
self
.
measurefrac
*
len
(
measurementPoints
)))
print
(
f
'selecting
{
nMeasurementsDesired
}
of
{
len
(
measurementPoints
)
}
measuring spots'
)
partIndicesToMeasure
=
random
.
sample
(
measurementPoints
.
keys
(),
nMeasurementsDesired
)
newMeasPoints
=
{}
for
index
in
partIndicesToMeasure
:
newMeasPoints
[
index
]
=
measurementPoints
[
index
]
measurementPoints
=
newMeasPoints
measurementPoints
=
random
.
sample
(
measurementPoints
,
nMeasurementsDesired
)
total_time
=
time
()
-
t0
print
(
'segmentation took'
,
total_time
,
'seconds'
)
...
...
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