Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
That is my code

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

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.
Posted
Updated 1-Mar-14 18:52pm
v2
Comments
BillWoodruff 1-Mar-14 20:17pm    
You might consider posting a question on the EmguCV C# discussion group:

http://www.emgu.com/forum/viewforum.php?f=7&sid=411dd7bbf4f46dbae2f88f1f6d588f74

1 solution

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

C#
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

C#
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
    }
}


In this example we are using the Data property of the image. http://www.emgu.com/wiki/index.php/Working_with_Images[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900