سؤال

I have a 48-bit (16 bits per pixel) image I've loaded with FreeImage. I'm trying to generate a histogram from this image without having to convert it to a 24-bit image.

This is how I understand histograms are calculated..

for (pixel in pixels)
{
    red_histo[pixel.red]++;
}

Where pixel.red can be between 0 and 255. So there is a range from 0 to 255 on my histogram. But if there is 16 bits per pixel, it could be between 0 and 65535, which is too large to be displayed on a histogram.

Is there a standard way to calculate histograms with 48-bit (or higher) images?

هل كانت مفيدة؟

المحلول

You have to decide how many bins you need in the histogram. For eg. the Matlab histogram function takes these forms

imhist(I) imhist(I, n) imhist(X, map)

In the first case, the number of bins is by default used as 256. So, if you have 16bit input, these will be scaled down to 8 bit and split into 256 bin histogram.

In the second one, you can specify number of bins 'n'. Lets say you specify n=2 for your 16 bit data. Then, this will essentially split the histogram as [0-2^15, 2^15-2^16-1].

The third case is where you specify the map for each bin. ie you have to specify the ranges of the pixel values for each bin.

http://www.mathworks.com/help/images/ref/imhist.html

How you want to choose the number of bins depends on your requirement.

نصائح أخرى

This Stack Overflow Question May have the answer you are looking for.

I do not know if there is a "standard" way.

If this is for display purposes you can scale back the pixels to keep the range from 0-255 for instance:

double scalingFactor = 255/65535;
for (pixel in pixels)
{
    red_histo[(int)(scalingFactor * pixel.red)]++;
}

This will allow the upper range of the 16 bit pixel to come in at 255 and lower range of the 16 bit pixel to come in at 0.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top