1

I have loaded the image as gray sclae, I know I need use threshold to binarize it. But how to do it in Java?

Mat imageMat = Imgcodecs.imread(picDir + "color_console.tif",
Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);

//then what API?
smwikipedia
  • 61,609
  • 92
  • 309
  • 482

1 Answers1

3

I recommend you to read this tutorial about thresholding: http://docs.opencv.org/doc/tutorials/imgproc/threshold/threshold.html.

Documentation for threshold function in Java is here. THRESH_BINARY and THRESH_BINARY_INV modes are suitable for binarization.

For example:

Mat binarized; threshold(imageMat, binarized, 100, 255, THRESH_BINARY);

If result will be unsatisfied, you can try adaptivehreshold function. It performs thresholding more carefully, but it's quite computationally expensive. Documentation for Java is here.

akarsakov
  • 2,134
  • 4
  • 21
  • 26