Determining frequency of colours in a BMP

Determining frequency of colours in a BMP

Post by Pete Sergean » Tue, 20 May 2003 19:30:45



Hi,

I'd like to determine the frequency distribution of RGB colours in a 24-bit
BMP.  I tried to use the brute-force approach of creating an array of bins
[0..16777215] of integer, and then simply incrementing the appropriate bin
using the RGB value as the index, but Delphi7 didn't even tell me why it
crashed!  This approach works for 8-bit or 12-bit values, and the help tells
me I can create an array up to 2GB.  The above-mentioned array is only (!)
64MB, and my computer has 512MB.

I'm not looking to simply count the number of different colours; the routine
suggested by Earl Glynn on his website does that nicely.  I want to know
what each one is, and how many times it appears in the image, i.e.

Colour 0:  R=12, R=234, B=45, number = 165

and so on, with (obviously) the sum of all the individual numbers being the
total number of pixels in the image.

Any ideas?

Thanks

Pete