"Roy Schestowitz" <newsgroups@xxxxxxxxxxxxxxx> wrote in message
news:e096nu$69d$7@xxxxxxxxxxxxxxxxxxxx
> __/ [ tirzan ] on Monday 27 March 2006 16:31 \__
>
>> Roy Schestowitz wrote:
>>
>>> You can look up a precise description by searching the Web. In short,
>>> histogram bins involve taking the pixels whose values lie within a given
>>> range (say 0..255) and then partitioning that range into smaller chunks
>>> (bins or 'buckets'). You could, for example, have a bin that contains
>>> all
>>> pixels whose (greylevel) value is between 1 and 10.
>>
>> yes! thanks!
>>
>>> What are "min" and "max"?
>>
>> the min and the max grey value on the image, we can consider min=0 and
>> max=255
>> but (maybe) is more convenient to calculate the min and the max
>> before...
>>
>>> This seems okay, but why not use many of the
>>> existing implementation, which could be /far/ more efficient?
>>
>> do you have any link? or any example of a more efficient
>> implementation?
>>
>>> Hope it helps,
>>
>> sure!
>> thanks
>>
>> tirzan
>
> Have a look at VXL:
>
> http://vxl.sourceforge.net/
>
> It is very extensive and Open Source too.
>
> Hope it helps,
>
> Roy
>
> 
> Roy S. Schestowitz  Useless fact: sheep outnumber people in NZ
> http://Schestowitz.com  SuSE Linux ¦ PGPKey: 0x74572E8E
> 6:15pm up 19 days 8:00, 8 users, load average: 1.36, 0.91, 0.74
> http://iuron.com  help build a nonprofit search engine
Histograms are very simple. Here's some code (UNTESTED!!)
#define BINS 64
char* imagedata[
unsigned long histogram[BINS];
unsigned long histo_total;
int result;
unsigned long histo_perc;
int pixel_value;
int total_pixels = image_width * image_height;
memset(histogram,0,BINS*sizeof(long));
for(int y = 0; y<image_height;y++)
for(x=;x<image_width;x++)
{
pixel_value = GetPixel(x,y);
pixel_value /=BINS;
histogram[pixel_value]++;
histo_total++;
}
// You may want to normalise the histogram
// This loop gives the bins as a percentage of the total number of pixels
// NB you may want to multiply by a larger value or make the histogram array
of type float to get better than 1% resolution here
for(i=0;i<BINS;i++)
histogram[i] = histogram[i] * 100 / histo_total;
// You may want to find the grey level of a percentile, e.g. the median
brighness, or the level that 90% of pixels are darker than
// These can be useful in automatic thresholding
// This code assumes you have normalised. If not then scale the histo_total
to get the stopping condition, in place of 90 here.
histo_perc = 0;
for(i=0;i<BINS;i++)
{
histo_perc += histogram[i];
if(histo_perc > 90) break;
}
// i is the grey level bin of the 90th percentile
// The actual grey level is then
result = i*256/BINS;
Graham

