Java OpenCV: How to convert a color image into black and white?

南笙酒味 提交于 2019-12-08 11:22:48

问题


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:


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.



来源:https://stackoverflow.com/questions/30250950/java-opencv-how-to-convert-a-color-image-into-black-and-white

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!