Verifying image pixel wise whether it its Color or B/w in a faster way..

Posted by Sukesh.net under C# on 2/15/2012 | Points: 10 | Views : 4697 | Status : [Member] | Replies : 4
Hi Every one.. I want to know whether a image is color (or) Black&white by comparing with every pixel of a image using C# in faster way.... how can we get this code.. please help me.. Thanks in Advance

Thanks
Sukesh



Responses

Posted by: Vuyiswamb on: 2/15/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
i but note that a Photo might contain Pixels of Diffident colour so it might be difficult to say the whole Picture is of certain colour. But here are some resources that might help you

http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.getpixel.aspx

http://csharpmentor.blogspot.com/2009/05/get-rgb-color-at-point-in-image-with.html

Thank you for posting at Dotnetfunda
[Administrator]

Sukesh.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sukesh.net on: 2/15/2012 [Member] Starter | Points: 25

Up
0
Down
Hi i don't want the particular pixel color.. I want to verify weather the image is color (or) black and white..if we got any color pixel it has to show it is a color image, and we have to check every pixel if we didn't get any color pixel (i.e all are black and white (or) gray scale colors) it must show it is black and white image.

Note: when ever we got the color pixel stop to verify and it must show its color image, otherwise it has to verify till the end.. I did the code but its taking 2sec time for black and white image. i need much faster..

Thanks
Sukesh

Sukesh.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bipro.reader on: 2/16/2012 [Member] Starter | Points: 25

Up
0
Down
1) First determine the dimension of the image,
2) loop through each pixel and check whether any color other than white or black exist , if yes, echo "color image" message.

Code snippet:

static int check;
protected void Page_Load(object sender, EventArgs e)
{
int x,y;
Bitmap image = (Bitmap) Bitmap.FromFile(@"C:\xyz\test_color.bmp");
x = Int32.Parse(image.Width.ToString());
y = Int32.Parse(image.Height.ToString());
for(int i =0;i<x;i++)
{
for (int j = 0; j < y; j++)
{
Color pixelColor = image.GetPixel(i, j);
if ( (pixelColor.R == 255 && pixelColor.G == 255 && pixelColor.B == 255) || (pixelColor.R == 0 && pixelColor.G == 0 && pixelColor.B == 0))
continue;
else
{
check = -1;
lblUserName.Text = "Color Image";
break;
}
}
if (check < 0)
break;
}

Sukesh.net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sukesh.net on: 2/16/2012 [Member] Starter | Points: 25

Up
0
Down
Thank you very much Bipro.. the code is working but its taking 7 sec to read black and white picture..Please suggest us any code take less than 400ms and i need one more point, i want to know the image is Gray scale image or not..

Note: i want to differentiate gray scale image and color image please provide in faster way...

Thanks
Sukesh

Sukesh.net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response