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
92f24fb4
Commit
92f24fb4
authored
Jul 19, 2019
by
Josef Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Particle Painting seems to be stable
parent
156ef9b8
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
71 additions
and
83 deletions
+71
-83
analysis/particleContainer.py
analysis/particleContainer.py
+1
-3
analysis/particlePainter.py
analysis/particlePainter.py
+53
-40
analysis/particleeditor.py
analysis/particleeditor.py
+10
-6
gepard.py
gepard.py
+5
-6
sampleview.py
sampleview.py
+2
-9
viewitems.py
viewitems.py
+0
-19
No files found.
analysis/particleContainer.py
View file @
92f24fb4
...
@@ -178,8 +178,6 @@ class ParticleContainer(object):
...
@@ -178,8 +178,6 @@ class ParticleContainer(object):
def
getMeasurementPixelCoords
(
self
):
def
getMeasurementPixelCoords
(
self
):
coords
=
[]
coords
=
[]
# for particle in self.particles:
# for measurement in particle.getMeasurements():
for
meas
in
self
.
measurements
:
for
meas
in
self
.
measurements
:
coords
.
append
([
meas
.
pixelcoord_x
,
meas
.
pixelcoord_y
])
coords
.
append
([
meas
.
pixelcoord_x
,
meas
.
pixelcoord_y
])
return
coords
return
coords
...
...
analysis/particlePainter.py
View file @
92f24fb4
...
@@ -23,7 +23,6 @@ from PyQt5 import QtWidgets, QtCore, QtGui
...
@@ -23,7 +23,6 @@ from PyQt5 import QtWidgets, QtCore, QtGui
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
class
ParticlePainter
(
QtWidgets
.
QGraphicsItem
):
class
ParticlePainter
(
QtWidgets
.
QGraphicsItem
):
def
__init__
(
self
,
editorParent
,
img
,
topLeft
):
def
__init__
(
self
,
editorParent
,
img
,
topLeft
):
super
(
ParticlePainter
,
self
).
__init__
()
super
(
ParticlePainter
,
self
).
__init__
()
...
@@ -38,22 +37,20 @@ class ParticlePainter(QtWidgets.QGraphicsItem):
...
@@ -38,22 +37,20 @@ class ParticlePainter(QtWidgets.QGraphicsItem):
self
.
painting
=
False
self
.
painting
=
False
self
.
erasing
=
False
self
.
erasing
=
False
self
.
minRadius
=
10
self
.
minRadius
=
5
self
.
maxRadius
=
500
self
.
maxRadius
=
500
self
.
radius
=
30
self
.
radius
=
30
self
.
brect
=
QtCore
.
QRectF
(
0
,
0
,
1
,
1
)
self
.
brect
=
QtCore
.
QRectF
(
0
,
0
,
1
,
1
)
self
.
imgTo
Pixmap
()
self
.
set
Pixmap
()
self
.
setBrect
()
self
.
setBrect
()
def
imgTo
Pixmap
(
self
):
def
set
Pixmap
(
self
):
img
=
self
.
img
.
repeat
(
3
).
reshape
(
self
.
img
.
shape
[
0
],
self
.
img
.
shape
[
1
],
3
)
img
=
self
.
img
.
repeat
(
3
).
reshape
(
self
.
img
.
shape
[
0
],
self
.
img
.
shape
[
1
],
3
)
height
,
width
,
channel
=
img
.
shape
height
,
width
,
channel
=
img
.
shape
assert
channel
==
3
bytesPerLine
=
3
*
width
bytesPerLine
=
3
*
width
pix
=
QtGui
.
QPixmap
()
self
.
pixmap
=
QtGui
.
QPixmap
()
pix
.
convertFromImage
(
QtGui
.
QImage
(
img
.
data
,
width
,
height
,
bytesPerLine
,
QtGui
.
QImage
.
Format_RGB888
))
self
.
pixmap
.
convertFromImage
(
QtGui
.
QImage
(
img
.
data
,
width
,
height
,
bytesPerLine
,
QtGui
.
QImage
.
Format_RGB888
))
self
.
pixmap
=
pix
def
setBrect
(
self
):
def
setBrect
(
self
):
x0
=
self
.
topLeft
[
1
]
x0
=
self
.
topLeft
[
1
]
...
@@ -101,48 +98,64 @@ class ParticlePainter(QtWidgets.QGraphicsItem):
...
@@ -101,48 +98,64 @@ class ParticlePainter(QtWidgets.QGraphicsItem):
elif
event
.
key
()
==
QtCore
.
Qt
.
Key_Return
:
elif
event
.
key
()
==
QtCore
.
Qt
.
Key_Return
:
self
.
editorParent
.
acceptPaintedResult
()
self
.
editorParent
.
acceptPaintedResult
()
def
drawParticle
(
self
,
pos
):
def
drawParticle
(
self
,
pixelPos
):
pixelPos
=
round
(
pos
.
y
()
-
self
.
topLeft
[
0
]),
round
(
pos
.
x
()
-
self
.
topLeft
[
1
])
x_min
,
x_max
=
round
(
pixelPos
.
x
()
-
self
.
radius
),
round
(
pixelPos
.
x
()
+
self
.
radius
)
x_min
,
x_max
=
round
(
pixelPos
[
1
]
-
self
.
radius
/
2
),
round
(
pixelPos
[
1
]
+
self
.
radius
/
2
)
y_min
,
y_max
=
round
(
pixelPos
.
y
()
-
self
.
radius
),
round
(
pixelPos
.
y
()
+
self
.
radius
)
y_min
,
y_max
=
round
(
pixelPos
[
0
]
-
self
.
radius
/
2
),
round
(
pixelPos
[
0
]
+
self
.
radius
/
2
)
x_shift
=
y_shift
=
0
x_shift
=
y_shift
=
int
(
0
)
if
x_min
<
0
:
if
x_min
<
0
:
x_shift
=
x_min
x_shift
=
int
(
x_min
)
elif
x_min
>=
self
.
img
.
shape
[
1
]:
self
.
topLeft
[
1
]
-=
abs
(
x_min
)
x_shift
=
x_min
+
1
-
self
.
img
.
shape
[
1
]
elif
x_max
>=
self
.
img
.
shape
[
1
]:
x_shift
=
int
(
x_max
+
1
-
self
.
img
.
shape
[
1
])
if
y_min
<
0
:
if
y_min
<
0
:
y_shift
=
y_min
self
.
topLeft
[
0
]
-=
abs
(
y_min
)
elif
y_min
>=
self
.
img
.
shape
[
0
]:
y_shift
=
int
(
y_min
)
y_shift
=
y_min
+
1
-
self
.
img
.
shape
[
0
]
elif
y_max
>=
self
.
img
.
shape
[
0
]:
y_shift
=
int
(
y_max
+
1
-
self
.
img
.
shape
[
0
])
if
x_shift
!=
0
or
y_shift
!=
0
:
if
x_shift
!=
0
or
y_shift
!=
0
:
x_range
=
self
.
img
.
shape
[
1
]
+
abs
(
x_shift
)
x_range
=
int
(
self
.
img
.
shape
[
1
]
+
abs
(
x_shift
))
y_range
=
self
.
img
.
shape
[
0
]
+
abs
(
y_shift
)
y_range
=
int
(
self
.
img
.
shape
[
0
]
+
abs
(
y_shift
))
newImg
=
np
.
zeros
((
y_range
,
x_range
))
newImg
=
np
.
zeros
((
y_range
,
x_range
))
if
x_shift
<
0
:
if
x_shift
<
0
:
if
y_shift
==
0
:
if
y_shift
<
0
:
newImg
[
abs
(
x_shift
):,
:]
=
self
.
img
newImg
[
abs
(
y_shift
):,
abs
(
x_shift
):]
=
self
.
img
elif
y_shift
<
0
:
elif
y_shift
==
0
:
newImg
[:,
abs
(
x_shift
):]
=
self
.
img
elif
y_shift
>
0
:
newImg
[:
self
.
img
.
shape
[
0
],
abs
(
x_shift
):]
=
self
.
img
elif
x_shift
==
0
:
if
y_shift
<
0
:
newImg
[
abs
(
y_shift
):,
:]
=
self
.
img
elif
y_shift
==
0
:
newImg
[:,
:]
=
self
.
img
elif
y_shift
>
0
:
newImg
[:
self
.
img
.
shape
[
0
],
:]
=
self
.
img
elif
x_shift
>
0
:
if
y_shift
<
0
:
newImg
[
abs
(
y_shift
):,
:
self
.
img
.
shape
[
1
]]
=
self
.
img
elif
y_shift
==
0
:
newImg
[:,
:
self
.
img
.
shape
[
1
]]
=
self
.
img
elif
y_shift
>
0
:
newImg
[:
y_shift
,
:
self
.
img
.
shape
[
1
]]
=
self
.
img
self
.
img
=
np
.
uint8
(
newImg
)
self
.
setBrect
()
center
=
(
int
(
pixelPos
.
x
()),
int
(
pixelPos
.
y
()))
if
self
.
painting
:
cv2
.
circle
(
self
.
img
,
center
,
self
.
radius
,
255
,
-
1
)
elif
self
.
erasing
:
cv2
.
circle
(
self
.
img
,
center
,
self
.
radius
,
0
,
-
1
)
# img, xmin, ymin, padding = self.contoursToImg(self.contours)
self
.
setPixmap
()
# center = (int(pos.x()+self.radius), int(pos.y()+self.radius))
self
.
update
()
# if self.painting:
# cv2.circle(img, center, self.radius, 255, -1)
# elif self.erasing:
# cv2.circle(img, center, self.radius, 0, -1)
#
# img = np.uint8(img)
# self.contours = self.imgToCnt(img, xmin, ymin, padding)
# self.getBrectAndPolygon()
# self.update()
def
paint
(
self
,
painter
,
option
,
widget
):
def
paint
(
self
,
painter
,
option
,
widget
):
painter
.
setPen
(
QtCore
.
Qt
.
white
)
painter
.
setPen
(
QtCore
.
Qt
.
white
)
...
...
analysis/particleeditor.py
View file @
92f24fb4
...
@@ -189,9 +189,10 @@ class ParticleEditor(QtCore.QObject):
...
@@ -189,9 +189,10 @@ class ParticleEditor(QtCore.QObject):
self
.
storedAssignmend
=
newAssignment
self
.
storedAssignmend
=
newAssignment
contours
=
self
.
particleContainer
.
getParticleContoursByIndex
(
contourIndices
)
contours
=
self
.
particleContainer
.
getParticleContoursByIndex
(
contourIndices
)
topLeft
=
self
.
getTopLeft
(
contours
)
# topLeft = self.getTopLeft(contours)
img
,
self
.
xmin
,
self
.
ymin
,
self
.
padding
=
self
.
contoursToImg
(
contours
)
# img, self.xmin, self.ymin, self.padding = self.contoursToImg(contours, padding=0)
img
,
xmin
,
ymin
,
self
.
padding
=
self
.
contoursToImg
(
contours
,
padding
=
0
)
topLeft
=
[
ymin
,
xmin
]
self
.
particlePainter
=
ParticlePainter
(
self
,
img
,
topLeft
)
self
.
particlePainter
=
ParticlePainter
(
self
,
img
,
topLeft
)
self
.
viewparent
.
normalSize
()
self
.
viewparent
.
normalSize
()
...
@@ -201,7 +202,10 @@ class ParticleEditor(QtCore.QObject):
...
@@ -201,7 +202,10 @@ class ParticleEditor(QtCore.QObject):
def
acceptPaintedResult
(
self
):
def
acceptPaintedResult
(
self
):
try
:
try
:
newContour
=
self
.
mergeContours
(
self
.
particlePainter
.
contours
)
img
=
self
.
particlePainter
.
img
xmin
=
self
.
particlePainter
.
topLeft
[
1
]
ymin
=
self
.
particlePainter
.
topLeft
[
0
]
newContour
=
self
.
imgToCnt
(
img
,
xmin
,
ymin
,
0
)
except
NotConnectedContoursError
:
except
NotConnectedContoursError
:
self
.
storedIndices
=
[]
self
.
storedIndices
=
[]
self
.
storedAssignmend
=
None
self
.
storedAssignmend
=
None
...
@@ -258,7 +262,7 @@ class ParticleEditor(QtCore.QObject):
...
@@ -258,7 +262,7 @@ class ParticleEditor(QtCore.QObject):
if
len
(
contours
)
>
1
:
if
len
(
contours
)
>
1
:
QtWidgets
.
QMessageBox
.
critical
(
self
.
viewparent
,
'ERROR!'
,
QtWidgets
.
QMessageBox
.
critical
(
self
.
viewparent
,
'ERROR!'
,
'Particle contours are not connected
and cannot be combin
ed!'
)
'Particle contours are not connected
or have holes.
\n
That is currently not support
ed!'
)
raise
NotConnectedContoursError
raise
NotConnectedContoursError
newContour
=
contours
[
0
]
newContour
=
contours
[
0
]
...
@@ -273,7 +277,7 @@ class ParticleEditor(QtCore.QObject):
...
@@ -273,7 +277,7 @@ class ParticleEditor(QtCore.QObject):
#draw contours
#draw contours
xmin
=
cnt
[:,
0
,:][:,
0
].
min
()
xmin
=
cnt
[:,
0
,:][:,
0
].
min
()
ymin
=
cnt
[:,
0
,:][:,
1
].
min
()
ymin
=
cnt
[:,
0
,:][:,
1
].
min
()
return
ymin
,
xmin
return
[
ymin
,
xmin
]
def
mergeParticlesInParticleContainerAndSampleView
(
self
,
indices
,
newContour
,
stats
,
assignment
):
def
mergeParticlesInParticleContainerAndSampleView
(
self
,
indices
,
newContour
,
stats
,
assignment
):
self
.
viewparent
.
addParticleContourToIndex
(
newContour
,
len
(
self
.
viewparent
.
contourItems
)
-
1
)
self
.
viewparent
.
addParticleContourToIndex
(
newContour
,
len
(
self
.
viewparent
.
contourItems
)
-
1
)
...
...
gepard.py
View file @
92f24fb4
...
@@ -326,12 +326,11 @@ if __name__ == '__main__':
...
@@ -326,12 +326,11 @@ if __name__ == '__main__':
if
not
os
.
path
.
exists
(
logpath
):
if
not
os
.
path
.
exists
(
logpath
):
os
.
mkdir
(
logpath
)
os
.
mkdir
(
logpath
)
logname
=
os
.
path
.
join
(
logpath
,
'logfile.txt'
)
logname
=
os
.
path
.
join
(
logpath
,
'logfile.txt'
)
#
# fp = open(logname, "a")
fp
=
open
(
logname
,
"a"
)
# sys.stderr = fp
sys
.
stderr
=
fp
# sys.stdout = fp
sys
.
stdout
=
fp
print
(
"starting GEPARD at: "
+
strftime
(
"%d %b %Y %H:%M:%S"
,
localtime
()),
print
(
"starting GEPARD at: "
+
strftime
(
"%d %b %Y %H:%M:%S"
,
localtime
()),
flush
=
True
)
flush
=
True
)
gepard
=
GEPARDMainWindow
(
logpath
)
gepard
=
GEPARDMainWindow
(
logpath
)
gepard
.
showMaximized
()
gepard
.
showMaximized
()
...
...
sampleview.py
View file @
92f24fb4
...
@@ -268,14 +268,9 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -268,14 +268,9 @@ class SampleView(QtWidgets.QGraphicsView):
if
self
.
particleEditor
is
None
:
if
self
.
particleEditor
is
None
:
self
.
particleEditor
=
ParticleEditor
(
self
,
self
.
dataset
.
particleContainer
)
self
.
particleEditor
=
ParticleEditor
(
self
,
self
.
dataset
.
particleContainer
)
#try disconnecting the signals. If they are connected multiple times, the functions will run accordingly...
# tryDisconnectingSignal(self.particleEditor.particleContoursChanged)
tryDisconnectingSignal
(
self
.
particleEditor
.
particleAssignmentChanged
)
# self.particleEditor.particleContoursChanged.connect(self.resetParticleContours)
tryDisconnectingSignal
(
self
.
particleEditor
.
particleAssignmentChanged
)
if
self
.
analysiswidget
is
not
None
:
if
self
.
analysiswidget
is
not
None
:
# self.particleEditor.particleContoursChanged.connect(self.analysiswidget.updateHistogramsAndContours)
self
.
particleEditor
.
particleAssignmentChanged
.
connect
(
self
.
analysiswidget
.
updateHistogramsAndContours
)
self
.
particleEditor
.
particleAssignmentChanged
.
connect
(
self
.
analysiswidget
.
updateHistogramsAndContours
)
def
setMicroscopeMode
(
self
):
def
setMicroscopeMode
(
self
):
...
@@ -381,9 +376,7 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -381,9 +376,7 @@ class SampleView(QtWidgets.QGraphicsView):
self
.
dataset
.
readin
=
False
self
.
dataset
.
readin
=
False
else
:
else
:
return
return
# x, y, z = self.dataset.mapToLengthRaman([p0.x(), p0.y()],
# microscopeMode=self.microscopeMode,
# noz=(False if self.mode=="RamanScan" else True))
noz
=
(
self
.
mode
in
[
'OpticalScan'
,
'RamanScan'
])
noz
=
(
self
.
mode
in
[
'OpticalScan'
,
'RamanScan'
])
x
,
y
,
z
=
self
.
dataset
.
mapToLengthRaman
([
pos
.
x
(),
pos
.
y
()],
microscopeMode
=
self
.
microscopeMode
,
noz
=
noz
)
x
,
y
,
z
=
self
.
dataset
.
mapToLengthRaman
([
pos
.
x
(),
pos
.
y
()],
microscopeMode
=
self
.
microscopeMode
,
noz
=
noz
)
if
z
is
not
None
:
if
z
is
not
None
:
...
...
viewitems.py
View file @
92f24fb4
...
@@ -29,7 +29,6 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
...
@@ -29,7 +29,6 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
self
.
setZValue
(
1
)
self
.
setZValue
(
1
)
self
.
setPos
(
pos
[
0
],
pos
[
1
])
self
.
setPos
(
pos
[
0
],
pos
[
1
])
self
.
setFlag
(
QtWidgets
.
QGraphicsItem
.
ItemIsSelectable
)
self
.
setFlag
(
QtWidgets
.
QGraphicsItem
.
ItemIsSelectable
)
# self.setAcceptedMouseButtons(QtCore.Qt.AllButtons)
self
.
brect
=
QtCore
.
QRectF
(
0
,
0
,
1
,
1
)
self
.
brect
=
QtCore
.
QRectF
(
0
,
0
,
1
,
1
)
self
.
contourData
=
contourData
self
.
contourData
=
contourData
...
@@ -56,9 +55,6 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
...
@@ -56,9 +55,6 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
def
boundingRect
(
self
):
def
boundingRect
(
self
):
return
self
.
brect
return
self
.
brect
# def createRamanScanIndices(self):
def
setIndex
(
self
,
index
):
def
setIndex
(
self
,
index
):
self
.
particleIndex
=
index
self
.
particleIndex
=
index
...
@@ -83,13 +79,6 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
...
@@ -83,13 +79,6 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
painter
.
drawPolygon
(
self
.
polygon
)
painter
.
drawPolygon
(
self
.
polygon
)
# def mousePressEvent(self, event):
# print('press in contour')
#
# def mouseMoveEvent(self, event):
# print('move in contour')
#
def
contextMenuEvent
(
self
,
event
):
def
contextMenuEvent
(
self
,
event
):
if
self
.
isSelected
:
if
self
.
isSelected
:
self
.
contextMenu
=
ParticleContextMenu
(
self
.
viewparent
)
self
.
contextMenu
=
ParticleContextMenu
(
self
.
viewparent
)
...
@@ -170,14 +159,6 @@ class RamanScanIndicator(QtWidgets.QGraphicsItem):
...
@@ -170,14 +159,6 @@ class RamanScanIndicator(QtWidgets.QGraphicsItem):
painter
.
setFont
(
font
)
painter
.
setFont
(
font
)
painter
.
drawText
(
rect
,
QtCore
.
Qt
.
AlignCenter
,
str
(
self
.
number
))
painter
.
drawText
(
rect
,
QtCore
.
Qt
.
AlignCenter
,
str
(
self
.
number
))
# def mousePressEvent(self, event):
# p = event.pos()
# x, y = p.x(), p.y()
# r = np.sqrt(x**2+y**2)
# if r<self.radius:
# self.view.selectRamanScanPoint(self.number, r)
# super().mouseReleaseEvent(event)
class
ScanIndicator
(
QtWidgets
.
QGraphicsItem
):
class
ScanIndicator
(
QtWidgets
.
QGraphicsItem
):
def
__init__
(
self
,
number
,
wx
,
wy
,
pos
=
(
0
,
0
)):
def
__init__
(
self
,
number
,
wx
,
wy
,
pos
=
(
0
,
0
)):
...
...
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