From dd71babfc49c4aaa9dd94cb4b295e8fb8684c5fc Mon Sep 17 00:00:00 2001 From: Josef Brandt Date: Tue, 29 Oct 2019 08:45:10 +0100 Subject: [PATCH] Fixes in SeedPointProcessing --- detectionview.py | 55 +++++++++++++++++++++++++++++++----------------- segmentation.py | 9 +------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/detectionview.py b/detectionview.py index 4fb53ba..709d660 100644 --- a/detectionview.py +++ b/detectionview.py @@ -175,12 +175,14 @@ class ImageView(QtWidgets.QLabel): else: self.drag = "add" p0 = event.pos() - if self.drag=="add": - self.seedpoints.append([p0.x(),p0.y(),self.seedradius]) - elif self.drag=="delete": - self.seeddeletepoints.append([p0.x(),p0.y(),self.seedradius]) - else: - self.removeSeeds([p0.x(),p0.y()]) + self.appendSeedPoints(p0) + # print(p0) + # if self.drag =="add": + # self.seedpoints.append([p0.x(), p0.y(), self.seedradius]) + # elif self.drag =="delete": + # self.seeddeletepoints.append([p0.x(), p0.y(), self.seedradius]) + # elif self.drag == "remove": + # self.removeSeeds([p0.x(), p0.y()]) self.update() super().mousePressEvent(event) @@ -188,12 +190,13 @@ class ImageView(QtWidgets.QLabel): def mouseMoveEvent(self, event): if self.drag: p0 = event.pos() - if self.drag=="add": - self.seedpoints.append([p0.x(),p0.y(),self.seedradius]) - elif self.drag=="delete": - self.seeddeletepoints.append([p0.x(),p0.y(),self.seedradius]) - else: - self.removeSeeds([p0.x(),p0.y()]) + self.appendSeedPoints(p0) + # if self.drag == "add": + # self.seedpoints.append([p0.x(),p0.y(),self.seedradius]) + # elif self.drag == "delete": + # self.seeddeletepoints.append([p0.x(),p0.y(),self.seedradius]) + # else: + # self.removeSeeds([p0.x(),p0.y()]) self.update() super().mouseMoveEvent(event) @@ -202,6 +205,16 @@ class ImageView(QtWidgets.QLabel): self.seedChanged.emit() self.drag = False 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): self.contours = [] @@ -356,10 +369,7 @@ class ParticleDetectionView(QtWidgets.QWidget): 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()) @@ -399,6 +409,12 @@ class ParticleDetectionView(QtWidgets.QWidget): self.slider.setOrientation(QtCore.Qt.Horizontal) self.slider.sliderMoved.connect(self.imglabel.resetAlpha) 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() self.pdetectsub = QtWidgets.QPushButton("Detect", self) self.pdetectall = QtWidgets.QPushButton("Detect all", self) @@ -488,11 +504,11 @@ class ParticleDetectionView(QtWidgets.QWidget): arr1 = self.dataset.seedpoints # 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]): seedpoints.append([point[0] - p0[0][0], point[1] - p0[0][1], point[2]]) 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]): seeddeletepoints.append([point[0] - p0[0][0], point[1] - p0[0][1], point[2]]) @@ -522,7 +538,8 @@ class ParticleDetectionView(QtWidgets.QWidget): if self.drag: self.lastcenter = self.lastmove self.drag = False - self.detectShow(None) + if self.autoUpdateCheckBox.isChecked(): + self.detectShow(None) def setDataSet(self, ds): self.dataset = ds diff --git a/segmentation.py b/segmentation.py index 5cc354a..9f09266 100644 --- a/segmentation.py +++ b/segmentation.py @@ -381,13 +381,6 @@ class Segmentation(object): sure_bg = self.closeHoles(sure_bg) # 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): 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) @@ -419,7 +412,7 @@ class Segmentation(object): if self.cancelcomputation: return None, None, None 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 = watershed(-dist_transform, markers, mask=sure_bg, compactness = self.compactness, watershed_line = True) #labels = 0 for background, 1... for particles -- GitLab