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?
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?
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
andTHRESH_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.