Java OpenCV: How to convert a color image into bla

2019-06-11 17:11发布

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?

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-06-11 17:50

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.

查看更多
登录 后发表回答