Commit 4a04d651 authored by Hackmet's avatar Hackmet

Added second threshold in detectionview.py

parent 961b3253
......@@ -275,7 +275,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
self.dataset = self.verifySeedpoints(dataset)
self.img = img
self.imgclip = 0,0,0,0
self.seg = Segmentation(self.dataset)
self.seg = Segmentation(self.dataset, self)
self.thread = None
self.view = parent
......@@ -303,10 +303,12 @@ class ParticleDetectionView(QtWidgets.QWidget):
group = QtWidgets.QGroupBox("Detection settings", self)
grid = QtWidgets.QGridLayout()
self.parameters = []
checkBoxesToLink = {}
# create editable parameters:
for i, p in enumerate(self.seg.parlist):
label, colstretch = None, 1
if p.name == "points":
if p.name == "contrastCurve":
paramui = HistWidget(lambda : self.seg.calculateHist(self.seg.convert2Gray(self.subimg)),
self.seg.calculateHistFunction, self)
valuefunc = makeValueLambda(paramui.value)
......@@ -316,6 +318,8 @@ class ParticleDetectionView(QtWidgets.QWidget):
paramui.setChecked(p.value)
valuefunc = makeValueLambda(paramui.isChecked)
colstretch = 2
if p.linkedParameter is not None:
checkBoxesToLink[paramui] = p.linkedParameter
elif p.dtype == int or p.dtype == float:
label = QtWidgets.QLabel(p.helptext, self)
if p.dtype == int:
......@@ -334,18 +338,44 @@ class ParticleDetectionView(QtWidgets.QWidget):
elif p.dtype is None:
label = QtWidgets.QLabel(p.helptext, self)
paramui = None
if paramui is not None:
self.parameters.append([paramui, p.name, valuefunc])
self.parameters.append([paramui, p.name, valuefunc, None])
if colstretch == 1:
grid.addWidget(paramui, i, 1, QtCore.Qt.AlignLeft)
else:
grid.addWidget(paramui, i, 0, 1, 2, QtCore.Qt.AlignLeft)
grid.addWidget(paramui, i, 0, 1, 2, QtCore.Qt.AlignLeft)
if label is not None:
grid.addWidget(label, i, 0, QtCore.Qt.AlignLeft)
if p.show is True:
pshow = QtWidgets.QPushButton(">", self)
pshow.released.connect(makeShowLambda(p.name))
grid.addWidget(pshow, i, 2, QtCore.Qt.AlignRight)
if paramui is not None:
self.parameters[-1][3] = pshow
#link checkboxes to other parameters:
def makeEnableLambda(checkbox, parameter):
return lambda: parameter.setEnabled(checkbox.isChecked())
for box in checkBoxesToLink:
linkedName = checkBoxesToLink[box]
for p in self.parameters:
if p[1] == linkedName:
p[0].setEnabled(box.isChecked())
box.stateChanged.connect(makeEnableLambda(box, p[0])) #the actual control element
if p[3] is not None: #the "show" box, if present
box.stateChanged.connect(makeEnableLambda(box, p[3]))
p[3].setEnabled(box.isChecked())
label = QtWidgets.QLabel("Seed radius", self)
grid.addWidget(label, i+1, 0, QtCore.Qt.AlignLeft)
......@@ -384,7 +414,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
def saveDetectParams(self, ds=None):
if ds is not None:
for param in self.parameters:
if param[1] == 'points':
if param[1] == 'contrastCurve':
print(param[0].value())
try: # is it a spinbox or the histWidget? Read out the value
ds.detectParams[param[1]] = param[0].value()
......@@ -535,7 +565,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
self.saveDetectParams(self.dataset)
img = self.subimg.copy()
kwargs = {}
for ui, name, valuefunc in self.parameters:
for ui, name, valuefunc, showbtn in self.parameters:
kwargs[name] = valuefunc()
self.seg.setParameters(**kwargs)
seedradius = self.seedradiusedit.value()
......@@ -579,6 +609,9 @@ class ParticleDetectionView(QtWidgets.QWidget):
self.pdetectsub.setEnabled(True)
self.pclear.setEnabled(True)
def raiseWarning(self, warning):
QtWidgets.QMessageBox.critical(self, "Warning", warning)
@QtCore.pyqtSlot()
def detectParticles(self):
self.saveDetectParams(self.dataset)
......@@ -615,7 +648,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
if self.dataset is not None:
seedpoints = self.dataset.seedpoints
deletepoints = self.dataset.seeddeletepoints
for ui, name, valuefunc in self.parameters:
for ui, name, valuefunc, showbtn in self.parameters:
kwargs[name] = valuefunc()
seedradius = self.seedradiusedit.value()
self.seg.setParameters(**kwargs)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment