Re: calculating # of pixels of 3 colors in RGB image using a histogram [message #42652] |
Sat, 19 February 2005 06:47 |
Chris Lee
Messages: 101 Registered: August 2003
|
Senior Member |
|
|
In article <1108751817.410432.294440@c13g2000cwb.googlegroups.com>,
"coold" <nrodricks@gmail.com> wrote:
> Hi,
> I am trying to calculate the number of pixels using a histogram
> specifically for 3 colors(white,black and green) in a image (256
> colors).
> I have modified the color palette for the image so that the background
> is white and the dark colors are black and the light green remains the
> same.
> I am unable to interpret the results as indicated by the histogram. I
> have uploaded the pictures.
> http://pg.photos.yahoo.com/ph/coold_2006/album?.dir=/b4b9&am p;.src=ph Would
> appreciate any help in how to calculate the number of pixels of white,
> black and green.
> Thanks.
> coold
>
If the data is 2D (i.e color table indices) then your histogram will show
the number of points corresponding to each color, i.e if black=0 and
white=255 then
plot, histogram(data, binsize=1, min=0, max=255)
would give you a histogram of the colors, the number in the '0' bin is
the number of black points etc. Probably better to print the values
rather than just plot them.
If the data is 3D, i.e. truecolor, then you need to histogram over each
color component( red, green, blue). Since you only have green 'color' in
the image, you could try using the green component only since black and
white have the same value in each component. In either case, you will
get a spread in the data around the three main colors, because of the
color variation in the image. You'll need to decide where each color
starts and ends in your color spectrum (what values are green enough to
count as green etc.)
If you want to do it in truecolor, with all three components, you need to
decide what range of RGB color values are 'green' and you might want to
convert the 3D data into 2D data by converting to a linear index of colors
(e.g. (r*255+g)*255+b or whatever it is).
Chris.
|
|
|