RE: Histogram computation on HDR rendering

This topic is 2687 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Original discussion here

In ShaderX 6 article of Franceso Carucci "HDR Meets Black & White 2", author mentioned absolute_max_luminance and gave brief explanation of where to get it's numerical value. As a previous topic starter, I was confused too by that parameter, but I've found these slides and according to them absolute_max_luminance used to build bins of histogram, is a maximum luminance of the scene, that needs to be calculated BEFORE building histogram as it will define the highest histogram bin (page 20).

Hope it helps.

Triying to wrap my head over mentioned histogram equalisation approach, looks like it needs "summed area table" approach to get it working or sort of similar algorithm. Not really getting how "remapping" process works algorithmically.

Share on other sites
Quote:
 Original post by ViikOriginal discussion here In ShaderX 6 article of Franceso Carucci "HDR Meets Black & White 2", author mentioned absolute_max_luminance and gave brief explanation of where to get it's numerical value. As a previous topic starter, I was confused too by that parameter, but I've found these slides and according to them absolute_max_luminance used to build bins of histogram, is a maximum luminance of the scene, that needs to be calculated BEFORE building histogram as it will define the highest histogram bin (page 20).Hope it helps.Triying to wrap my head over mentioned histogram equalisation approach, looks like it needs "summed area table" approach to get it working or sort of similar algorithm. Not really getting how "remapping" process works algorithmically.PS: Please merge threads if possible.

Histogram equalization is actually easy, here's some code to help you understand:

        float probabilityR[256];	float probabilityG[256];	float probabilityB[256];	float sumR[256];	float sumG[256];	float sumB[256];	memset(probabilityR,0,sizeof(float)*256);	memset(probabilityG,0,sizeof(float)*256);	memset(probabilityB,0,sizeof(float)*256);	memset(sumR,0,sizeof(float)*256);	memset(sumG,0,sizeof(float)*256);	memset(sumB,0,sizeof(float)*256);	for(int i=0;i<result.height;++i)	{		for(int j=0;j<result.width;++j)		{			++probabilityR[ int(result.R[j]*255.0f) ];			++probabilityG[ int(result.G[j]*255.0f) ];			++probabilityB[ int(result.B[j]*255.0f) ];		}	}	for(int i=0;i<256;++i)	{		probabilityR /= (result.height*result.width);		probabilityG /= (result.height*result.width);		probabilityB /= (result.height*result.width);		for(int j=0;j<=i;++j)		{			sumR += probabilityR[j];			sumG += probabilityG[j];			sumB += probabilityB[j];		}		sumR *= 255.0f;		sumR = floor(sumR + 0.5f);		sumG *= 255.0f;		sumG = floor(sumG + 0.5f);		sumB *= 255.0f;		sumB = floor(sumB + 0.5f);	}	for(int i=0;i<result.height;++i)	{		for(int j=0;j<result.width;++j)		{			result.R[j] = sumR[int(result.R[j]*255.0f)] / 255.0f;			result.G[j] = sumG[int(result.G[j]*255.0f)] / 255.0f;			result.B[j] = sumB[int(result.B[j]*255.0f)] / 255.0f;		}	}

In that code, result is both the input and output. There are only 256 "gray level" values; in other words, 256 discreet values a pixel can be (on either red, green or blue channels). Do note that I am storing the pixel values in the result as real numbers in the range [0,1], so I have to convert them to the integral range [0,255] to do this algorithm. A larger range would work too. Any questions?

[Edited by - xytor on October 16, 2010 11:39:04 AM]

Share on other sites
As I understood it's a basically a summed area table but with only one dimmension. So mentioned in paper S array is the array where each element consist of sum of all previous elements of original histohram. It kind of works now.
I didn't like the tonemaping operator presented in paper itself. Anyway, calculated values of min max and average luminosities can be plugged into Reinhard's operator for example.