Skip to content

Commit

Permalink
[#52] Add thresholding with percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
jeaunrg committed Jun 29, 2021
1 parent d610a18 commit 2c795ca
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
4 changes: 2 additions & 2 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
1013
],
"window_position": [
-48,
39
15,
-9
],
"module_width": 250,
"space_between_modules": [
Expand Down
44 changes: 37 additions & 7 deletions resources/ui/modules/ThresholdImage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>213</width>
<height>110</height>
<width>222</width>
<height>90</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -17,11 +17,38 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="reversed">
<property name="text">
<string>reversed</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="reversed">
<property name="text">
<string>reversed</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="inPercentage">
<property name="text">
<string>in percentage</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
Expand All @@ -43,6 +70,9 @@
<property name="maximum">
<number>256</number>
</property>
<property name="value">
<number>50</number>
</property>
</widget>
</item>
</layout>
Expand Down
8 changes: 7 additions & 1 deletion src/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -171,12 +171,18 @@ 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
-------
mask: 2d/3d numpy array
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)
3 changes: 2 additions & 1 deletion src/presenter/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/view/graph_bricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 2c795ca

Please sign in to comment.