0
我已經加載圖像gray sclae
,我知道我需要使用閾值來對其進行二值化。但如何在Java中做到這一點?Java OpenCV:如何將彩色圖像轉換爲黑白圖像?
Mat imageMat = Imgcodecs.imread(picDir + "color_console.tif",
Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
//then what API?
我已經加載圖像gray sclae
,我知道我需要使用閾值來對其進行二值化。但如何在Java中做到這一點?Java OpenCV:如何將彩色圖像轉換爲黑白圖像?
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。它更仔細地執行閾值,但它在計算上相當昂貴。 Java的文檔是here。