Commit dd71babf authored by Josef Brandt's avatar Josef Brandt

Fixes in SeedPointProcessing

parent d91bcf42
...@@ -175,12 +175,14 @@ class ImageView(QtWidgets.QLabel): ...@@ -175,12 +175,14 @@ class ImageView(QtWidgets.QLabel):
else: else:
self.drag = "add" self.drag = "add"
p0 = event.pos() p0 = event.pos()
if self.drag=="add": self.appendSeedPoints(p0)
self.seedpoints.append([p0.x(),p0.y(),self.seedradius]) # print(p0)
elif self.drag=="delete": # if self.drag =="add":
self.seeddeletepoints.append([p0.x(),p0.y(),self.seedradius]) # self.seedpoints.append([p0.x(), p0.y(), self.seedradius])
else: # elif self.drag =="delete":
self.removeSeeds([p0.x(),p0.y()]) # self.seeddeletepoints.append([p0.x(), p0.y(), self.seedradius])
# elif self.drag == "remove":
# self.removeSeeds([p0.x(), p0.y()])
self.update() self.update()
super().mousePressEvent(event) super().mousePressEvent(event)
...@@ -188,12 +190,13 @@ class ImageView(QtWidgets.QLabel): ...@@ -188,12 +190,13 @@ class ImageView(QtWidgets.QLabel):
def mouseMoveEvent(self, event): def mouseMoveEvent(self, event):
if self.drag: if self.drag:
p0 = event.pos() p0 = event.pos()
if self.drag=="add": self.appendSeedPoints(p0)
self.seedpoints.append([p0.x(),p0.y(),self.seedradius]) # if self.drag == "add":
elif self.drag=="delete": # self.seedpoints.append([p0.x(),p0.y(),self.seedradius])
self.seeddeletepoints.append([p0.x(),p0.y(),self.seedradius]) # elif self.drag == "delete":
else: # self.seeddeletepoints.append([p0.x(),p0.y(),self.seedradius])
self.removeSeeds([p0.x(),p0.y()]) # else:
# self.removeSeeds([p0.x(),p0.y()])
self.update() self.update()
super().mouseMoveEvent(event) super().mouseMoveEvent(event)
...@@ -202,6 +205,16 @@ class ImageView(QtWidgets.QLabel): ...@@ -202,6 +205,16 @@ class ImageView(QtWidgets.QLabel):
self.seedChanged.emit() self.seedChanged.emit()
self.drag = False self.drag = False
super().mouseReleaseEvent(event) super().mouseReleaseEvent(event)
def appendSeedPoints(self, pos):
if 0 <= pos.x() < Nscreen and 0 <= pos.y() < Nscreen:
print(pos)
if self.drag == "add":
self.seedpoints.append([pos.x(), pos.y(), self.seedradius])
elif self.drag == "delete":
self.seeddeletepoints.append([pos.x(), pos.y(), self.seedradius])
elif self.drag == "remove":
self.removeSeeds([pos.x(), pos.y()])
def clearData(self): def clearData(self):
self.contours = [] self.contours = []
...@@ -356,10 +369,7 @@ class ParticleDetectionView(QtWidgets.QWidget): ...@@ -356,10 +369,7 @@ class ParticleDetectionView(QtWidgets.QWidget):
if paramui is not None: if paramui is not None:
self.parameters[-1][3] = pshow self.parameters[-1][3] = pshow
#link checkboxes to other parameters: #link checkboxes to other parameters:
def makeEnableLambda(checkbox, parameter): def makeEnableLambda(checkbox, parameter):
return lambda: parameter.setEnabled(checkbox.isChecked()) return lambda: parameter.setEnabled(checkbox.isChecked())
...@@ -399,6 +409,12 @@ class ParticleDetectionView(QtWidgets.QWidget): ...@@ -399,6 +409,12 @@ class ParticleDetectionView(QtWidgets.QWidget):
self.slider.setOrientation(QtCore.Qt.Horizontal) self.slider.setOrientation(QtCore.Qt.Horizontal)
self.slider.sliderMoved.connect(self.imglabel.resetAlpha) self.slider.sliderMoved.connect(self.imglabel.resetAlpha)
vbox.addWidget(self.slider) vbox.addWidget(self.slider)
self.autoUpdateCheckBox = QtWidgets.QCheckBox('Auto-update detection')
self.autoUpdateCheckBox.setMaximumWidth(200)
self.autoUpdateCheckBox.setChecked(True)
vbox.addWidget(self.autoUpdateCheckBox)
hbox2 = QtWidgets.QHBoxLayout() hbox2 = QtWidgets.QHBoxLayout()
self.pdetectsub = QtWidgets.QPushButton("Detect", self) self.pdetectsub = QtWidgets.QPushButton("Detect", self)
self.pdetectall = QtWidgets.QPushButton("Detect all", self) self.pdetectall = QtWidgets.QPushButton("Detect all", self)
...@@ -488,11 +504,11 @@ class ParticleDetectionView(QtWidgets.QWidget): ...@@ -488,11 +504,11 @@ class ParticleDetectionView(QtWidgets.QWidget):
arr1 = self.dataset.seedpoints arr1 = self.dataset.seedpoints
# what seeds are actually in image view? # what seeds are actually in image view?
for point in arr1: #Josef says: I replaced the commented logic with the one right here below, as the old one somehow did not work.... The for-loop might become slow at some point?? for point in arr1:
if point[0] > (m1-point[2]) and point[0] <= (m2+point[2]) and point[1] > (n1-point[2]) and point[1] <= (n2+point[2]): if point[0] > (m1-point[2]) and point[0] <= (m2+point[2]) and point[1] > (n1-point[2]) and point[1] <= (n2+point[2]):
seedpoints.append([point[0] - p0[0][0], point[1] - p0[0][1], point[2]]) seedpoints.append([point[0] - p0[0][0], point[1] - p0[0][1], point[2]])
arr2 = self.dataset.seeddeletepoints arr2 = self.dataset.seeddeletepoints
for point in arr2: #Josef says: I replaced the commented logic with the one right here below, as the old one somehow did not work.... The for-loop might become slow at some point?? for point in arr2:
if point[0] > (m1-point[2]) and point[0] <= (m2+point[2]) and point[1] > (n1-point[2]) and point[1] <= (n2+point[2]): if point[0] > (m1-point[2]) and point[0] <= (m2+point[2]) and point[1] > (n1-point[2]) and point[1] <= (n2+point[2]):
seeddeletepoints.append([point[0] - p0[0][0], point[1] - p0[0][1], point[2]]) seeddeletepoints.append([point[0] - p0[0][0], point[1] - p0[0][1], point[2]])
...@@ -522,7 +538,8 @@ class ParticleDetectionView(QtWidgets.QWidget): ...@@ -522,7 +538,8 @@ class ParticleDetectionView(QtWidgets.QWidget):
if self.drag: if self.drag:
self.lastcenter = self.lastmove self.lastcenter = self.lastmove
self.drag = False self.drag = False
self.detectShow(None) if self.autoUpdateCheckBox.isChecked():
self.detectShow(None)
def setDataSet(self, ds): def setDataSet(self, ds):
self.dataset = ds self.dataset = ds
......
...@@ -381,13 +381,6 @@ class Segmentation(object): ...@@ -381,13 +381,6 @@ class Segmentation(object):
sure_bg = self.closeHoles(sure_bg) sure_bg = self.closeHoles(sure_bg)
# modify sure_fg and sure_bg with seedpoints and deletepoints # modify sure_fg and sure_bg with seedpoints and deletepoints
if len(deletepoints)>0:
h, w = sure_fg.shape[:2]
mask = np.zeros((h+2, w+2), np.uint8)
for p in np.int32(deletepoints):
if 0 < p[0] < h and 0 < p[1] < w: #point has to be within image, otherwise the floodFill fails
cv2.floodFill(sure_fg, mask, tuple([p[0], p[1]]), 0)
for p in np.int32(seedpoints): for p in np.int32(seedpoints):
cv2.circle(sure_fg, tuple([p[0], p[1]]), int(p[2]), 1, -1) cv2.circle(sure_fg, tuple([p[0], p[1]]), int(p[2]), 1, -1)
cv2.circle(sure_bg, tuple([p[0], p[1]]), int(p[2]), 1, -1) cv2.circle(sure_bg, tuple([p[0], p[1]]), int(p[2]), 1, -1)
...@@ -419,7 +412,7 @@ class Segmentation(object): ...@@ -419,7 +412,7 @@ class Segmentation(object):
if self.cancelcomputation: if self.cancelcomputation:
return None, None, None return None, None, None
twatershed = time() twatershed = time()
#ich habe jetzt nur noch den Skimage Watershed integriert. Oben auskommentiert der opencv watershed, falls wir ihn doch nochmal für irgendwas brauchen...
markers = ndi.label(sure_fg)[0] markers = ndi.label(sure_fg)[0]
markers = watershed(-dist_transform, markers, mask=sure_bg, compactness = self.compactness, watershed_line = True) #labels = 0 for background, 1... for particles markers = watershed(-dist_transform, markers, mask=sure_bg, compactness = self.compactness, watershed_line = True) #labels = 0 for background, 1... for particles
......
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