2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > 图像加斑点java Java OpenCV:如何将彩色图像转换为黑白图像?

图像加斑点java Java OpenCV:如何将彩色图像转换为黑白图像?

时间:2023-01-12 01:15:18

相关推荐

图像加斑点java Java OpenCV:如何将彩色图像转换为黑白图像?

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?

解决方案

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.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。