如何从二进制图像中获取值1或0? [英] How to get values 1 or 0 from binary images?

查看:71
本文介绍了如何从二进制图像中获取值1或0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码



That is my code

Image<Gray, Byte> image = new Image<Gray, byte>(Openfile.FileName);
pictureBox1.Image = image.ToBitmap();
image1 = image1.ThresholdBinary(new Gray(50), new Gray(255));



我打开我的图片桌面并将其转换为灰度,然后二进制。我想从二进制图像中获取值1或0,以便存储在矩阵中。我怎样才能做到这一点??我正在使用emgucv。


I open an image from my desktop and convert it to grayscale and then binary. I want to get either the values 1 or 0 from binary images in order to storage in matrix. How can I do that?? I am using emgucv.

推荐答案

记住黑白图像的值为0和255.所以如果你想要0和1,那么:



Remember a black and white image has values 0 and 255. So if you want 0 and 1 then either:

image = image.ThresholdBinary(new Gray(50), new Gray(255));

 for (int v = 0; v < image.Height; v++)
 {
     for (int u = 0; u < image.Width; u++)
     {
         int a = image.Data[v, u, 0] & 1; //Get Pixel
    }
 }











OR

image = image.ThresholdBinary(new Gray(50), new Gray(1));

for (int v = 0; v < image.Height; v++)
{
    for (int u = 0; u < image.Width; u++)
    {
        int a = image.Data[v, u, 0]; //Get Pixel
    }
}





在这个例子中,我们使用图像的Data属性。 http://www.emgu.com/wiki/index.php/Working_with_Images [ ^ ]


这篇关于如何从二进制图像中获取值1或0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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