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
Hide 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):
...
@@ -229,7 +229,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
fullOverlayAct
=
QtWidgets
.
QAction
(
"&Full Overlay"
,
self
)
self
.
fullOverlayAct
=
QtWidgets
.
QAction
(
"&Full Overlay"
,
self
)
self
.
transpAct
=
QtWidgets
.
QAction
(
"&Transparent 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
=
QtWidgets
.
QAction
(
'&Hide Polymer Numbers'
,
self
)
self
.
hideLabelAct
.
triggered
.
connect
(
self
.
show_hide_labels
)
self
.
hideLabelAct
.
triggered
.
connect
(
self
.
show_hide_labels
)
...
@@ -262,7 +262,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
...
@@ -262,7 +262,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
dispMenu
=
QtWidgets
.
QMenu
(
"&Display"
,
self
)
self
.
dispMenu
=
QtWidgets
.
QMenu
(
"&Display"
,
self
)
self
.
overlayActGroup
=
QtWidgets
.
QActionGroup
(
self
.
dispMenu
)
self
.
overlayActGroup
=
QtWidgets
.
QActionGroup
(
self
.
dispMenu
)
self
.
overlayActGroup
.
setExclusive
(
True
)
self
.
overlayActGroup
.
setExclusive
(
True
)
self
.
overlayActGroup
.
triggered
.
connect
(
self
.
updateContours
)
self
.
overlayActGroup
.
triggered
.
connect
(
self
.
updateContour
Color
s
)
self
.
overlayActGroup
.
triggered
.
connect
(
self
.
updateDisplays
)
self
.
overlayActGroup
.
triggered
.
connect
(
self
.
updateDisplays
)
for
act
in
[
self
.
noOverlayAct
,
self
.
selOverlayAct
,
self
.
fullOverlayAct
]:
for
act
in
[
self
.
noOverlayAct
,
self
.
selOverlayAct
,
self
.
fullOverlayAct
]:
...
@@ -385,8 +385,9 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
...
@@ -385,8 +385,9 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
# else:
# else:
# print('displaying new type with resetting index')
# print('displaying new type with resetting index')
# self.displayNewPolymerType()
# self.displayNewPolymerType()
def
updateDisplays
(
self
):
def
updateDisplays
(
self
):
self
.
createHistogramData
()
t0
=
time
.
time
()
t0
=
time
.
time
()
self
.
updateTypeHistogram
()
self
.
updateTypeHistogram
()
print
(
'update type hist:'
,
round
((
time
.
time
()
-
t0
)
*
1000
))
print
(
'update type hist:'
,
round
((
time
.
time
()
-
t0
)
*
1000
))
...
@@ -394,7 +395,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
...
@@ -394,7 +395,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
updateSizeHistogram
()
self
.
updateSizeHistogram
()
print
(
'update size hist:'
,
round
((
time
.
time
()
-
t0
)
*
1000
))
print
(
'update size hist:'
,
round
((
time
.
time
()
-
t0
)
*
1000
))
t0
=
time
.
time
()
t0
=
time
.
time
()
self
.
updateContours
()
self
.
updateContour
Color
s
()
print
(
'update contours:'
,
round
((
time
.
time
()
-
t0
)
*
1000
))
print
(
'update contours:'
,
round
((
time
.
time
()
-
t0
)
*
1000
))
t0
=
time
.
time
()
t0
=
time
.
time
()
self
.
updateLegend
()
self
.
updateLegend
()
...
@@ -471,7 +472,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
...
@@ -471,7 +472,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
ref
=
self
.
dbWin
.
activeDatabase
.
spectra
[
refID
]
ref
=
self
.
dbWin
.
activeDatabase
.
spectra
[
refID
]
self
.
specPlot
.
updateReferenceSpectrum
(
ref
[:,
0
],
ref
[:,
1
])
self
.
specPlot
.
updateReferenceSpectrum
(
ref
[:,
0
],
ref
[:,
1
])
def
updateContours
(
self
):
def
updateContour
Color
s
(
self
):
contours
=
self
.
parent
.
contourItems
contours
=
self
.
parent
.
contourItems
alpha
=
(
128
if
self
.
transpAct
.
isChecked
()
else
255
)
alpha
=
(
128
if
self
.
transpAct
.
isChecked
()
else
255
)
selectedPolymers
=
self
.
getSelectedPolymers
()
selectedPolymers
=
self
.
getSelectedPolymers
()
...
@@ -521,7 +522,9 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
...
@@ -521,7 +522,9 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
spectrumSelector
.
setValue
(
1
)
self
.
spectrumSelector
.
setValue
(
1
)
self
.
currentParticleIndex
=
self
.
getParticleIndexFromParticleSelector
()
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
.
currentSpectrumIndex
=
self
.
getSpectrumIndexFromSpectrumSelector
()
self
.
updateSpecPlot
(
centerOn
=
False
)
self
.
updateSpecPlot
(
centerOn
=
False
)
...
...
analysis/particleInfo.py
View file @
96e55786
...
@@ -38,13 +38,15 @@ class ParticleContainer(object):
...
@@ -38,13 +38,15 @@ class ParticleContainer(object):
self
.
inconsistentParticles
=
[]
self
.
inconsistentParticles
=
[]
self
.
typeHistogram
=
None
self
.
typeHistogram
=
None
def
initializeParticles
(
self
,
numParticles
):
def
initializeParticles
(
self
,
numParticles
):
self
.
particles
=
[]
self
.
particles
=
[]
for
i
in
range
(
numParticles
):
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
)
assert
len
(
self
.
particles
)
==
len
(
contours
)
for
index
,
particle
in
enumerate
(
self
.
particles
):
for
index
,
particle
in
enumerate
(
self
.
particles
):
particle
.
contour
=
contours
[
index
]
particle
.
contour
=
contours
[
index
]
...
@@ -212,14 +214,49 @@ class ParticleContainer(object):
...
@@ -212,14 +214,49 @@ class ParticleContainer(object):
typehistogram
[
assignment
]
+=
1
typehistogram
[
assignment
]
+=
1
##sort typehistogram, it will be converted into a list!!
##sort typehistogram, it will be converted into a list!!
sorted_typehistogram
=
sorted
(
typehistogram
.
items
(),
key
=
operator
.
itemgetter
(
1
),
reverse
=
True
)
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
}
final_typehistogram
=
{
i
[
0
]:
i
[
1
]
for
i
in
sorted_typehistogram
}
return
final_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
):
class
Particle
(
object
):
def
__init__
(
self
,
index
):
def
__init__
(
self
):
self
.
index
=
index
super
(
Particle
,
self
).
__init__
()
self
.
index
=
None
self
.
longSize_ellipse
=
np
.
nan
self
.
longSize_ellipse
=
np
.
nan
self
.
shortSize_ellipse
=
np
.
nan
self
.
shortSize_ellipse
=
np
.
nan
self
.
longSize_box
=
np
.
nan
self
.
longSize_box
=
np
.
nan
...
@@ -227,7 +264,10 @@ class Particle(object):
...
@@ -227,7 +264,10 @@ class Particle(object):
self
.
area
=
None
self
.
area
=
None
self
.
contour
=
None
self
.
contour
=
None
self
.
measurements
=
[]
self
.
measurements
=
[]
def
addExistingMeasurement
(
self
,
meas
):
self
.
measurements
.
append
(
meas
)
def
addEmptyMeasurement
(
self
):
def
addEmptyMeasurement
(
self
):
self
.
measurements
.
append
(
Measurement
())
self
.
measurements
.
append
(
Measurement
())
indexOfNewMeasurment
=
len
(
self
.
measurements
)
-
1
indexOfNewMeasurment
=
len
(
self
.
measurements
)
-
1
...
@@ -318,6 +358,7 @@ class Particle(object):
...
@@ -318,6 +358,7 @@ class Particle(object):
class
Measurement
(
object
):
class
Measurement
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
super
(
Measurement
,
self
).
__init__
()
self
.
ramanScanIndex
=
None
self
.
ramanScanIndex
=
None
self
.
pixelcoord_x
=
None
self
.
pixelcoord_x
=
None
self
.
pixelcoord_y
=
None
self
.
pixelcoord_y
=
None
...
@@ -328,17 +369,18 @@ class Measurement(object):
...
@@ -328,17 +369,18 @@ class Measurement(object):
def
setAssignment
(
self
,
assignment
):
def
setAssignment
(
self
,
assignment
):
self
.
assignment_orig
=
assignment
self
.
assignment_orig
=
assignment
self
.
a
ssignment_afterHQI
=
'unknown'
self
.
a
pplyHQIThreshold
()
def
setHQI
(
self
,
hqi
):
def
setHQI
(
self
,
hqi
):
self
.
hqi
=
hqi
self
.
hqi
=
hqi
self
.
applyHQIThreshold
()
self
.
applyHQIThreshold
()
def
applyHQIThreshold
(
self
,
minHQI
=
0
):
def
applyHQIThreshold
(
self
,
minHQI
=
0
):
if
self
.
hqi
>=
minHQI
:
if
self
.
hqi
is
not
None
:
#i.e. skip for initial setup, when hqi is not yet aplied...
self
.
assignment_afterHQI
=
self
.
assignment_orig
if
self
.
hqi
>=
minHQI
:
else
:
self
.
assignment_afterHQI
=
self
.
assignment_orig
self
.
assignment_afterHQI
=
'unknown'
else
:
self
.
assignment_afterHQI
=
'unknown'
def
getHQI
(
self
):
def
getHQI
(
self
):
return
self
.
hqi
return
self
.
hqi
...
...
analysis/particleeditor.py
View file @
96e55786
...
@@ -70,15 +70,26 @@ class ParticleContextMenu(QtWidgets.QMenu):
...
@@ -70,15 +70,26 @@ class ParticleContextMenu(QtWidgets.QMenu):
action
=
self
.
exec_
(
screenPos
)
action
=
self
.
exec_
(
screenPos
)
if
action
in
self
.
combineActs
:
if
action
in
self
.
combineActs
:
newAssignment
=
action
.
text
()
newAssignment
=
self
.
validifyAssignment
(
action
.
text
()
)
self
.
combineParticlesSignal
.
emit
(
self
.
selectedParticleIndices
,
newAssignment
)
self
.
combineParticlesSignal
.
emit
(
self
.
selectedParticleIndices
,
newAssignment
)
elif
action
in
self
.
reassignActs
:
elif
action
in
self
.
reassignActs
:
newAssignment
=
action
.
text
()
newAssignment
=
self
.
validifyAssignment
(
action
.
text
()
)
self
.
reassignParticlesSignal
.
emit
(
self
.
selectedParticleIndices
,
newAssignment
)
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
):
class
ParticleEditor
(
QtCore
.
QObject
):
particlesWereEdited
=
QtCore
.
pyqtSignal
()
particleEditProcessStarted
=
QtCore
.
pyqtSignal
()
particlesEdited
=
QtCore
.
pyqtSignal
()
def
__init__
(
self
,
sampleView
,
particleContainer
):
def
__init__
(
self
,
sampleView
,
particleContainer
):
super
(
ParticleEditor
,
self
).
__init__
()
super
(
ParticleEditor
,
self
).
__init__
()
self
.
particleContainer
=
particleContainer
self
.
particleContainer
=
particleContainer
...
@@ -98,109 +109,19 @@ class ParticleEditor(QtCore.QObject):
...
@@ -98,109 +109,19 @@ class ParticleEditor(QtCore.QObject):
print
(
'backing up as'
,
backupname
)
print
(
'backing up as'
,
backupname
)
self
.
neverBackedUp
=
False
self
.
neverBackedUp
=
False
self
.
actionCounter
=
0
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
)
@
QtCore
.
pyqtSlot
(
list
,
str
)
def
combineParticles
(
self
,
contourIndices
,
new_assignment
):
def
combineParticles
(
self
,
contourIndices
,
newAssignment
):
print
(
contourIndices
,
new_assignment
)
self
.
particleEditProcessStarted
.
emit
()
self
.
createSafetyBackup
()
# if new_assignment == 'other':
print
(
f
'Combining particles
{
contourIndices
}
into
{
newAssignment
}
'
)
# new_assignment = self.getNewEntry()
contours
=
self
.
particleContainer
.
getParticleContoursByIndex
(
contourIndices
)
# if new_assignment is None:
newContour
=
self
.
mergeContours
(
contours
.
copy
())
# return
stats
=
self
.
characterizeParticle
(
newContour
)
#
# contourIndices = sorted(contourIndices) #we want to keep the contour with lowest index
self
.
particleContainer
.
mergeParticles
(
contourIndices
,
newContour
,
stats
,
newAssignment
=
newAssignment
)
# #get contours:
self
.
particlesEdited
.
emit
()
# 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()
# #save data
# #save data
# minHQI = self.parent.hqiSpinBox.value()
# minHQI = self.parent.hqiSpinBox.value()
# compHQI = self.parent.compHqiSpinBox.value()
# compHQI = self.parent.compHqiSpinBox.value()
...
@@ -210,19 +131,53 @@ class ParticleEditor(QtCore.QObject):
...
@@ -210,19 +131,53 @@ class ParticleEditor(QtCore.QObject):
# QtWidgets.QMessageBox.Ok)
# QtWidgets.QMessageBox.Ok)
@
QtCore
.
pyqtSlot
(
list
,
str
)
@
QtCore
.
pyqtSlot
(
list
,
str
)
def
reassignParticles
(
self
,
contourindices
,
new_assignment
):
def
reassignParticles
(
self
,
contourindices
,
newAssignment
):
if
new_assignment
==
'other'
:
self
.
particleEditProcessStarted
.
emit
()
new_assignment
=
self
.
getNewEntry
()
if
new_assignment
is
None
:
return
self
.
createSafetyBackup
()
self
.
createSafetyBackup
()
print
(
f
'reassigning indices
{
contourindices
}
into
{
new
_a
ssignment
}
'
)
print
(
f
'reassigning indices
{
contourindices
}
into
{
new
A
ssignment
}
'
)
for
partIndex
in
contourindices
:
for
partIndex
in
contourindices
:
self
.
particleContainer
.
reassignParticleToAssignment
(
partIndex
,
new
_a
ssignment
)
self
.
particleContainer
.
reassignParticleToAssignment
(
partIndex
,
new
A
ssignment
)
self
.
particlesWereEdited
.
emit
()
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
def
characterizeParticle
(
self
,
contours
):
def
characterizeParticle
(
self
,
contours
):
##characterize particle
##characterize particle
longellipse
,
shortellipse
=
np
.
nan
,
np
.
nan
longellipse
,
shortellipse
=
np
.
nan
,
np
.
nan
...
...
dataset.py
View file @
96e55786
...
@@ -257,7 +257,7 @@ class DataSet(object):
...
@@ -257,7 +257,7 @@ class DataSet(object):
self
.
particleContainer
.
initializeParticles
(
len
(
self
.
particlestats
))
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
.
setParticleStats
(
self
.
particlestats
)
self
.
particleContainer
.
applyPixelScaleToParticleStats
(
self
.
getPixelScale
())
self
.
particleContainer
.
applyPixelScaleToParticleStats
(
self
.
getPixelScale
())
if
hasattr
(
self
,
'particles2spectra'
):
if
hasattr
(
self
,
'particles2spectra'
):
...
...
detectionview.py
View file @
96e55786
...
@@ -664,7 +664,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
...
@@ -664,7 +664,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
particleContainer
=
self
.
dataset
.
particleContainer
particleContainer
=
self
.
dataset
.
particleContainer
particleContainer
.
initializeParticles
(
numParticles
)
particleContainer
.
initializeParticles
(
numParticles
)
particleContainer
.
setParticle
c
ontours
(
contours
)
particleContainer
.
setParticle
C
ontours
(
contours
)
particleContainer
.
setParticleStats
(
particlestats
)
particleContainer
.
setParticleStats
(
particlestats
)
particleContainer
.
applyPixelScaleToParticleStats
(
self
.
dataset
.
getPixelScale
())
particleContainer
.
applyPixelScaleToParticleStats
(
self
.
dataset
.
getPixelScale
())
...
...
sampleview.py
View file @
96e55786
...
@@ -58,6 +58,8 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -58,6 +58,8 @@ class SampleView(QtWidgets.QGraphicsView):
self
.
setRenderHint
(
QtGui
.
QPainter
.
Antialiasing
)
self
.
setRenderHint
(
QtGui
.
QPainter
.
Antialiasing
)
self
.
setTransformationAnchor
(
QtWidgets
.
QGraphicsView
.
AnchorUnderMouse
)
self
.
setTransformationAnchor
(
QtWidgets
.
QGraphicsView
.
AnchorUnderMouse
)
self
.
setResizeAnchor
(
QtWidgets
.
QGraphicsView
.
AnchorViewCenter
)
self
.
setResizeAnchor
(
QtWidgets
.
QGraphicsView
.
AnchorViewCenter
)
self
.
disableSelection
=
False
self
.
ramanctrl
=
RamanControl
()
self
.
ramanctrl
=
RamanControl
()
self
.
simulatedRaman
=
simulatedRaman
self
.
simulatedRaman
=
simulatedRaman
#determine, if ramanSwitch is needed:
#determine, if ramanSwitch is needed:
...
@@ -177,7 +179,7 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -177,7 +179,7 @@ class SampleView(QtWidgets.QGraphicsView):
self
.
detectionwidget
.
close
()
self
.
detectionwidget
.
close
()
self
.
detectionwidget
.
destroy
()
self
.
detectionwidget
.
destroy
()
self
.
ramanwidget
.
setVisible
(
False
)
self
.
ramanwidget
.
setVisible
(
False
)
self
.
update
ParticleContours
()
self
.
reset
ParticleContours
()
self
.
mode
=
mode
self
.
mode
=
mode
self
.
loadPixmap
(
self
.
microscopeMode
)
self
.
loadPixmap
(
self
.
microscopeMode
)
if
mode
==
"OpticalScan"
:
if
mode
==
"OpticalScan"
:
...
@@ -202,7 +204,7 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -202,7 +204,7 @@ class SampleView(QtWidgets.QGraphicsView):
print
(
'creating new analysiswidget'
)
print
(
'creating new analysiswidget'
)
self
.
analysiswidget
=
ParticleAnalysis
(
self
.
dataset
,
self
)
self
.
analysiswidget
=
ParticleAnalysis
(
self
.
dataset
,
self
)
self
.
analysiswidget
.
showMaximized
()
self
.
analysiswidget
.
showMaximized
()
self
.
particleEditor
.
particlesWereEdited
.
connect
(
self
.
analysiswidget
.
updateDisplays
)
self
.
setupParticleEditor
(
)
else
:
else
:
print
(
'show maximized already exisiting analysiswidget'
)
print
(
'show maximized already exisiting analysiswidget'
)
self
.
analysiswidget
.
showMaximized
()
self
.
analysiswidget
.
showMaximized
()
...
@@ -228,10 +230,9 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -228,10 +230,9 @@ class SampleView(QtWidgets.QGraphicsView):
widget
.
destroy
()
widget
.
destroy
()
del
widget
del
widget
self
.
updateParticleContours
()
self
.
dataset
=
loadData
(
fname
)
self
.
dataset
=
loadData
(
fname
)
self
.
particleEditor
=
ParticleEditor
(
self
,
self
.
dataset
.
particleContainer
)
self
.
resetParticleContours
()
self
.
setupParticleEditor
()
self
.
setMicroscopeMode
()
self
.
setMicroscopeMode
()
self
.
imparent
.
setWindowTitle
(
self
.
dataset
.
name
+
(
" SIMULATION"
if
simulatedRaman
else
""
))
self
.
imparent
.
setWindowTitle
(
self
.
dataset
.
name
+
(
" SIMULATION"
if
simulatedRaman
else
""
))
self
.
imgdata
=
None
self
.
imgdata
=
None
...
@@ -250,13 +251,23 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -250,13 +251,23 @@ class SampleView(QtWidgets.QGraphicsView):
if
self
.
dataset
is
not
None
:
if
self
.
dataset
is
not
None
:
self
.
dataset
.
save
()
self
.
dataset
.
save
()
self
.
dataset
=
DataSet
(
fname
,
newProject
=
True
)
self
.
dataset
=
DataSet
(
fname
,
newProject
=
True
)
self
.
particleEditor
=
ParticleEditor
(
self
,
self
.
dataset
.
particleContainer
)
self
.
setupParticleEditor
(
)
self
.
setMicroscopeMode
()
self
.
setMicroscopeMode
()
self
.
imparent
.
setWindowTitle
(
self
.
dataset
.
name
+
(
" SIMULATION"
if
simulatedRaman
else
""
))
self
.
imparent
.
setWindowTitle
(
self
.
dataset
.
name
+
(
" SIMULATION"
if
simulatedRaman
else
""
))
self
.
imgdata
=
None
self
.
imgdata
=
None
self
.
activateMaxMode
(
loadnew
=
True
)
self
.
activateMaxMode
(
loadnew
=
True
)
self
.
imparent
.
snapshotAct
.
setEnabled
(
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
):
def
setMicroscopeMode
(
self
):
if
self
.
ramanSwitchNeeded
:
if
self
.
ramanSwitchNeeded
:
self
.
imparent
.
ramanSwitch
.
connectToSampleView
()
self
.
imparent
.
ramanSwitch
.
connectToSampleView
()
...
@@ -295,38 +306,39 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -295,38 +306,39 @@ class SampleView(QtWidgets.QGraphicsView):
return
maxmode
return
maxmode
def
mousePressEvent
(
self
,
event
):
def
mousePressEvent
(
self
,
event
):
if
event
.
button
()
==
QtCore
.
Qt
.
MiddleButton
:
if
not
self
.
disableSelection
:
self
.
drag
=
event
.
pos
()
if
event
.
button
()
==
QtCore
.
Qt
.
MiddleButton
:
elif
event
.
button
()
==
QtCore
.
Qt
.
LeftButton
:
self
.
drag
=
event
.
pos
()
self
.
checkForContourSelection
(
event
)
elif
event
.
button
()
==
QtCore
.
Qt
.
LeftButton
:
event
.
ignore
()
self
.
checkForContourSelection
(
event
)
elif
event
.
button
()
==
QtCore
.
Qt
.
LeftButton
and
self
.
mode
in
[
"OpticalScan"
,
"RamanScan"
]
\