-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThresholding.py
More file actions
26 lines (23 loc) · 763 Bytes
/
Thresholding.py
File metadata and controls
26 lines (23 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from Application.Utils.AlgorithmDecorators import RegisterAlgorithm
from Application.Utils.InputDecorators import InputDialog
from Application.Utils.OutputDecorators import OutputDialog
@RegisterAlgorithm("Binarization", "Thresholding")
@InputDialog(threshold=int)
@OutputDialog(title="Binarization Output")
def binarization(image, threshold):
"""Applies binarization based on given threshold.
:param image:
:param threshold:
:return:
"""
# if the image is grayscale
if len(image.shape) == 2:
image[image < threshold] = 0
image[image >= threshold] = 255
return {
'processedImage': image
}
else:
return {
'outputMessage': "Error: image is not grayscale!"
}