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
96e55786
Commit
96e55786
authored
Jul 12, 2019
by
JosefBrandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Particle Combination works (bugfix needed)
parent
f0ab34e7
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
202 additions
and
174 deletions
+202
-174
analysis/analysisview.py
analysis/analysisview.py
+9
-6
analysis/particleInfo.py
analysis/particleInfo.py
+54
-12
analysis/particleeditor.py
analysis/particleeditor.py
+68
-113
dataset.py
dataset.py
+1
-1
detectionview.py
detectionview.py
+1
-1
sampleview.py
sampleview.py
+67
-41
viewitems.py
viewitems.py
+2
-0
No files found.
analysis/analysisview.py
View file @
96e55786
...
...
@@ -229,7 +229,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
fullOverlayAct
=
QtWidgets
.
QAction
(
"&Full Overlay"
,
self
)
self
.
transpAct
=
QtWidgets
.
QAction
(
"&Transparent Overlay"
,
self
)
self
.
transpAct
.
triggered
.
connect
(
self
.
updateContours
)
self
.
transpAct
.
triggered
.
connect
(
self
.
updateContour
Color
s
)
self
.
hideLabelAct
=
QtWidgets
.
QAction
(
'&Hide Polymer Numbers'
,
self
)
self
.
hideLabelAct
.
triggered
.
connect
(
self
.
show_hide_labels
)
...
...
@@ -262,7 +262,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
dispMenu
=
QtWidgets
.
QMenu
(
"&Display"
,
self
)
self
.
overlayActGroup
=
QtWidgets
.
QActionGroup
(
self
.
dispMenu
)
self
.
overlayActGroup
.
setExclusive
(
True
)
self
.
overlayActGroup
.
triggered
.
connect
(
self
.
updateContours
)
self
.
overlayActGroup
.
triggered
.
connect
(
self
.
updateContour
Color
s
)
self
.
overlayActGroup
.
triggered
.
connect
(
self
.
updateDisplays
)
for
act
in
[
self
.
noOverlayAct
,
self
.
selOverlayAct
,
self
.
fullOverlayAct
]:
...
...
@@ -387,6 +387,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
# self.displayNewPolymerType()
def
updateDisplays
(
self
):
self
.
createHistogramData
()
t0
=
time
.
time
()
self
.
updateTypeHistogram
()
print
(
'update type hist:'
,
round
((
time
.
time
()
-
t0
)
*
1000
))
...
...
@@ -394,7 +395,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
updateSizeHistogram
()
print
(
'update size hist:'
,
round
((
time
.
time
()
-
t0
)
*
1000
))
t0
=
time
.
time
()
self
.
updateContours
()
self
.
updateContour
Color
s
()
print
(
'update contours:'
,
round
((
time
.
time
()
-
t0
)
*
1000
))
t0
=
time
.
time
()
self
.
updateLegend
()
...
...
@@ -471,7 +472,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
ref
=
self
.
dbWin
.
activeDatabase
.
spectra
[
refID
]
self
.
specPlot
.
updateReferenceSpectrum
(
ref
[:,
0
],
ref
[:,
1
])
def
updateContours
(
self
):
def
updateContour
Color
s
(
self
):
contours
=
self
.
parent
.
contourItems
alpha
=
(
128
if
self
.
transpAct
.
isChecked
()
else
255
)
selectedPolymers
=
self
.
getSelectedPolymers
()
...
...
@@ -521,7 +522,9 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
spectrumSelector
.
setValue
(
1
)
self
.
currentParticleIndex
=
self
.
getParticleIndexFromParticleSelector
()
self
.
spectrumSelector
.
setMaximum
(
self
.
particleContainer
.
getNumberOfSpectraOfParticle
(
self
.
currentParticleIndex
))
numSpectra
=
self
.
particleContainer
.
getNumberOfSpectraOfParticle
(
self
.
currentParticleIndex
)
self
.
spectrumSelector
.
setMaximum
(
numSpectra
)
self
.
spectrumNumberLabel
.
setText
(
f
'of
{
numSpectra
}
Spectra'
)
self
.
currentSpectrumIndex
=
self
.
getSpectrumIndexFromSpectrumSelector
()
self
.
updateSpecPlot
(
centerOn
=
False
)
...
...
analysis/particleInfo.py
View file @
96e55786
...
...
@@ -42,9 +42,11 @@ class ParticleContainer(object):
def
initializeParticles
(
self
,
numParticles
):
self
.
particles
=
[]
for
i
in
range
(
numParticles
):
self
.
particles
.
append
(
Particle
(
i
))
newParticle
=
Particle
()
newParticle
.
index
=
i
self
.
particles
.
append
(
newParticle
)
def
setParticle
c
ontours
(
self
,
contours
):
def
setParticle
C
ontours
(
self
,
contours
):
assert
len
(
self
.
particles
)
==
len
(
contours
)
for
index
,
particle
in
enumerate
(
self
.
particles
):
particle
.
contour
=
contours
[
index
]
...
...
@@ -212,14 +214,49 @@ class ParticleContainer(object):
typehistogram
[
assignment
]
+=
1
##sort typehistogram, it will be converted into a list!!
sorted_typehistogram
=
sorted
(
typehistogram
.
items
(),
key
=
operator
.
itemgetter
(
1
),
reverse
=
True
)
#convert back to dict
#convert back to d
setParticlecontours
ict
final_typehistogram
=
{
i
[
0
]:
i
[
1
]
for
i
in
sorted_typehistogram
}
return
final_typehistogram
def
mergeParticles
(
self
,
particleIndices
,
newContour
,
newStats
,
newAssignment
=
None
):
newParticle
=
Particle
()
#copy Measurements
for
index
in
particleIndices
:
particle
=
self
.
getParticleOfIndex
(
index
)
for
meas
in
particle
.
getMeasurements
():
if
newAssignment
is
not
None
:
meas
.
setAssignment
(
newAssignment
)
meas
.
setHQI
(
100
)
newParticle
.
addExistingMeasurement
(
meas
)
#set Particle Stats
long
,
short
,
longellipse
,
shortellipse
,
area
=
newStats
newParticle
.
longSize_box
=
long
newParticle
.
shortSize_box
=
short
newParticle
.
longSize_ellipse
=
longellipse
newParticle
.
shortSize_ellipse
=
shortellipse
newParticle
.
area
=
area
newParticle
.
contour
=
newContour
self
.
particles
.
append
(
newParticle
)
self
.
removeParticles
(
particleIndices
)
self
.
resetParticleIndices
()
def
removeParticles
(
self
,
indexList
):
for
index
in
indexList
:
particle
=
self
.
getParticleOfIndex
(
index
)
print
(
'removing particle of index'
,
index
)
self
.
particles
.
remove
(
particle
)
def
resetParticleIndices
(
self
):
for
newIndex
,
particle
in
enumerate
(
self
.
particles
):
particle
.
index
=
newIndex
class
Particle
(
object
):
def
__init__
(
self
,
index
):
self
.
index
=
index
def
__init__
(
self
):
super
(
Particle
,
self
).
__init__
()
self
.
index
=
None
self
.
longSize_ellipse
=
np
.
nan
self
.
shortSize_ellipse
=
np
.
nan
self
.
longSize_box
=
np
.
nan
...
...
@@ -228,6 +265,9 @@ class Particle(object):
self
.
contour
=
None
self
.
measurements
=
[]
def
addExistingMeasurement
(
self
,
meas
):
self
.
measurements
.
append
(
meas
)
def
addEmptyMeasurement
(
self
):
self
.
measurements
.
append
(
Measurement
())
indexOfNewMeasurment
=
len
(
self
.
measurements
)
-
1
...
...
@@ -318,6 +358,7 @@ class Particle(object):
class
Measurement
(
object
):
def
__init__
(
self
):
super
(
Measurement
,
self
).
__init__
()
self
.
ramanScanIndex
=
None
self
.
pixelcoord_x
=
None
self
.
pixelcoord_y
=
None
...
...
@@ -328,13 +369,14 @@ class Measurement(object):
def
setAssignment
(
self
,
assignment
):
self
.
assignment_orig
=
assignment
self
.
a
ssignment_afterHQI
=
'unknown'
self
.
a
pplyHQIThreshold
()
def
setHQI
(
self
,
hqi
):
self
.
hqi
=
hqi
self
.
applyHQIThreshold
()
def
applyHQIThreshold
(
self
,
minHQI
=
0
):
if
self
.
hqi
is
not
None
:
#i.e. skip for initial setup, when hqi is not yet aplied...
if
self
.
hqi
>=
minHQI
:
self
.
assignment_afterHQI
=
self
.
assignment_orig
else
:
...
...
analysis/particleeditor.py
View file @
96e55786
...
...
@@ -70,15 +70,26 @@ class ParticleContextMenu(QtWidgets.QMenu):
action
=
self
.
exec_
(
screenPos
)
if
action
in
self
.
combineActs
:
newAssignment
=
action
.
text
()
newAssignment
=
self
.
validifyAssignment
(
action
.
text
()
)
self
.
combineParticlesSignal
.
emit
(
self
.
selectedParticleIndices
,
newAssignment
)
elif
action
in
self
.
reassignActs
:
newAssignment
=
action
.
text
()
newAssignment
=
self
.
validifyAssignment
(
action
.
text
()
)
self
.
reassignParticlesSignal
.
emit
(
self
.
selectedParticleIndices
,
newAssignment
)
def
validifyAssignment
(
self
,
assignment
):
if
assignment
==
"other"
:
assignment
=
self
.
getNewEntry
()
return
assignment
def
getNewEntry
(
self
):
text
,
okClicked
=
QtWidgets
.
QInputDialog
.
getText
(
QtWidgets
.
QWidget
(),
"Custom assignment"
,
"Enter new assignment"
)
if
okClicked
and
text
!=
''
:
return
text
class
ParticleEditor
(
QtCore
.
QObject
):
particlesWereEdited
=
QtCore
.
pyqtSignal
()
particleEditProcessStarted
=
QtCore
.
pyqtSignal
()
particlesEdited
=
QtCore
.
pyqtSignal
()
def
__init__
(
self
,
sampleView
,
particleContainer
):
super
(
ParticleEditor
,
self
).
__init__
()
self
.
particleContainer
=
particleContainer
...
...
@@ -99,108 +110,18 @@ class ParticleEditor(QtCore.QObject):
self
.
neverBackedUp
=
False
self
.
actionCounter
=
0
def
getNewEntry
(
self
):
text
,
okClicked
=
QtWidgets
.
QInputDialog
.
getText
(
QtWidgets
.
QWidget
(),
"Custom assignment"
,
"Enter new assignment"
)
if
okClicked
and
text
!=
''
:
return
text
@
QtCore
.
pyqtSlot
(
list
,
str
)
def
combineParticles
(
self
,
contourIndices
,
new_assignment
):
print
(
contourIndices
,
new_assignment
)
# if new_assignment == 'other':
# new_assignment = self.getNewEntry()
# if new_assignment is None:
# return
#
# contourIndices = sorted(contourIndices) #we want to keep the contour with lowest index
# #get contours:
# contours = self.particleContainer.getParticleContoursByIndex(contourIndices)
## contours = [self.datastats.dataset.particlecontours[i] for i in contourIndices]
# cnt = np.vstack(tuple(contours)) #combine contous
#
# #draw contours
# xmin, xmax = cnt[:,0,:][:, 0].min(), cnt[:,0,:][:, 0].max()
# ymin, ymax = cnt[:,0,:][:, 1].min(), cnt[:,0,:][:, 1].max()
#
# padding = 2 #pixel in each direction
# rangex = int(np.round((xmax-xmin)+2*padding))
# rangey = int(np.round((ymax-ymin)+2*padding))
#
# img = np.zeros((rangey, rangex))
# for i in contourIndices:
# curCnt = self.particleContainer.getParticleContoursByIndex(i).copy()
## curCnt = self.datastats.dataset.particlecontours[i].copy()
# for i in range(len(curCnt)):
# curCnt[i][0][0] -= xmin-padding
# curCnt[i][0][1] -= ymin-padding
#
# cv2.drawContours(img, [curCnt], -1, 1, -1)
# cv2.drawContours(img, [curCnt], -1, 1, 1)
#
# img = np.uint8(cv2.morphologyEx(img, cv2.MORPH_CLOSE, np.ones((3, 3))))
#
# if cv2.__version__ > '3.5':
# contours, hierarchy = cv2.findContours(img, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
# else:
# temp, contours, hierarchy = cv2.findContours(img, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
#
# if len(contours)>1:
# QtWidgets.QMessageBox.critical(self.parent, 'ERROR!',
# 'Particle contours are not connected and cannot be combined!')
# return
#
# newContour = contours[0]
# stats = self.characterizeParticle(newContour)
#dateContours()
# for i in range(len(newContour)):
# newContour[i][0][0] += xmin-padding
# newContour[i][0][1] += ymin-padding
#
# print('merging contours:', contourIndices)
# self.createSafetyBackup()
#
## #check, if dataset contains (already modified) particle2spectra, otherwise create new.
## if self.datastats.dataset.particles2spectra is None: #create default assignment
## print('recreating particles2spectra from within edit particles...')
## sortindices = self.datastats.dataset.ramanscansortindex
## self.datastats.dataset.particles2spectra = [[int(np.where(sortindices == i)[0])] for i in range(len(sortindices))]
#
# #Contour indices are the same as the original particlestats, which are contained in the dataset.
# #We have to modify that and reload in the analysisview
# #first, overwrite first index with new particlestats
# self.datastats.dataset.particlestats[contourIndices[0]] = stats
#
# #now, delete the rest...
# self.datastats.dataset.particlestats = [i for ind, i in enumerate(self.datastats.dataset.particlestats) if ind not in contourIndices[1:]]
#
# #same with the contours
# self.datastats.dataset.particlecontours[contourIndices[0]] = newContour
# self.datastats.dataset.particlecontours = [i for ind, i in enumerate(self.datastats.dataset.particlecontours) if ind not in contourIndices[1:]]
#
# #update particle2spectra_list
# #what is the current particle index??
# specIndices = []
# #other spectra indices:
# for index in contourIndices:
# specIndices.append(self.datastats.particles2spectra[index])
#
# #flatten index list (in case, that a nested list was created...)
# specIndices = list(np.concatenate(specIndices))
# for i in specIndices:
# self.datastats.spectraResults[i] = new_assignment
# self.datastats.hqis[i] = 100 #avoid sorting them out again by hqi-filter...
# print(f'spectrum {i} of particle{contourIndices[0]} is now {new_assignment}')
#
# #modify particles2spectra..
# self.datastats.dataset.particles2spectra[contourIndices[0]] = specIndices
# for index in reversed(contourIndices[1:]):
# print('removing index from particles2spectra:', index)
# del self.datastats.dataset.particles2spectra[index]
#
# #update contours in sampleview
# self.parent.parent.contouritem.resetContours(self.datastats.dataset.particlecontours)
# self.parent.loadParticleData()
def
combineParticles
(
self
,
contourIndices
,
newAssignment
):
self
.
particleEditProcessStarted
.
emit
()
self
.
createSafetyBackup
()
print
(
f
'Combining particles
{
contourIndices
}
into
{
newAssignment
}
'
)
contours
=
self
.
particleContainer
.
getParticleContoursByIndex
(
contourIndices
)
newContour
=
self
.
mergeContours
(
contours
.
copy
())
stats
=
self
.
characterizeParticle
(
newContour
)
self
.
particleContainer
.
mergeParticles
(
contourIndices
,
newContour
,
stats
,
newAssignment
=
newAssignment
)
self
.
particlesEdited
.
emit
()
# #save data
# minHQI = self.parent.hqiSpinBox.value()
# compHQI = self.parent.compHqiSpinBox.value()
...
...
@@ -210,18 +131,52 @@ class ParticleEditor(QtCore.QObject):
# QtWidgets.QMessageBox.Ok)
@
QtCore
.
pyqtSlot
(
list
,
str
)
def
reassignParticles
(
self
,
contourindices
,
new_assignment
):
if
new_assignment
==
'other'
:
new_assignment
=
self
.
getNewEntry
()
if
new_assignment
is
None
:
return
def
reassignParticles
(
self
,
contourindices
,
newAssignment
):
self
.
particleEditProcessStarted
.
emit
()
self
.
createSafetyBackup
()
print
(
f
'reassigning indices
{
contourindices
}
into
{
new
_a
ssignment
}
'
)
print
(
f
'reassigning indices
{
contourindices
}
into
{
new
A
ssignment
}
'
)
for
partIndex
in
contourindices
:
self
.
particleContainer
.
reassignParticleToAssignment
(
partIndex
,
new_assignment
)
self
.
particleContainer
.
reassignParticleToAssignment
(
partIndex
,
newAssignment
)
self
.
particlesEdited
.
emit
()
def
mergeContours
(
self
,
contours
):
cnt
=
np
.
vstack
(
tuple
(
contours
))
#combine contous
#draw contours
xmin
,
xmax
=
cnt
[:,
0
,:][:,
0
].
min
(),
cnt
[:,
0
,:][:,
0
].
max
()
ymin
,
ymax
=
cnt
[:,
0
,:][:,
1
].
min
(),
cnt
[:,
0
,:][:,
1
].
max
()
padding
=
2
#pixel in each direction
rangex
=
int
(
np
.
round
((
xmax
-
xmin
)
+
2
*
padding
))
rangey
=
int
(
np
.
round
((
ymax
-
ymin
)
+
2
*
padding
))
img
=
np
.
zeros
((
rangey
,
rangex
))
for
curCnt
in
contours
:
for
i
in
range
(
len
(
curCnt
)):
curCnt
[
i
][
0
][
0
]
-=
xmin
-
padding
curCnt
[
i
][
0
][
1
]
-=
ymin
-
padding
cv2
.
drawContours
(
img
,
[
curCnt
],
-
1
,
1
,
-
1
)
cv2
.
drawContours
(
img
,
[
curCnt
],
-
1
,
1
,
1
)
img
=
np
.
uint8
(
cv2
.
morphologyEx
(
img
,
cv2
.
MORPH_CLOSE
,
np
.
ones
((
3
,
3
))))
if
cv2
.
__version__
>
'3.5'
:
contours
,
hierarchy
=
cv2
.
findContours
(
img
,
cv2
.
RETR_CCOMP
,
cv2
.
CHAIN_APPROX_NONE
)
else
:
temp
,
contours
,
hierarchy
=
cv2
.
findContours
(
img
,
cv2
.
RETR_CCOMP
,
cv2
.
CHAIN_APPROX_NONE
)
if
len
(
contours
)
>
1
:
QtWidgets
.
QMessageBox
.
critical
(
self
.
parent
,
'ERROR!'
,
'Particle contours are not connected and cannot be combined!'
)
return
newContour
=
contours
[
0
]
for
i
in
range
(
len
(
newContour
)):
newContour
[
i
][
0
][
0
]
+=
xmin
-
padding
newContour
[
i
][
0
][
1
]
+=
ymin
-
padding
return
newContour
self
.
particlesWereEdited
.
emit
()
def
characterizeParticle
(
self
,
contours
):
##characterize particle
...
...
dataset.py
View file @
96e55786
...
...
@@ -257,7 +257,7 @@ class DataSet(object):
self
.
particleContainer
.
initializeParticles
(
len
(
self
.
particlestats
))
self
.
particleContainer
.
setParticle
c
ontours
(
self
.
particlecontours
)
self
.
particleContainer
.
setParticle
C
ontours
(
self
.
particlecontours
)
self
.
particleContainer
.
setParticleStats
(
self
.
particlestats
)
self
.
particleContainer
.
applyPixelScaleToParticleStats
(
self
.
getPixelScale
())
if
hasattr
(
self
,
'particles2spectra'
):
...
...
detectionview.py
View file @
96e55786
...
...
@@ -664,7 +664,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
particleContainer
=
self
.
dataset
.
particleContainer
particleContainer
.
initializeParticles
(
numParticles
)
particleContainer
.
setParticle
c
ontours
(
contours
)
particleContainer
.
setParticle
C
ontours
(
contours
)
particleContainer
.
setParticleStats
(
particlestats
)
particleContainer
.
applyPixelScaleToParticleStats
(
self
.
dataset
.
getPixelScale
())
...
...
sampleview.py
View file @
96e55786
...
...
@@ -58,6 +58,8 @@ class SampleView(QtWidgets.QGraphicsView):
self
.
setRenderHint
(
QtGui
.
QPainter
.
Antialiasing
)
self
.
setTransformationAnchor
(
QtWidgets
.
QGraphicsView
.
AnchorUnderMouse
)
self
.
setResizeAnchor
(
QtWidgets
.
QGraphicsView
.
AnchorViewCenter
)
self
.
disableSelection
=
False
self
.
ramanctrl
=
RamanControl
()
self
.
simulatedRaman
=
simulatedRaman
#determine, if ramanSwitch is needed:
...
...
@@ -177,7 +179,7 @@ class SampleView(QtWidgets.QGraphicsView):
self
.
detectionwidget
.
close
()
self
.
detectionwidget
.
destroy
()
self
.
ramanwidget
.
setVisible
(
False
)
self
.
update
ParticleContours
()
self
.
reset
ParticleContours
()
self
.
mode
=
mode
self
.
loadPixmap
(
self
.
microscopeMode
)
if
mode
==
"OpticalScan"
:
...
...
@@ -202,7 +204,7 @@ class SampleView(QtWidgets.QGraphicsView):
print
(
'creating new analysiswidget'
)
self
.
analysiswidget
=
ParticleAnalysis
(
self
.
dataset
,
self
)
self
.
analysiswidget
.
showMaximized
()
self
.
particleEditor
.
particlesWereEdited
.
connect
(
self
.
analysiswidget
.
updateDisplays
)
self
.
setupParticleEditor
(
)
else
:
print
(
'show maximized already exisiting analysiswidget'
)
self
.
analysiswidget
.
showMaximized
()
...
...
@@ -228,10 +230,9 @@ class SampleView(QtWidgets.QGraphicsView):
widget
.
destroy
()
del
widget
self
.
updateParticleContours
()
self
.
dataset
=
loadData
(
fname
)
self
.
particleEditor
=
ParticleEditor
(
self
,
self
.
dataset
.
particleContainer
)
self
.
resetParticleContours
()
self
.
setupParticleEditor
()
self
.
setMicroscopeMode
()
self
.
imparent
.
setWindowTitle
(
self
.
dataset
.
name
+
(
" SIMULATION"
if
simulatedRaman
else
""
))
self
.
imgdata
=
None
...
...
@@ -250,13 +251,23 @@ class SampleView(QtWidgets.QGraphicsView):
if
self
.
dataset
is
not
None
:
self
.
dataset
.
save
()
self
.
dataset
=
DataSet
(
fname
,
newProject
=
True
)
self
.
particleEditor
=
ParticleEditor
(
self
,
self
.
dataset
.
particleContainer
)
self
.
setupParticleEditor
(
)
self
.
setMicroscopeMode
()
self
.
imparent
.
setWindowTitle
(
self
.
dataset
.
name
+
(
" SIMULATION"
if
simulatedRaman
else
""
))
self
.
imgdata
=
None
self
.
activateMaxMode
(
loadnew
=
True
)
self
.
imparent
.
snapshotAct
.
setEnabled
(
True
)
def
setupParticleEditor
(
self
):
if
self
.
particleEditor
is
None
:
self
.
particleEditor
=
ParticleEditor
(
self
,
self
.
dataset
.
particleContainer
)
self
.
particleEditor
.
particleEditProcessStarted
.
connect
(
self
.
disableContourSelection
)
self
.
particleEditor
.
particlesEdited
.
connect
(
self
.
resetParticleContours
)
self
.
particleEditor
.
particlesEdited
.
connect
(
self
.
enableContourSelection
)
if
self
.
analysiswidget
is
not
None
:
self
.
particleEditor
.
particlesEdited
.
connect
(
self
.
analysiswidget
.
updateDisplays
)
def
setMicroscopeMode
(
self
):
if
self
.
ramanSwitchNeeded
:
self
.
imparent
.
ramanSwitch
.
connectToSampleView
()
...
...
@@ -295,6 +306,7 @@ class SampleView(QtWidgets.QGraphicsView):
return
maxmode
def
mousePressEvent
(
self
,
event
):
if
not
self
.
disableSelection
:
if
event
.
button
()
==
QtCore
.
Qt
.
MiddleButton
:
self
.
drag
=
event
.
pos
()
elif
event
.
button
()
==
QtCore
.
Qt
.
LeftButton
:
...
...
@@ -313,9 +325,9 @@ 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))
# x, y, z = self.dataset.mapToLengthRaman([p0.x(), p0.y()],
# microscopeMode=self.microscopeMode,
# noz=(False if self.mode=="RamanScan" else True))
x
,
y
,
z
=
self
.
dataset
.
mapToLengthRaman
([
p0
.
x
(),
p0
.
y
()],
microscopeMode
=
self
.
microscopeMode
,
noz
=
False
)
if
z
is
not
None
:
assert
z
>-
100.
...
...
@@ -411,7 +423,7 @@ class SampleView(QtWidgets.QGraphicsView):
@
QtCore
.
pyqtSlot
(
str
)
def
detectionUpdate
(
self
):
self
.
update
ParticleContours
()
self
.
reset
ParticleContours
()
self
.
prepareAnalysis
()
self
.
update
()
...
...
@@ -424,7 +436,7 @@ class SampleView(QtWidgets.QGraphicsView):
data
=
self
.
imgdata
fname
=
self
.
dataset
.
getImageName
()
if
self
.
mode
==
"ParticleDetection"
or
self
.
mode
==
"ParticleAnalysis"
:
self
.
update
ParticleContours
()
self
.
reset
ParticleContours
()
if
data
is
None
and
os
.
path
.
exists
(
fname
):
data
=
cv2
.
cvtColor
(
cv2imread_fix
(
fname
),
cv2
.
COLOR_BGR2RGB
)
self
.
imgdata
=
data
...
...
@@ -527,12 +539,17 @@ class SampleView(QtWidgets.QGraphicsView):
self
.
scene
().
addItem
(
item
)
self
.
ramanscanitems
.
append
(
item
)
def
update
ParticleContours
(
self
):
def
reset
ParticleContours
(
self
):
for
cnt
in
self
.
contourItems
:
self
.
scene
().
removeItem
(
cnt
)
self
.
contourItems
=
[]
if
self
.
dataset
is
not
None
:
for
particleIndex
,
contour
in
enumerate
(
self
.
dataset
.
particleContainer
.
getParticleContours
()):
###
part
=
self
.
dataset
.
particleContainer
.
getParticleOfIndex
(
particleIndex
)
if
part
.
index
!=
particleIndex
:
print
(
'missmatch at countour index and particleIndex'
,
part
.
index
,
particleIndex
)
###
newCnt
=
SegmentationContour
(
self
,
contour
)
newCnt
.
setIndex
(
particleIndex
)
assignment
=
self
.
dataset
.
particleContainer
.
getParticleAssignmentByIndex
(
particleIndex
)
...
...
@@ -540,8 +557,17 @@ class SampleView(QtWidgets.QGraphicsView):
newCnt
.
setColor
(
QtGui
.
QColor
(
color
[
0
],
color
[
1
],
color
[
2
],
255
))
self
.
contourItems
.
append
(
newCnt
)
self
.
scene
().
addItem
(
newCnt
)
self
.
update
()
def
disableContourSelection
(
self
):
self
.
disableSelection
=
True
# for contourItem in self.contourItems:
# contourItem.setAcceptedMouseButtons(QtCore.Qt.NoButton)
def
enableContourSelection
(
self
):
self
.
disableSelection
=
False
# for contourItem in self.contourItems:
# contourItem.setAcceptedMouseButtons(QtCore.Qt.AllButtons)
def
updateLegend
(
self
,
legendItems
):
self
.
imparent
.
legend
.
setTextColorItems
(
legendItems
)
...
...
viewitems.py
View file @
96e55786
...
...
@@ -26,6 +26,7 @@ class SegmentationContour(QtWidgets.QGraphicsItem):
def
__init__
(
self
,
parent
,
contourData
,
pos
=
(
0
,
0
)):
super
().
__init__
()
self
.
parent
=
parent
self
.
setZValue
(
1
)
self
.
setPos
(
pos
[
0
],
pos
[
1
])
self
.
setFlag
(
QtWidgets
.
QGraphicsItem
.
ItemIsSelectable
)
self
.
setAcceptedMouseButtons
(
QtCore
.
Qt
.
AllButtons
)
...
...
@@ -254,6 +255,7 @@ class RamanScanIndicator(QtWidgets.QGraphicsItem):
super
().
__init__
()
# self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable)
self
.
setAcceptedMouseButtons
(
QtCore
.
Qt
.
NoButton
)
self
.
setZValue
(
100
)
#higher numbers will be in foreground. Shall always be in foreground!
self
.
view
=
view
self
.
number
=
number
self
.
radius
=
radius
...
...
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