Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to perform Histogram Equalization on an image. For that i need to store the pixel intensity values in an array.
How can i get the intensity or gray scale value (0-255) of a pixel in C#
Pls help.

Thanks :)
Posted
Updated 1-Feb-13 7:57am
v3
Comments
Sergey Alexandrovich Kryukov 1-Feb-13 13:27pm    
Not a question. Also, what library do you want to use, System.Drawing, WPF, or something else?
It is just one pixel (performance is a problem)? And what did you try?
—SA
fjdiewornncalwe 1-Feb-13 13:30pm    
You have to define what "intensity" means to you and then find a way to compare the value of the pixel with that "intensity" definition.
You'll need to provide a lot more information than this if you want a better answer.

1 solution

There are several color models, also known as color spaces[^] (http://en.wikipedia.org/wiki/List_of_color_spaces_and_their_uses[^]). A pixel can be represented in any of them - but not all colors are present in all color spaces. A color space defines components of a color. On a general monitor screen you use RGB (red-green-blue) but for example the color model used in typography is the CMYK (cyan-magenta-yellow-black). But there are more. An image file on your computer is most likely in RGB or CMYK.

There is a color model called HSI (hue-saturation-intensity), you might find useful if you are interested in the intensity part. The conversion from RGB is quite simple, as described here: http://fourier.eng.hmc.edu/e161/lectures/color_processing/node3.html[^]. I suggest you consult this article first, but if does not fits your needs, try other color spaces too.
You can play around also with tools like this to get a practical insight on color components: http://www.workwithcolor.com/color-converter-01.htm[^]
 
Share this answer
 
v2
Comments
deepaksharma0390 1-Feb-13 14:05pm    
my image is a gray scale one
Zoltán Zörgő 1-Feb-13 14:10pm    
Than what is the problem? The intensity of a pixel is the value of any of the R,G or B components (supposing RGB(A)), or the value of the color itself if it is a 8bppx image.
Here is a sample about PixelFormat property and how to access pixels: http://msdn.microsoft.com/en-us/library/system.drawing.image.pixelformat.aspx, and the Color class contains methods to access color components, even simple color space transformations.
deepaksharma0390 1-Feb-13 14:17pm    
Is the value of intensity value is calculated using the formula below ?

intensity=(int)(0.3f * color.R + 0.59f * color.G + 0.11f * color.B);
Zoltán Zörgő 1-Feb-13 14:23pm    
Where are this float values coming from? If you look at the link about the RGB to HSI conversion, it is as easy as this: I=(R+G+B)/3
But the Color class gas a GetBrightness method that could be also good for you.
deepaksharma0390 1-Feb-13 14:29pm    
Thanks a ton...that solved my query.
Thanks again :)

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