Binarization & Thresholding Methods
Binarizer component
BinarizerImage
BinarizerImage class
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
binary(method='sauvola')
Binary representation of the image with values that can be only 0 or 1. The value 0 is now 0 and value of 255 are now 1. Black is 0 and white is 1. We can also talk about the mask of the image to refer to the binary representation of it.
The sauvola is generally the best binarization method however it is way slower than the others methods. The adaptative or otsu method are the best method in terms of speed and quality.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
the binarization method to apply. Must be in ["adaptative", "otsu", "sauvola", "niblack", "nick", "wolf"]. Defaults to "sauvola". |
'sauvola'
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
array where its inner values are 0 or 1 |
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
binaryrev(method='sauvola')
Reversed binary representation of the image. The value 0 is now 1 and value of 255 are now 0. Black is 1 and white is 0. This is why it is called the "binary rev" or "binary reversed".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
the binarization method to apply. Defaults to "adaptative". |
'sauvola'
|
Returns:
Name | Type | Description |
---|---|---|
NDArray |
NDArray
|
array where its inner values are 0 or 1 |
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
threshold_adaptative()
Apply adaptive thresholding.
A median blur is applied before for better thresholding results. See https://docs.opencv.org/4.x/d7/d4d/tutorial_py_thresholding.html.
As the input image must be a grayscale before applying any thresholding methods we convert the image to grayscale.
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
threshold_niblack(window_size=15, k=0.2)
Apply Niblack thresholding. See https://scikit-image.org/docs/stable/auto_examples/segmentation/ plot_niblack_sauvola.html
As the input image must be a grayscale before applying any thresholding methods we convert the image to grayscale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
window_size
|
int
|
apply on the image. Defaults to 15. |
15
|
k
|
float
|
factor to apply to regulate the impact of the std. Defaults to 0.2. |
0.2
|
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
threshold_otsu()
Apply Ostu thresholding.
A gaussian blur is applied before for better thresholding results. See https://docs.opencv.org/4.x/d7/d4d/tutorial_py_thresholding.html.
As the input image must be a grayscale before applying any thresholding methods we convert the image to grayscale.
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
threshold_sauvola(window_size=15, k=0.2, r=128.0)
Apply Sauvola thresholding. See https://scikit-image.org/docs/stable/auto_examples/segmentation/ plot_niblack_sauvola.html.
As the input image must be a grayscale before applying any thresholding methods we convert the image to grayscale.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
window_size
|
int
|
sauvola window size to apply on the image. Defaults to 15. |
15
|
k
|
float
|
sauvola k factor to apply to regulate the impact of the std. Defaults to 0.2. |
0.2
|
r
|
float
|
sauvola r value. Defaults to 128. |
128.0
|
Source code in otary/image/components/transformer/components/binarizer/binarizer.py
threshold_simple(thresh)
Compute the image thesholded by a single value T. All pixels with value v <= T are turned black and those with value v > T are turned white.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thresh
|
int
|
value to separate the black from the white pixels. |
required |