Threshold an image by local mean and standard deviation analysis.
The operator 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 window of size MaskWidth x MaskHeight around each pixel (x,y). If MaskWidth or MaskHeight is even, the next larger odd value is used. The mask window should be greater than the image features to be segmented and it should comprise at least three pixels.
Let g(x,y) be the gray value at position (x,y) in the input image Image and m(x,y) and d(x,y) the corresponding mean and standard deviation of the gray values in the window around that pixel and
v(x,y) = max( StdDevScale * d(x,y),AbsThreshold) for StdDevScale >= 0or
v(x,y) = min( StdDevScale * d(x,y),AbsThreshold) for $StdDevScale < 0$.
The standard deviation is used as a measure of noise in the image and scaled by StdDevScale to reflect the desired sensitivity. The threshold condition is determined by the parameter LightDark:
LightDark = 'light':
g(x,y) >= m(x,y) + v(x,y).
LightDark = 'dark':
g(x,y) <= m(x,y) - v(x,y).
LightDark = 'equal':
m(x,y) - v(x,y) <= g(x,y)
<= m(x,y) + v(x,y).
LightDark = 'not_equal':
m(x,y) - v(x,y) > g(x,y) or g(x,y) < m(x,y) + v(x,y).
All pixels fulfilling the above condition are aggregated into the resulting region Region.
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. The parameter AbsThreshold places an additional threshold on StdDevScale*dev(x,y). If StdDevScale*dev(x,y) is below AbsThreshold for positive values of StdDevScale or above for negative values StdDevScale, AbsThreshold is taken instead.
|
Image (input_object) |
singlechannelimage(-array) -> object : byte / int2 / int4 / uint2 / real |
| Input image. | |
|
Region (output_object) |
region(-array) -> object |
| Segmented regions. | |
|
MaskWidth (input_control) |
extent.x -> integer |
| Mask width for mean and deviation calculation. | |
| Default value: 15 | |
| Suggested values: 9, 11, 13, 15 | |
| Restriction: MaskWidth >= 1 | |
|
MaskHeight (input_control) |
extent.y -> integer |
| Mask height for mean and deviation calculation. | |
| Default value: 15 | |
| Suggested values: 9, 11, 13, 15 | |
| Restriction: MaskHeight >= 1 | |
|
StdDevScale (input_control) |
real -> real |
| Factor for the standard deviation of the gray values. | |
| Default value: 0.2 | |
| Suggested values: -0.2, -0.1, 0.1, 0.2 | |
|
AbsThreshold (input_control) |
real -> real |
| Minimum gray value difference from the mean. | |
| Default value: 2 | |
| Suggested values: -2, -1, 0, 1, 2 | |
|
LightDark (input_control) |
string -> string |
| Threshold type. | |
| Default value: 'dark' | |
| List of values: 'dark', 'light', 'equal', '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.
var_threshold is reentrant and automatically parallelized (on tuple level, domain level).
W.Niblack, ''An Introduction to Digital Image Processing'', Page 115-116, Englewood Cliffs, N.J., Prentice Hall, 1986
Foundation