Operators |
var_threshold — Threshold an image by local mean and standard deviation analysis.
var_threshold(Image : Region : MaskWidth, MaskHeight, StdDevScale, AbsThreshold, LightDark : )
With var_threshold , it's possible to select the pixels of the input Image which
have a high local standard deviation (for a positive StdDevScale), or a low local standard deviation (for a negative StdDevScale)
and
are locally bright or dark, according to LightDark.
Thus, it is possible to segment regions on inhomogeneous, noisy, or unevenly illuminated backgrounds.
The size of the filter mask defined by MaskWidth and MaskHeight determines the maximum size of the objects to be segmented. However, if the mask is chosen too large, objects that are very close might be merged.
(1) | (2) |
(3) | (4) |
If MaskWidth or MaskHeight is even, the next larger odd value is used. Altogether, a value of 3 can be considered the minimum sensible value.
The local standard deviation is used as a measure of noise in the image. It can be scaled by StdDevScale to reflect the desired sensitivity. A higher value means that only pixels that are very different from their surrounding are selected.
For the parameter StdDevScale values between -1.0 and 1.0 are sensible choices, with 0.2 as a suggested value. If the parameter is too high or too low, an empty or full region may be returned.
(1) | (2) |
In homogeneous areas of an image, the standard deviation is low; thus, the influence of single gray values is high. To reduce the sensitivity of the operator in homogeneous areas, it's possible to adjust AbsThreshold. Thus, small gray value changes in homogeneous surroundings can be ignored. Note that for negative values of StdDevScale, AbsThreshold should also be chosen negative.
'light' or 'dark' returns all pixels that are lighter or darker than their surrounding, respectively. 'equal' returns all pixels that are not selected by either option, i.e. the pixels that are relatively equal to their surrounding. 'not_equal' returns the combined results of 'light' and 'dark' , i.e., all pixels that differ from their surrounding.
(1) | (2) |
var_threshold selects from the input image Image those regions Region in which the pixels fulfill a threshold condition. The threshold is calculated from the mean gray value and the standard deviation in a local mask of size MaskWidth x MaskHeight around each pixel (x,y).
Let
g(x,y) be the gray value at position (x,y) in the input Image,
m(x,y) the corresponding mean gray value, and
d(x,y) the corresponding standard deviation in the mask around that pixel.
Then, the variable threshold v(x,y) is defined as
Interpretation: For a positive StdDevScale, each pixel is analyzed. It is determined whether the user-defined AbsThreshold or the scaled standard deviation is greater. The bigger value is chosen as variable threshold v(x,y). For a negative StdDevScale, the corresponding smaller value is chosen.
Which pixels are chosen based on the variable threshold is defined by the parameter LightDark:
LightDark = 'light' :
Interpretation: If the pixel is brighter by v(x,y) than its surrounding, it is selected.
LightDark = 'dark' :
Interpretation: If the pixel is darker by v(x,y) than its surrounding, it is selected.
LightDark = 'equal' :
Interpretation: Select exactly those pixels that are not selected by 'light' and 'dark' , i.e., the pixels that are relatively equal to their surrounding.
LightDark = 'not_equal' :
Interpretation: Select all pixels of 'light' and 'dark' , i.e., all pixels that differ by v(x,y) from their surrounding.
This operator may return unexpected results if an image with a reduced domain is used as input. Please refer to the chapter Filters.
Input image.
Segmented regions.
Mask width for mean and deviation calculation.
Default value: 15
Suggested values: 9, 11, 13, 15
Restriction: MaskWidth >= 1
Mask height for mean and deviation calculation.
Default value: 15
Suggested values: 9, 11, 13, 15
Restriction: MaskHeight >= 1
Factor for the standard deviation of the gray values.
Default value: 0.2
Suggested values: -0.2, -0.1, 0.1, 0.2
Minimum gray value difference from the mean.
Default value: 2
Suggested values: -2, -1, 0, 1, 2
Threshold type.
Default value: 'dark'
List of values: 'dark' , 'equal' , 'light' , 'not_equal'
Let A be the area of the input region, then the runtime is O(A).
var_threshold returns 2 (H_MSG_TRUE) if all parameters are correct. The behavior with respect to the input images and output regions can be determined by setting the values of the flags 'no_object_result', 'empty_region_result', and 'store_empty_region' with set_system. If necessary, an exception is raised.
W.Niblack, ”An Introduction to Digital Image Processing”, Page 115-116, Englewood Cliffs, N.J., Prentice Hall, 1986
Foundation
Operators |