In this project I detail the process of preparing and tonemapping a HDR image for viewing via Matlab.
Opening HDR Images in Matlab
The command to open HDR files on Matlab is
hdrread(). What you will receive is a [x,y,3] matrix for an image of (x,y) resolution. The three matrices in depth hold the RGB information separately. Since we will have to reuse the information, it’s best that the image file is stored in a handle like such:
IMG = hdread('img.hdr');
Since tonemapping is applied on luminance, it would make sense to extract the luminance of our image. To do that we will use the relative luminance equation.
lum = 0.213*IMG(:,:,1)+0.715*IMG(:,:,2)+0.072*IMG(:,:,3);
x = log10(lum)
Very important here that
log10 is used instead of
log, as the latter computes the natural log that will give you problems.
Performing Histogram Equalization
The problem of performing histogram equalization on Matlab is that the native image equalization function on Matlab will not work, thus the range of luminace that are dealt with are different. Thus it was necessary to perform manual histogram equalization.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 x = x(:)-min(x(:)); [n,edge]=histcounts(x,index1); nk = [0 n]; rk = edge/(max(edge)-min(edge))*index0; %bins pr = nk/sum(nk); %density cdf = cumsum(pr)/sum(pr); s = round(max(rk)*cdf,0); fin = zeros(size(rk)); %equalized histogram luminance values for i = 1:index0 fin(s(i)+1) = fin(s(i)+1)+pr(i); end fincdf = cumsum(fin)/sum(fin); new_lum = zeros(1080,1920); lum_index = round(lum,0)+1; for i = 1:1080 for y = 1:1920 new_lum(i,y) = fincdf(lum_index(i,y)); end end
• Wmax = max log luminance value
• Wmin = min log luminance value
• Lum = log luminance value scaled between [1,250] so can be used as index
• nk = density
• rk = bins
• pr = percentage density
• cdf = cumulative sum of percentage density of old histogram
• s = converting bins to index values
• fin = final equalized histogram
Applying Linear Ceiling
The next step is to apply a ceiling. The original purpose of this project was to examine the difference between linear ceilings and perceptual ceilings. First this is my approach to a linear ceiling:
Below is my approach to achieving a perceptual ceiling based on Larson et al. (2011)
Here, the pbw max and min values are the target display range in log10 scale with 252 levels corresponding to the number of bins I used. And the look up table used in the code is:
Conversion back into luminance Space and Normalization
Now that the image has been modified, the image needs to be processed for display. To do so, each pixel is interpolated using the histogram modified in the previous section, then together as a matrix converted out of log space and normalized.
Replacing Old Luminance Values
Clipping and Gamma Correction
Hopefully when I have more time, I can upload pictures of better quality including the histogram changes through the process as well
Project from assignment of partial fulfillment of EECE 421, December 2016.