niBlackThreshold performs thresholding on an
Image object using Niblack's technique or some of the popular
variations it inspired.
Usage
niBlackThreshold(
image,
max_value = 255,
threshold_type = "binary",
block_size = 31,
k = 0.5,
method = "Niblack",
r = 128,
target = "new"
)Arguments
- image
An 8-bit (8U) single-channel
Imageobject.- max_value
Non-zero value assigned to the pixels for which the condition is satisfied (default: 255). It is used only if
threshold_typeis set to "binary" or "inverse".- threshold_type
The name of the threshold type to use. It can be any of the following:
- "binary":
each pixel is replaced by `max_value` if its value is above the threshold, and by zero otherwise (the default).
- "inverse":
each pixel is replaced by zero if its value is above the threshold, and by `max_value` otherwise.
- "truncate":
each pixel is replaced by `threshold` if its value is above the threshold, and is unchanged otherwise.
- "to_zero":
each pixel is replaced by zero if its value is below the threshold, and is unchanged otherwise.
- "to_zero_inverse":
each pixel is replaced by zero if its value is above the threshold, and is unchanged otherwise.
- block_size
Size of a pixel neighborhood that is used to calculate a threshold value for the pixel (default: 31). It must be an odd number greater than 1.
- k
A user-adjustable parameter used by Niblack and inspired techniques. For Niblack, this is normally a value between 0 and 1 that is multiplied with the standard deviation and subtracted from the mean.
- method
A string indicating the binarization method to use. It can be any of the following:
"Niblack (the default)"
"Sauvola"
"Wolf"
"Nick"
- r
A user-adjustable parameter used by Sauvola's technique. This is the dynamic range of standard deviation.
- target
The location where the results should be stored. It can take 3 values:
- "new":
a new
Imageobject is created and the results are stored inside (the default).- "self":
the results are stored back into
image(faster but destructive).- An
Imageobject: the results are stored in another existing
Imageobject. This is fast and will not replace the content ofimagebut will replace that oftarget. Note that iftargetdoes not have the same dimensions, number of channels, and bit depth asimage, an error may be thrown.
Value
If target="new", the function returns an Image
object. If target="self", the function returns nothing and modifies
image in place. If target is an Image object,
the function returns nothing and modifies that Image object in
place.
Author
Simon Garnier, garnier@njit.edu
Examples
balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
balloon_gray <- changeColorSpace(balloon, "GRAY")
balloon_th <- niBlackThreshold(balloon_gray)