Understanding the Digital Unsharp Mask
By: Dale Cotton (glib tongue)
and Brian D. Buck (penetrating insight)
Fuzzy Concepts of Sharp Pictures
Apparently, I have not been alone in feeling that the digital implementation of Unsharp Mask (USM) was one of the great mysteries of the universe. The USM dialogue has three sliders — Amount, Radius, Threshold. They all have an effect, but finding an optimal setting seemed a hit and miss process because one never knew quite what the sliders were actually doing. The mystery became even more acute when Michael Reichmann posted a tutorial on using USM to achieve Local Contrast Enhancement. Finally, a discussion about this on the Luminous Landscape forum caused Brian D. Buck to shatter the Graphics Programmers' unwritten vow of silence by revealing the Arcane Secret of the Digital Unsharp Mask. You can read Brian's succinct statement here; the verbose version follows.
Fig 1. A picture before applying USM
Sharpening is about restoring acutance that has been lost previously along the image capture chain of events. acutance is Photography 101 speak for how precisely the edges of things are defined. Fuzzy edges cause us to rub our eyes, wondering if we need new glasses, so high acutance tends to be one of the holy grails of photography. (See also Understanding Sharpness for more information.)
Fig 2. Same picture after applying USM
But if the edges have been blurred during digitization, how can the lost detail that defined the edges be recovered? One option would be to re-assemble the team of PhDs that corrected the Hubble Space Telescopes optics by means of a computer program. Lacking that, we resort to the old law that two wrongs make a right. We throw away even more information in the hopes that what is left gives the illusion of the original acutance
Gaining an Edge
Fig 3. Zooming in on Fig 1 (100% magnification)
The principle behind unsharp masking is exaggerating the light-dark contrast between the two sides of an edge. By way of example, consider the boundaries between the leaves and the pale green background in Fig 3. Looking at these edges at high magnification what we see is like looking at the original scene through a screen door — crucial transitions are missing. One wants to take a piece of masking tape, lay it down along one's best guess where an edge should be, then colour everything on one side scarlet or dark green and everything on the other side pea soup green.
That's what USM tries to do; the crux is where to put the masking tape? The edges where the leaves are dark are fairly clear-cut. Where the leaves are backlit and very nearly identical in colour to the background, however, the decision as to whether any given pixel belongs to a leaf or to the background becomes anything but clear-cut.
USM is an algorithm that goes through the entire picture one pixel at a time, asking this question: shall I leave the brightness of this pixel unchanged or shall I change it? To make that decision it has to decide whether the pixel is part of an edge or not. Tough going for a human, let alone for a computer. But whoever created the first digital USM lifted a page from the wet darkroom. To create an unsharp mask in a wet darkroom one creates a blurred negative of the original, then overlays the two, then creates a final print from that.
Fig 4. Gaussian blur applied to Fig 3.
Digital USM works the same way behind the scenes. When you set the sliders where you want them then click OK, the USM code creates an unseen duplicate of your image file in RAM, applies Gaussian blur to that duplicate (Fig 4), then compares the blurred copy with the original. In this case, compare means to examine the brightness value of the same pixel in both copies and subtract one number from the other. Fig 5 shows this graphically. The lighter a location is in Fig 5 the greater the difference between the original and the blurred copy at that location.
Fig 5. Previous two images overlaid and mode set to Difference
The bigger the resulting number, the closer that pixel is to an edge. (Actually, USM processes each colour channel separately, but you didn't need to know that.)
A Light Begins to Dawn
But once USM has decided where an edge is, how does it actually "sharpen" it? One of the strongest cues the human optic system uses to decide where one object ends and the next begins is an abrupt change from dark to light. Most objects, being three dimensional, have shadowing along at least one edge. So, like certain religious orthodoxies, USM loves to draw the line between darkness and light. As you increase the Amount parameter by moving the slider to the right, dark areas get darker and light areas get lighter, eventually leading to sanctifying the good pixels (light-hued) with haloes of white, and damning the bad pixels (dark-hued) to the oblivion of pure blackness. Fig. 6 shows USM taken to extremes:
Fig 6. Exaggerated USM - Amount: 500, Radius: 20, Threshold 50
Knowledge is Power
The Radius slider does exactly the same thing in USM as it does in Gaussian Blur — it controls how much blurring is used in the edge-finding stage. The practical effect of this is to specify how large a region is darkened or lightened.
Finally, the Threshold slider tells the USM code how big a difference between a pixel in the blurred copy and the original copy is needed before any darkening or lightening will be applied. Open any picture file in Photoshop, launch the Unsharp Mask dialogue, make sure Preview is checked, then play with each slider to watch this process in action.
Fig 7. Reasonable USM - Amount: 130, Radius: 1.5, Threshold 6
All of which not only explains the mystery of USM, it also puts Local Contrast Enhancement into pretty sharp focus. LCE uses a large blurring Radius. This effectively cancels out the edge-finding aspect of USM. The small Amount value used in LCE applies only a gentle amount of dark/light exaggeration. The result is that contrast is boosted throughout an image without any meaningful change in perceived sharpness.