单色黑白位图
我正在 Android 上工作,将从相机捕获的彩色位图转换为黑白单色图像(没有灰色!)。
我有几种灰度转换方法,但我无法将图像转换为黑白格式。
有没有什么方法可以将位图转换成这种格式?
I'm working on Android for converting a colored bitmap captured from the camera into a black-and-white monochromatic image (no grays!).
I've got several methods for the gray scale conversion but I can't manage to get my image to a b&W format.
Are there any methods for converting a bitmap into this format?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种可靠的方法是平均阈值位图。该方法在本文中的方法部分中进行了描述。它通常用于图像对齐,并对不同的亮度级别进行补偿等。您可以直接从颜色使用它,也可以在灰度转换后使用它。获取图像后,您可以简单地使用缓冲区中的
setPixels()
将白色像素设置为白色,将黑色像素设置为黑色。您还可以对其进行调整,使其不完全使用平均值。您可以有一个 0-100% 黑色的滑块,其中平均值为 50%。这样您就可以对每张图片进行即时调整。您只需重新计算阈值并再次应用像素缓冲区即可。
One solid way is a mean threshold bitmap. The method is described in this paper, in the method section. It's often used for image alignment, and will compensate for different brightness levels, etc. You can use it straight from color, or after a greyscale conversion. After you get your image, you can simply set the white pixels to white, and black to black with
setPixels()
from a buffer.You can also tweak it so that it doesn't use the mean exactly. You could have a slider for 0-100% black, where the mean would be 50%. That way you could do on-the-fly adjustments for each individual picture. You just have to recalculate the threshold and apply the pixel buffer again.
您可以尝试以下方法:
You can try this approatch: