From 2c795ca1eb847ac70acf01e783b0c37154656c95 Mon Sep 17 00:00:00 2001 From: jean unrug Date: Tue, 29 Jun 2021 18:57:24 +0200 Subject: [PATCH] [#52] Add thresholding with percentage --- config/default.json | 4 +-- resources/ui/modules/ThresholdImage.ui | 44 ++++++++++++++++++++++---- src/model/model.py | 8 ++++- src/presenter/presenter.py | 3 +- src/view/graph_bricks.py | 1 - 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/config/default.json b/config/default.json index 2679699..40e330b 100644 --- a/config/default.json +++ b/config/default.json @@ -4,8 +4,8 @@ 1013 ], "window_position": [ - -48, - 39 + 15, + -9 ], "module_width": 250, "space_between_modules": [ diff --git a/resources/ui/modules/ThresholdImage.ui b/resources/ui/modules/ThresholdImage.ui index ee0a774..e5d2b4e 100644 --- a/resources/ui/modules/ThresholdImage.ui +++ b/resources/ui/modules/ThresholdImage.ui @@ -6,8 +6,8 @@ 0 0 - 213 - 110 + 222 + 90 @@ -17,11 +17,38 @@ - - - reversed - - + + + + + reversed + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + in percentage + + + true + + + + @@ -43,6 +70,9 @@ 256 + + 50 + diff --git a/src/model/model.py b/src/model/model.py index 5a4b646..0cafd6d 100644 --- a/src/model/model.py +++ b/src/model/model.py @@ -160,7 +160,7 @@ def apply_operation(self, arr, elements=[], operation='add'): arr = function(arr, element, dtype=np.float64) return arr - def apply_threshold(self, im, threshold, reverse=False): + def apply_threshold(self, im, threshold, reverse=False, thresholdInPercentage=False): """ Apply binary threshold on the input image @@ -171,6 +171,7 @@ def apply_threshold(self, im, threshold, reverse=False): Pixel value, image=1 above threshold, image=0 below threshold reverse: bool, default=False If True invert 0 and 1 in output + thresholdInPercentage: bool, default=False Returns ------- @@ -178,5 +179,10 @@ def apply_threshold(self, im, threshold, reverse=False): Binarized input image with same size as im """ + if thresholdInPercentage: + mini, maxi = np.min(im), np.max(im) + threshold = mini + threshold * (maxi - mini) / 100 + print(mini, maxi) + print(threshold) mask = im < threshold if reverse else im > threshold return mask.astype(np.uint8) diff --git a/src/presenter/presenter.py b/src/presenter/presenter.py index c7f664b..fa0fd0d 100644 --- a/src/presenter/presenter.py +++ b/src/presenter/presenter.py @@ -269,7 +269,8 @@ def call_apply_threshold(self, module): function = self._model.apply_threshold args = {"im": module.getData(parent_name), "threshold": module.parameters.spin.value(), - "reverse": module.parameters.reversed.isChecked()} + "reverse": module.parameters.reversed.isChecked(), + "thresholdInPercentage": module.parameters.inPercentage.isChecked()} return function, args @utils.manager(2) diff --git a/src/view/graph_bricks.py b/src/view/graph_bricks.py index 9f4b7ee..467003c 100644 --- a/src/view/graph_bricks.py +++ b/src/view/graph_bricks.py @@ -420,7 +420,6 @@ def snapMousePressEvent(self, event): if im.ndim == 2: x, y, z = *true_pos, '' value = im[x, y] - self.rightfoot.setText("%d " % im[x, y]) elif self.result.slicable: x, y, z = np.insert(true_pos, self.result.axis, self.result.currentSlice) value = im[x, y, z]