$extrastylesheet
Sauvola's Binarization implementations.
It is well suited for classical document image binarization.
Scribo provides three variants of Sauvola's binarization algorithm :
These algorithms are based on the following article: sauvola00pr . All of them are implemented using integral images for best performance shafait2008drr.
Sauvola's algorithm is a local thresholding method. Based on the mean and the standard deviation of a sliding centered window, it computes a local threshold for each pixel.
The following formula is used:
Where p is the central window point, m(p) and s(p) are, respectively, the mean and the standard deviation of the window centered to point p.
k is user-defined parameter. According to badekas2005ppriaa, this parameter is set to 0.34. However, it is possible to pass a different value and change the object sharpness.
The window size is also a user-defined parameter. In scribo::binarization::sauvola, it has to be adapted to the size of the binarized objects. In case of a document image with mixed objects of various size, we advice you to use the multi-scale version scribo::binarization::sauvola_ms. In this version, the window size parameter is adapted at each scale and both large and small objects are correctly retrieved at the same time.
![]()
Input image. | ![]()
sauvola_ms with k=0.03. | ![]()
sauvola_ms with k=0.34. | ![]()
sauvola_ms with k=0.60. |
scribo::binarization::sauvola_threshold variants return an image of thresholds. The latter can be used afterwards to binarize the input image.
Compare results between all Sauvola's implementations. The window size is set to 51 and k is set to 0.34.
![]()
Input image. | ![]()
Binarization using scribo::binarization::sauvola |
![]()
Binarization using scribo::binarization::sauvola_ms | ![]()
Binarization using scribo::binarization::sauvola_split |
mln::trait::ch_value< I , bool >::ret scribo::binarization::sauvola | ( | const Image< I > & | input, |
unsigned | window_size, | ||
double | K | ||
) |
Convert an image into a binary image.
[in] | input | A greyscale image. |
[in] | window_size | The window size. |
[in] | K | Sauvola's formulae constant. |
mln::trait::ch_value< I , bool >::ret scribo::binarization::sauvola | ( | const Image< I > & | input, |
unsigned | window_size | ||
) |
Convert an image into a binary image.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Sauvola's formulae constant K is set to 0.34.
[in] | input | A grayscale image. |
[in] | window_size | The window size. |
mln::trait::ch_value< I , bool >::ret scribo::binarization::sauvola | ( | const Image< I > & | input | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. The window size is set to 11.
mln::trait::ch_value< I , bool >::ret scribo::binarization::sauvola_ms | ( | const Image< I > & | input_1, |
unsigned | w_1, | ||
unsigned | s, | ||
image2d< mln::util::couple< double, double > > & | integral_sum_sum_2 | ||
) |
Binarize an image using a multi-scale implementation of Sauvola's algoritm.
[in] | input_1 | A grayscale image. |
[in] | w_1 | The window size used to compute stats. |
[in] | s | The scale factor used for the first subscaling (usually 2 or 3 is enough). |
[out] | integral_sum_sum_2 | Integral image of sum and squared sum. |
Sauvola's formula parameter K is set to 0.34. w_1
and lambda_min_1
are expressed according to the image at scale 0, i.e. the original size.
In this implementation, the input image is subscaled at three different scales. For each subscale image, Sauvola's is applied and relevant objects are preserved. The results of the three scales is merged and areas of the input image are marked with the appropriate scale to use for final binarization. Finally, the input image is binarized, using, for each pixel, the correct window size of the scale where it has been retrieved.
This implementation is very useful for document image with heterogeneous object sizes.
Its implementation is meant to be the fastest as possible. For instance, statistics computation is based on integral images shafait2008drr.
mln::trait::ch_value< I , bool >::ret scribo::binarization::sauvola_ms | ( | const Image< I > & | input_1, |
unsigned | w_1, | ||
unsigned | s | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The integral image is not returned.
K is set to 0.34.
mln::trait::ch_value< I , bool >::ret scribo::binarization::sauvola_ms | ( | const Image< I > & | input_1, |
unsigned | w_1 | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The integral image is not returned.
K is set to 0.34. s is set to 3.
mln::trait::ch_value< I , bool >::ret scribo::binarization::sauvola_ms_split | ( | const Image< I > & | input_1, |
unsigned | w_1, | ||
unsigned | s, | ||
unsigned | min_ntrue, | ||
double | k2, | ||
double | k3, | ||
double | k4 | ||
) |
Binarize a color image merging the binarization of each component using Sauvola's algorithm.
[in] | input_1 | A color image. |
[in] | w_1 | The window size used to compute stats. |
[in] | s | The scale factor used for the first subscaling. |
[in] | min_ntrue | A site is set to 'True' in the output if it is set to 'True' at least min_ntrue components. Possible values: 1, 2, 3. |
[in] | k2 | Sauvola's formula parameter. |
[in] | k3 | Sauvola's formula parameter. |
[in] | k4 | Sauvola's formula parameter. |
w_1
is expressed according to the image at scale 0, i.e. the original size.
mln::trait::ch_value< I , bool >::ret scribo::binarization::sauvola_ms_split | ( | const Image< I > & | input_1, |
unsigned | w_1, | ||
unsigned | s, | ||
unsigned | min_ntrue, | ||
double | K | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. k2, k3 and k4 are set to K
.
mln::trait::ch_value< I , bool >::ret scribo::binarization::sauvola_ms_split | ( | const Image< I > & | input_1, |
unsigned | w_1, | ||
unsigned | s, | ||
unsigned | min_ntrue | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. k2, k3 and k4 are set to 0.34.
mln::trait::ch_value< I , value::int_u8 >::ret scribo::binarization::sauvola_threshold | ( | const Image< I > & | input, |
unsigned | window_size, | ||
double | K | ||
) |
Compute an image of local threshold using Sauvola algorithm.
[in] | input | A gray level image. |
[in] | window_size | The window size. |
[in] | K | Controls the threshold value in the local window. |
mln::trait::ch_value< I , value::int_u8 >::ret scribo::binarization::sauvola_threshold | ( | const Image< I > & | input, |
unsigned | window_size | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.K is set to 0.34.
mln::trait::ch_value< I , value::int_u8 >::ret scribo::binarization::sauvola_threshold | ( | const Image< I > & | input | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The window size is set to 11.