Java OpenCV:如何将彩色图像转换为黑白图像?
Java OpenCV: How to convert a color image into black and white?
我已将图像加载为 gray sclae
,我知道我需要使用阈值对其进行二值化。但是Java怎么办呢?
Mat imageMat = Imgcodecs.imread(picDir + "color_console.tif",
Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
//then what API?
我建议您阅读有关阈值的教程:http://docs.opencv.org/doc/tutorials/imgproc/threshold/threshold.html。
Java 中 threshold
函数的文档是 here。 THRESH_BINARY
和THRESH_BINARY_INV
模式适合二值化。
例如:
Mat binarized;
threshold(imageMat, binarized, 100, 255, THRESH_BINARY);
如果结果不满意,可以试试adaptivehreshold
function. It performs thresholding more carefully, but it's quite computationally expensive. Documentation for Java is here.
我已将图像加载为 gray sclae
,我知道我需要使用阈值对其进行二值化。但是Java怎么办呢?
Mat imageMat = Imgcodecs.imread(picDir + "color_console.tif",
Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
//then what API?
我建议您阅读有关阈值的教程:http://docs.opencv.org/doc/tutorials/imgproc/threshold/threshold.html。
Java 中 threshold
函数的文档是 here。 THRESH_BINARY
和THRESH_BINARY_INV
模式适合二值化。
例如:
Mat binarized;
threshold(imageMat, binarized, 100, 255, THRESH_BINARY);
如果结果不满意,可以试试adaptivehreshold
function. It performs thresholding more carefully, but it's quite computationally expensive. Documentation for Java is here.