Ask Dr. Color’s Assistant: Tone-mapping in MATLAB

How does the tonemap function in the Image Processing Toolbox product work?

Tone mapping, or tone reproduction, compresses the enormous amount of illumination data in a high dynamic range image to something more suitable for output on a medium that has a lower dynamic range. The recent discussion of my office image shows the results of tone mapping.

But what is dynamic range? And what makes a high dynamic range image?

In the simplest terms, dynamic range is the ratio of the brightest value in an image or scene and the darkest value. Consider the following table of illumination sources from High Dynamic Range Imaging by Erik Reinhard, Greg Ward, Sumanta Pattanaik, and Paul Debevic:

Condition Illumination (in cd/m2)
Starlight 10-3
Moonlight 10-1
Indoor Lighting 102
Sunlight 105

The human visual system is capable of discriminating about five orders of magnitude at most of these different illumination levels.[1] That is, if you have normal vision, you can see something with a brightness value of 1 and a value of 100,000 in the same scene. Under different conditions, you might be able to make out detail in something with a value of 0.001 at the same time that you look at an object with a brightness level of 100. What you can’t do is see detail in something with a value of 0.001 and another thing with brightness 100,000 simultaneously. That would require being able to distinguish between eight orders of magnitude at once.

An image with values that range from 1 to 100,000 has a dynamic range of 100,000:1. Most of the images made for display on contemporary monitors have a dynamic range of only 256:1 per color channel, because that’s all that most monitors are built to support. We’ll call the latter images low dynamic range (LDR) images and anything with the ability to store more illumination detail a high dynamic range (HDR) image. There’s nothing stopping us from creating HDR images, but we won’t be able to display them on a LDR device like a monitor or inkjet prints.

Tone mapping is the HDR to LDR conversion. There are many tone mapping operators that we might have implemented. (See “A review of tone reproduction techniques” (2002) by Kate Devlin for an overview of these technique.) We chose a technique that renders floating-point high dynamic range RGB radiance maps to low dynamic range RGB UINT8 images using a spatially uniform tone mapping operator similar to what Ward et al. described in their 1997 paper “A visibility matching tone reproduction operator for high dynamic range images” (IEEE Transactions on Visualization and Computer Graphics, 3(4):291-306). It differs in several ways, though.

In a nutshell, our tonemap function takes the base-2 logarithm of the RGB radiance map to mimic the human visual response to brightness, transforms the image into the L*a*b* colorspace, and performs contrast limited adaptive histogram equalization on the luminance channel without changing the overall color content of the image. After converting the modified L*a*b* image back to RGB, the result for most images is a fairly good LDR image suitable for output. We provide a couple of parameters to improve the “artistic” qualities of the rendering – AdjustSaturation and AdjustLuminance – as well as the ability to tune the histogram equalization.

While our technique doesn’t use much of what is known about how the human visual system performs tone mapping, we think we picked a method that balances good results, acceptable performance, and low complexity. My hope is that people doing work on HDR imagery will take a look at the two-dozen so important lines inside tonemap and see just how easy it is to get started implementing their own tone reproduction operator in MATLAB.

[1] – One “order of magnitude” is one power of ten. Engineering types are fond of talking about orders of magnitude.

This entry was posted in Color and Vision, Computing, Fodder for Techno-weenies, MATLAB, Photography. Bookmark the permalink.

2 Responses to Ask Dr. Color’s Assistant: Tone-mapping in MATLAB

  1. Harbinder Singh says:

    very informative.

  2. SG says:

    I have these set of images. I have extracted the radiance map. Now I need to generate the .hdr file from one of the base images and the radiance map. How do I do this in Matlab? I want to tonemap this .hdr image separately later on. can you help me out?


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>