灰度图像到二进制图像 [英] gray image to binary image

查看:146
本文介绍了灰度图像到二进制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请我需要最好的java代码将灰色图像转换为二进制图像



i尝试了很多例子,但它不准确,例如当绘制的输出时将照片保存为单声道位图

please i need the best java code to convert gray image to binary image

i tried alot of examples but it is not accurate like for example the output of paint when save the photo as mono bitmap

推荐答案

我认为您需要通过某个阈值或类似标准将图像转换为黑白。



如果你只想一点,你会明白这种过滤器不能或多或少准确。它会根据某个阈值将一个图像转换为另一个图像,但是您可以决定选择何种阈值。







更确切地说,不准确这个词在这里完全不适用。如果你知道某些图像变换的最终完美结果,你可以将它与你得到的结果进行比较,但是没有一个完美的明确的变换。通过制作黑白图像,您总会丢失一些信息。究竟要失去什么,是一个哲学问题。这取决于输入图像和一些很难制定的标准。



[结束编辑#1]









您可以使用,例如, AForge.Imaging.Filters.Threshold

http://www.aforgenet.com/framework/docs/html/503a43b9-d98b-a19f-b74e-44767916ad65.htm [ ^ ]。



这是来自着名的.NET开源库,名为AForge.NET:

http://en.wikipedia.org/wiki/Aforge.net [ ^ ],

http:/ /www.aforgenet.com/ [ ^ ]。
对于阈值过滤器,请见 org.jscience.computing.ai.vision.Filter

http://jscience.org/experimental/javadoc/org/jscience/computing/ai/vision/ThresholdFilter.html [ ^ ]。



您可以在JScience库中找到它: http://jscience.org/ [ ^ ]。



[结束编辑#2]

-SA
I think you need to convert the image to black and white by some threshold or similar criterion.

If you think at it just a bit, you will understand that this kind if filter cannot be more or less "accurate". It converts one image to another one according some threshold value, but this is you who can decide what threshold to choose.



More exactly, the word "inaccurate" it totally inapplicable here. If you knew the final "perfect" result of some image transformation, you could compare it with the results you got, but there is no a "perfect" unambiguous transformation. By making a black-and-white image, you always lose some information. What exactly to lose, is a philosophical question. It depends on the input image and some criteria which can be quite hard to formulate.

[END EDIT #1]




You can use, for example, AForge.Imaging.Filters.Threshold:
http://www.aforgenet.com/framework/docs/html/503a43b9-d98b-a19f-b74e-44767916ad65.htm[^].

This is from the well-known open-source library for .NET called AForge.NET:
http://en.wikipedia.org/wiki/Aforge.net[^],
http://www.aforgenet.com/[^].
For the threshold filter, please see org.jscience.computing.ai.vision.Filter:
http://jscience.org/experimental/javadoc/org/jscience/computing/ai/vision/ThresholdFilter.html[^].

You can find it in the JScience library: http://jscience.org/[^].

[END EDIT #2]
—SA


正如您所要求的java解决方案,我可以推荐OpenCV [ ^ ]。在这里你有一个很好的教程,关于使用阈值转换将图像转换为二进制(黑白),也有一些理论: http://docs.opencv.org/doc/tutorials/imgproc/threshold/threshold.html [ ^ ]。您会注意到,没有最佳方法,您必须选择最适合您的方法。注意,那里的样本不是Java,但是在java中很容易做同样的事情,因为它们都使用OpenCV。



二进制化通常是一种特殊类型的图像分割 [ ^ ],还有其他更复杂的方面阈值。请注意,二值化也可以是形态学操作,如骨架提取。



如果你不想要OpenCV,请看这里: http://zerocool.is-a-geek.net/?p=376 [ ^ ]



[更新:重要链接缺失]
As you asked for java solution, I can recommend OpenCV[^]. And here you have a good tutorial about converting an image to binary (black and white) using thresholding, with some theory too: http://docs.opencv.org/doc/tutorials/imgproc/threshold/threshold.html[^]. You will notice, that there is no best method, you will have to choose the most suitable for you. Note, that the samples there are not in Java, but it will be easy to do the same in java since both use OpenCV.

Binarization is in general a special type of image segmentation[^], and there are other, more complex aspects of that than thresholding. Please note also, that binarization can be a morphological operation too, like skeleton extraction.

If you don''t want OpenCV, look here: http://zerocool.is-a-geek.net/?p=376[^]

[update: important link was missing]


这篇关于灰度图像到二进制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆