local_threshold
— Segment an image using local thresholding.
local_threshold(Image : Region : Method, LightDark, GenParamName, GenParamValue : )
local_threshold
segments a single-channel image Image
using the thresholding method given in Method
and returns the
segmented region in Region
. Currently the operator offers only the
Method 'adapted_std_deviation' . This algorithm is a text
binarization technique and provides good results for document images.
By selecting Method
= 'adapted_std_deviation' , a
locally adaptive thresholding based on local mean and standard
deviation according to Sauvola (see the paper in References) is
invoked. The algorithm is able to segment document images even if
they are degraded, e.g., due to inhomogeneous illumination or noise.
It enables text binarization on an inhomogeneous background by taking
into account the local contrast.
For a segmentation of the dark foreground (see parameter
LightDark
), for a pixel at position
(r,c)
, a local threshold
T(r,c)
is calculated within a window of size
'mask_size' x 'mask_size' (see the generic
parameter 'mask_size' ) as follows:
where is the local mean value
within the window and denotes
the corresponding standard deviation. The parameter
R
(see 'range' ) is the assumed maximum
value of the standard deviation (R
= 128 for
byte images) and k
(see 'scale' ) a
parameter that controls how much the threshold value
T(r,c)
differs from the mean value
. If there is high contrast in the
neighborhood of a point (r,c)
the standard
deviation has a value close to
R
which yields a threshold value
T(r,c)
close to the local mean
. If the contrast is low, the local
threshold is below the local mean value. For dark text on light
background containing also darker regions, this lower threshold
enables the segmentation of the text even in darker areas.
The parameter LightDark
controls, whether light or dark
structures are segmented.
If LightDark
= 'dark' ,
dark structures on a light background are segmented. Every
pixel p(r,c)
whose gray value is smaller
than the calculated local threshold
T(r,c)
is selected.
If LightDark
= 'light' ,
light structures on a dark background are segmented. The result
is essentially the same as if the image would have been inverted
and then, LightDark
was set to 'dark' .
By setting GenParamName
to one of the following values, additional
parameters specific for the 'adapted_std_deviation' method can be set
with GenParamValue
:
specifies the mask size, i.e., the size of the neighborhood in which the local threshold is calculated. The smaller the window size the thinner the segmented strokes. 'mask_size' must be set to a value that is larger than the stroke width of the characters or structures to be segmented. If 'mask_size' is even, the next larger odd value is used.
Suggested values: 15, 21, 31.
Default: 15.
sets the parameter k
(), that controls how much the threshold
value differs from the local mean value. Use smaller values for
'scale' to also segment structures with a lower
contrast to their background. Use larger values to suppress
clutter.
Suggested values: 0.2, 0.3, 0.5.
Default: 0.2.
sets the maximum assumed value of standard deviation
R
. This parameter should be adapted based
on the expected gray value range. As a rule of thumb, the
value for 'range' can be set to , where MinGray and MaxGray are
the minimum and maximum gray values in the image, which can be
determined with min_max_gray
.
Suggested values: 128, 32767.5.
Default: 128 (for byte
images),
32767.5 (for uint2
images).
Note that filter operators may return unexpected results if an image with a reduced domain is used as input. Please refer to the chapter Filters.
Image
(input_object) singlechannelimage(-array) →
object (byte / uint2)
Input Image.
Region
(output_object) region(-array) →
object
Segmented output region.
Method
(input_control) string →
(string)
Segmentation method.
Default: 'adapted_std_deviation'
List of values: 'adapted_std_deviation'
LightDark
(input_control) string →
(string)
Extract foreground or background?
Default: 'dark'
List of values: 'dark' , 'light'
GenParamName
(input_control) attribute.name(-array) →
(string)
List of generic parameter names.
Default: []
List of values: 'mask_size' , 'range' , 'scale'
GenParamValue
(input_control) attribute.value(-array) →
(integer / real)
List of generic parameter values.
Default: []
Suggested values: 0.2, 15, 30, 128.0
connection
,
select_shape
,
select_gray
auto_threshold
,
binary_threshold
,
char_threshold
J. Sauvola, M. Pietikäinen, “Adaptive document image binarization", Pattern Recognition, 33, 225-236 (2000)
Foundation