Now that we know the theory, let's dive into a real life example. For the purposes of this exercise, we shot three pictures of a scene with a wide range of brightness, in an office, using three different EV settings: -2, 0, and 2. The names of the three images are image_-2.jpg
, image_0.jpg
, and image_2.jpg
. So, in order to use them to make an HDR image, we will follow the steps as shown:
>> filenames = {'image_-2.jpg', 'image_0.jpg', 'image_2.jpg'}; >> expValues = [-2, 0, 2];
>> im1 = imread('image_-2.jpg'), >> im2 = imread('image_0.jpg'), >> im3 = imread('image_2.jpg'), >> subplot(1,3,1),imshow(im1),title('EV: -2') >> subplot(1,3,2),imshow(im2),title('EV: 0') >> subplot(1,3,3),imshow(im3),title('EV: 2')
>> hdr = makehdr(filenames, 'ExposureValues', expValues);
tonemap
with its default values, which will result in converting the HDR result to a lower dynamic range RGB image:>> rgb = tonemap(hdr);
>> rgb = tonemap(hdr);
>> for i=1:size(rgb,3) filtered(:,:,i) = medfilt2(imadjust(rgb(:,:,i)),[7 7]); end >> subplot(1,2,1),imshow(im2);title('Original image at 0EV') >> subplot(1,2,2),imshow(filtered);title('Final HDR result')
This was a basic example of how to shoot and process an HDR image in MATLAB. The use of JPEG images may not particularly help in getting the full idea of what HDR images can offer, but you have certainly acquired the basic knowledge on how to create them. Our process comprised the declaration of the names of our images and the respective exposure values, followed by a call of the function makehdr
. Then, the High Dynamic Range is converted to RGB using tonemap
and if we want, we perform some further preprocessing steps to acquire our final result.
When we want to create HDR images from action scenes, the process described previously is usually problematic, because of the subject's movement. In these situations, we can use cameras that capture raw images of higher color depth (12, or even 16 bit) and artificially create our three different exposures from a single shot, using techniques similar to the ones presented here: