Skip to contents

threshold transforms an image to a binary image.

Usage

threshold(
  image,
  thresh = 127,
  max_value = 255,
  method = "none",
  threshold_type = "binary",
  mask = NULL,
  target = "new",
  in_place = NULL
)

Arguments

image

An an 8-bit (8U) or 32-bit floating (32F) Image object.

thresh

A numeric threshold value (default: 127).

max_value

Non-zero value assigned to the pixels for which the condition determined by `threshold_type` is satisfied (default: 255). It is used only if threshold_type is set to "binary" or "inverse".

method

The name of the automated thresholding algorithm to use. It can be any of the following:

  • "none":the user-defined `threshold` value is used (the default).

  • "ImageJ":the default auto thresholding algorithm of ImageJ.

  • "Huang":Huang’s fuzzy thresholding method.

  • "Huang2":alternative implementation of Huang’s method by J. Schindelin.

  • "Intermodes":assuming a bimodal histogram, the threshold is the halfway point between the two modes.

  • "IsoData":iterative procedure based on the isodata algorithm of Ridler and Calvar.

  • "Li":Li’s Minimum Cross Entropy thresholding method based on the iterative version of the algorithm.

  • "MaxEntropy":Kapur-Sahoo-Wong (Maximum Entropy) thresholding method.

  • "Mean":the mean of grey levels of the image is used as the threshold.

  • "MinErrorI":an iterative implementation of Kittler and Illingworth’s Minimum Error thresholding.

  • "Minimum":similar to the Intermodes method but the threshold is the minimum value between the two modes after iterative smoothing.

  • "Moments":Tsai’s moment-preserving thresolding method.

  • "Otsu":Otsu’s threshold clustering method.

  • "Percentile":assumes the fraction of foreground pixels to be 0.5.

  • "RenyiEntropy":similar to the MaxEntropy method, but using Renyi’s entropy instead.

  • "Shanbhag":Shanbhag's information-based thresolding method.

  • "Triangle":the triangle thresholding method by Zack, Rogers, and Latt.

  • "Yen":Yen’s thresholding method.

Details about the functioning of each method can be found at https://imagej.net/plugins/auto-threshold.

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.

mask

A single-channel (GRAY) 8-bit (8U) Image object with the same dimensions as image. This can be used to mask out pixels that should not be considered when calculating the threshold (pixels set to 0 in the mask will be ignored during the threshold calculation).

target

The location where the results should be stored. It can take 3 values:

  • "new":a new Image object is created and the results are stored inside (the default).

  • "self":the results are stored back into image (faster but destructive).

  • An Image object:the results are stored in another existing Image object. This is fast and will not replace the content of image but will replace that of target. Note that if target does not have the same dimensions, number of channels, and bit depth as image, an error may be thrown.

in_place

Deprecated. Use target instead.

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.

Acknowledgements

Gabriel Landini coded all of these functions in Java. These java functions were then translated to C++ by Rory Nolan.

References

  • Huang, L-K & Wang, M-J J (1995), "Image thresholding by minimizing the measure of fuzziness", Pattern Recognition 28(1): 41-51

  • Prewitt, JMS & Mendelsohn, ML (1966), "The analysis of cell images", Annals of the New York Academy of Sciences 128: 1035-1053

  • Ridler, TW & Calvard, S (1978), "Picture thresholding using an iterative selection method", IEEE Transactions on Systems, Man and Cybernetics 8: 630-632

  • Li, CH & Lee, CK (1993), "Minimum Cross Entropy Thresholding", Pattern Recognition 26(4): 617-625

  • Li, CH & Tam, PKS (1998), "An Iterative Algorithm for Minimum Cross Entropy Thresholding", Pattern Recognition Letters 18(8): 771-776

  • Sezgin, M & Sankur, B (2004), "Survey over Image Thresholding Techniques and Quantitative Performance Evaluation", Journal of Electronic Imaging 13(1): 146-165

  • Kapur, JN; Sahoo, PK & Wong, ACK (1985), "A New Method for Gray-Level Picture Thresholding Using the Entropy of the Histogram", Graphical Models and Image Processing 29(3): 273-285

  • Glasbey, CA (1993), "An analysis of histogram-based thresholding algorithms", CVGIP: Graphical Models and Image Processing 55: 532-537

  • Kittler, J & Illingworth, J (1986), "Minimum error thresholding", Pattern Recognition 19: 41-47

  • Prewitt, JMS & Mendelsohn, ML (1966), "The analysis of cell images", Annals of the New York Academy of Sciences 128: 1035-1053

  • Tsai, W (1985), "Moment-preserving thresholding: a new approach", Computer Vision, Graphics, and Image Processing 29: 377-393

  • Otsu, N (1979), "A threshold selection method from gray-level histograms", IEEE Trans. Sys., Man., Cyber. 9: 62-66, doi:10.1109/TSMC.1979.4310076

  • Doyle, W (1962), "Operation useful for similarity-invariant pattern recognition", Journal of the Association for Computing Machinery 9: 259-267, doi:10.1145/321119.321123

  • Kapur, JN; Sahoo, PK & Wong, ACK (1985), "A New Method for Gray-Level Picture Thresholding Using the Entropy of the Histogram", Graphical Models and Image Processing 29(3): 273-285

  • Shanbhag, Abhijit G. (1994), "Utilization of information measure as a means of image thresholding", Graph. Models Image Process. (Academic Press, Inc.) 56 (5): 414--419, ISSN 1049-9652

  • Zack GW, Rogers WE, Latt SA (1977), "Automatic measurement of sister chromatid exchange frequency", J. Histochem. Cytochem. 25 (7): 74153, PMID 70454

  • Yen JC, Chang FJ, Chang S (1995), "A New Criterion for Automatic Multilevel Thresholding", IEEE Trans. on Image Processing 4 (3): 370-378, ISSN 1057-7149, doi:10.1109/83.366472

  • Sezgin, M & Sankur, B (2004), "Survey over Image Thresholding Techniques and Quantitative Performance Evaluation", Journal of Electronic Imaging 13(1): 146-165

Author

Simon Garnier, garnier@njit.edu

Examples

balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
balloon_gray <- changeColorSpace(balloon, "GRAY")
balloon_th <- threshold(balloon_gray)