Click here to Skip to main content
13,554,936 members
Rate this:
Please Sign up or sign in to vote.
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 1-Feb-13 7:24am
Updated 1-Feb-13 7:57am
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?
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

There are several color models, also known as color spaces[^] ([^]). 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:[^]. 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:[^]
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:, 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 :)
Zoltán Zörgő 1-Feb-13 14:30pm
Great! Than feel free to accept my answer. :)
Zoltán Zörgő 1-Feb-13 14:25pm
Ah, you mean Luma? Well, that's an other option. Be aware, that histogram equalization is a method, you can apply to several things including different color spaces according to your needs.
deepaksharma0390 1-Feb-13 14:32pm
i want to perform the histogram equalization of a gray scale image.
so will this intensity value be correct for the histogram ?
Zoltán Zörgő 1-Feb-13 14:58pm
Yes. As I said you have more options. Intensity from HSI, Value from HSV, Brightness from HSB or even Luma/Luminescence are good choices. In a practical situation it would depend on the image source and your final goals.
Zoltán Zörgő 2-Feb-13 3:40am
And what about accepting my answer?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180515.1 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100