Time for action – composing your own HDR images

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:

  1. Save the names of the three images in a cell and the respective EV choices in a matrix:
    >> filenames = {'image_-2.jpg', 'image_0.jpg', 'image_2.jpg'};
    >> expValues = [-2, 0, 2];
  2. In order to get an idea of what these images look like, we can optionally load them and display them:
    >> 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')
    Time for action – composing your own HDR images
  3. Now, we will use the two variables created in step 1 to make our HDR image:
    >> hdr = makehdr(filenames,  'ExposureValues', expValues);
  4. The HDR image now needs some postprocessing to be ready for viewing purposes. This can be done using tonemap with its default values, which will result in converting the HDR result to a lower dynamic range RGB image:
    >> rgb = tonemap(hdr);
  5. The result is clearly more detailed, but it includes some grain noise and also some small blocking effect in smooth areas (such as the desk surface) due to the JPEG compression and the limited bit depth:
    >> rgb = tonemap(hdr);
    Time for action – composing your own HDR images
  6. The grain noise mentioned previously, can be reduced using a median filter. A 7x7 median filter will suffice, without causing great degradation of the quality of the image. For color images, we must use the filter separately in each channel. Combining this filter with contrast adjustment, leads to:
    >> 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')
    Time for action – composing your own HDR images

What just happened?

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.

Tip

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:

http://captainkimo.com/single-exposure-hdr/

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset