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):
def
getMeasurementPixelCoords
(
self
):
coords
=
[]
# for particle in self.particles:
# for measurement in particle.getMeasurements():
for
meas
in
self
.
measurements
:
coords
.
append
([
meas
.
pixelcoord_x
,
meas
.
pixelcoord_y
])
return
coords
...
...
analysis/particlePainter.py
View file @
92f24fb4
...
...
@@ -23,7 +23,6 @@ from PyQt5 import QtWidgets, QtCore, QtGui
import
numpy
as
np
import
cv2
class
ParticlePainter
(
QtWidgets
.
QGraphicsItem
):
def
__init__
(
self
,
editorParent
,
img
,
topLeft
):
super
(
ParticlePainter
,
self
).
__init__
()
...
...
@@ -38,22 +37,20 @@ class ParticlePainter(QtWidgets.QGraphicsItem):
self
.
painting
=
False
self
.
erasing
=
False
self
.
minRadius
=
10
self
.
minRadius
=
5
self
.
maxRadius
=
500
self
.
radius
=
30
self
.
brect
=
QtCore
.
QRectF
(
0
,
0
,
1
,
1
)
self
.
imgTo
Pixmap
()
self
.
set
Pixmap
()
self
.
setBrect
()
def
imgTo
Pixmap
(
self
):
img
=
self
.
img
.
repeat
(
3
).
reshape
(
self
.
img
.
shape
[
0
],
self
.
img
.
shape
[
1
],
3
)
def
set
Pixmap
(
self
):
img
=
self
.
img
.
repeat
(
3
).
reshape
(
self
.
img
.
shape
[
0
],
self
.
img
.
shape
[
1
],
3
)
height
,
width
,
channel
=
img
.
shape
assert
channel
==
3
bytesPerLine
=
3
*
width
pix
=
QtGui
.
QPixmap
()
pix
.
convertFromImage
(
QtGui
.
QImage
(
img
.
data
,
width
,
height
,
bytesPerLine
,
QtGui
.
QImage
.
Format_RGB888
))
self
.
pixmap
=
pix
self
.
pixmap
=
QtGui
.
QPixmap
()
self
.
pixmap
.
convertFromImage
(
QtGui
.
QImage
(
img
.
data
,
width
,
height
,
bytesPerLine
,
QtGui
.
QImage
.
Format_RGB888
))
def
setBrect
(
self
):
x0
=
self
.
topLeft
[
1
]
...
...
@@ -101,48 +98,64 @@ class ParticlePainter(QtWidgets.QGraphicsItem):
elif
event
.
key
()
==
QtCore
.
Qt
.
Key_Return
:
self
.
editorParent
.
acceptPaintedResult
()
def
drawParticle
(
self
,
pos
):
pixelPos
=
round
(
pos
.
y
()
-
self
.
topLeft
[
0
]),
round
(
pos
.
x
()
-
self
.
topLeft
[
1
])
x_min
,
x_max
=
round
(
pixelPos
[
1
]
-
self
.
radius
/
2
),
round
(
pixelPos
[
1
]
+
self
.
radius
/
2
)
y_min
,
y_max
=
round
(
pixelPos
[
0
]
-
self
.
radius
/
2
),
round
(
pixelPos
[
0
]
+
self
.
radius
/
2
)
def
drawParticle
(
self
,
pixelPos
):
x_min
,
x_max
=
round
(
pixelPos
.
x
()
-
self
.
radius
),
round
(
pixelPos
.
x
()
+
self
.
radius
)
y_min
,
y_max
=
round
(
pixelPos
.
y
()
-
self
.
radius
),
round
(
pixelPos
.
y
()
+
self
.
radius
)
x_shift
=
y_shift
=
0
x_shift
=
y_shift
=
int
(
0
)
if
x_min
<
0
:
x_shift
=
x_min
elif
x_min
>=
self
.
img
.
shape
[
1
]:
x_shift
=
x_min
+
1
-
self
.
img
.
shape
[
1
]
x_shift
=
int
(
x_min
)
self
.
topLeft
[
1
]
-=
abs
(
x_min
)
elif
x_max
>=
self
.
img
.
shape
[
1
]:
x_shift
=
int
(
x_max
+
1
-
self
.
img
.
shape
[
1
])
if
y_min
<
0
:
y_shift
=
y_min
elif
y_min
>=
self
.
img
.
shape
[
0
]:
y_shift
=
y_min
+
1
-
self
.
img
.
shape
[
0
]
self
.
topLeft
[
0
]
-=
abs
(
y_min
)
y_shift
=
int
(
y_min
)
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
:
x_range
=
self
.
img
.
shape
[
1
]
+
abs
(
x_shift
)
y_range
=
self
.
img
.
shape
[
0
]
+
abs
(
y_shift
)
x_range
=
int
(
self
.
img
.
shape
[
1
]
+
abs
(
x_shift
))
y_range
=
int
(
self
.
img
.
shape
[
0
]
+
abs
(
y_shift
))
newImg
=
np
.
zeros
((
y_range
,
x_range
))
if
x_shift
<
0
:
if
y_shift
==
0
:
newImg
[
abs
(
x_shift
):,
:]
=
self
.
img
elif
y_shift
<
0
:
if
y_shift
<
0
:
newImg
[
abs
(
y_shift
):,
abs
(
x_shift
):]
=
self
.
img
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)
# center = (int(pos.x()+self.radius), int(pos.y()+self.radius))
# 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()
self
.
setPixmap
()
self
.
update
()
def
paint
(
self
,
painter
,
option
,
widget
):
painter
.
setPen
(
QtCore
.
Qt
.
white
)
...
...
analysis/particleeditor.py
View file @
92f24fb4
...
...
@@ -189,9 +189,10 @@ class ParticleEditor(QtCore.QObject):
self
.
storedAssignmend
=
newAssignment
contours
=
self
.
particleContainer
.
getParticleContoursByIndex
(
contourIndices
)
topLeft
=
self
.
getTopLeft
(
contours
)
img
,
self
.
xmin
,
self
.
ymin
,
self
.
padding
=
self
.
contoursToImg
(
contours
)
# topLeft = self.getTopLeft(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
.
viewparent
.
normalSize
()
...
...
@@ -201,7 +202,10 @@ class ParticleEditor(QtCore.QObject):
def
acceptPaintedResult
(
self
):
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
:
self
.
storedIndices
=
[]
self
.
storedAssignmend
=
None
...
...
@@ -258,7 +262,7 @@ class ParticleEditor(QtCore.QObject):
if
len
(
contours
)
>
1
:
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
newContour
=
contours
[
0
]
...
...
@@ -273,7 +277,7 @@ class ParticleEditor(QtCore.QObject):
#draw contours
xmin
=
cnt
[:,
0
,:][:,
0
].
min
()
ymin
=
cnt
[:,
0
,:][:,
1
].
min
()
return
ymin
,
xmin
return
[
ymin
,
xmin
]
def
mergeParticlesInParticleContainerAndSampleView
(
self
,
indices
,
newContour
,
stats
,
assignment
):
self
.
viewparent
.
addParticleContourToIndex
(
newContour
,
len
(
self
.
viewparent
.
contourItems
)
-
1
)
...
...
gepard.py
View file @
92f24fb4
...
...
@@ -326,12 +326,11 @@ if __name__ == '__main__':
if
not
os
.
path
.
exists
(
logpath
):
os
.
mkdir
(
logpath
)
logname
=
os
.
path
.
join
(
logpath
,
'logfile.txt'
)
#
# fp = open(logname, "a")
# sys.stderr = fp
# sys.stdout = fp
print
(
"starting GEPARD at: "
+
strftime
(
"%d %b %Y %H:%M:%S"
,
localtime
()),
flush
=
True
)
fp
=
open
(
logname
,
"a"
)
sys
.
stderr
=
fp
sys
.
stdout
=
fp
print
(
"starting GEPARD at: "
+
strftime
(
"%d %b %Y %H:%M:%S"
,
localtime
()),
flush
=
True
)
gepard
=
GEPARDMainWindow
(
logpath
)
gepard
.
showMaximized
()
...
...
sampleview.py
View file @
92f24fb4
...
...
@@ -268,14 +268,9 @@ class SampleView(QtWidgets.QGraphicsView):
if
self
.
particleEditor
is
None
:
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
:
# self.particleEditor.particleContoursChanged.connect(self.analysiswidget.updateHistogramsAndContours)
self
.
particleEditor
.
particleAssignmentChanged
.
connect
(
self
.
analysiswidget
.
updateHistogramsAndContours
)
def
setMicroscopeMode
(
self
):
...
...
@@ -381,9 +376,7 @@ class SampleView(QtWidgets.QGraphicsView):
self
.
dataset
.
readin
=
False
else
:
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'
])
x
,
y
,
z
=
self
.
dataset
.
mapToLengthRaman
([
pos
.
x
(),
pos
.
y
()],
microscopeMode
=
self
.
microscopeMode
,
noz
=
noz
)
if
z
is
not
None
:
...
...
viewitems.py
View file @
92f24fb4
...
...
@@ -29,7 +29,6 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
self
.
setZValue
(
1
)
self
.
setPos
(
pos
[
0
],
pos
[
1
])
self
.
setFlag
(
QtWidgets
.
QGraphicsItem
.
ItemIsSelectable
)
# self.setAcceptedMouseButtons(QtCore.Qt.AllButtons)
self
.
brect
=
QtCore
.
QRectF
(
0
,
0
,
1
,
1
)
self
.
contourData
=
contourData
...
...
@@ -56,9 +55,6 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
def
boundingRect
(
self
):
return
self
.
brect
# def createRamanScanIndices(self):
def
setIndex
(
self
,
index
):
self
.
particleIndex
=
index
...
...
@@ -83,13 +79,6 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
painter
.
drawPolygon
(
self
.
polygon
)
# def mousePressEvent(self, event):
# print('press in contour')
#
# def mouseMoveEvent(self, event):
# print('move in contour')
#
def
contextMenuEvent
(
self
,
event
):
if
self
.
isSelected
:
self
.
contextMenu
=
ParticleContextMenu
(
self
.
viewparent
)
...
...
@@ -170,14 +159,6 @@ class RamanScanIndicator(QtWidgets.QGraphicsItem):
painter
.
setFont
(
font
)
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
):
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