The UNSHARP_MASK function performs an unsharp-mask sharpening filter on a two-dimensional array or a TrueColor image. For TrueColor images the unsharp mask is applied to each channel.

The unsharp mask algorithm works by enhancing the contrast between neighboring pixels in an image, and is widely used for astronomical images and for digital photographs.

The algorithm involves the following steps:

  1. Smooth the original image with a Gaussian filter, with the width controlled by the RADIUS keyword.
  2. Subtract the smoothed image from the original to create a high-pass filtered image.
  3. Apply any clipping needed on the high-pass image, as controlled by the THRESHOLD keyword.
  4. Add a certain percentage of the high-pass filtered image to the original image, with the percentage controlled by the AMOUNT keyword.

In pseudocode this algorithm can be written as:

HighPass = Image - Convol ( Image, Gaussian )
Result = Image + A * HighPass * ( |HighPass| ≥ T )

where A is the amount, T is the threshold, and ≥ indicates a Boolean operation, 1 if true, or 0 otherwise.

Note: To avoid overflow for byte or integer data, the computations are performed using a larger integer type, the result is clipped to the minimum and maximum values for the original type, and the result is then converted back to the original type.

This routine is written in the IDL language. Its source code can be found in the file in the lib subdirectory of the IDL distribution.


This example sharpens an image of Mars by applying an unsharp mask filter:

file = FILEPATH('marsglobe.jpg', SUBDIR=['examples','data'])
READ_JPEG, file, marsImage
; Display the original image
i = IMAGE(marsImage, LAYOUT = [2, 1, 1], DIMENSIONS = [800, 500])
; Display the unsharp-mask-filtered image
result = UNSHARP_MASK(marsImage, RADIUS=4)
i = IMAGE(result, LAYOUT = [2, 1, 2], /CURRENT)


Result = UNSHARP_MASK(Image [, AMOUNT=value] [, RADIUS=value] [, THRESHOLD=value] [, TRUE={1|2|3}] )

Return Value

The Result is an array with the same dimensions and type as Image that contains the filtered image.



The two-dimensional array or multichannel image to be filtered. If Image is a multichannel image, then the TRUE keyword may be used to indicate which dimension represents the channels.



Set this keyword to a floating-point value giving the amount (or strength) of filtering to be applied. The default is AMOUNT=1.0, which implies that 100% of the filter difference will be applied to the Image. AMOUNT may be negative, which will have the effect of blurring the image instead of sharpening.


Set this keyword to a floating-point value giving the radius in pixels of the Gaussian smoothing filter. The default is RADIUS=3. The Gaussian filter is designed to fall to 1/e (~0.367) at a distance of RADIUS/sqrt(2). The total width of the Gaussian filter is given by ceil(3 * RADIUS)/2 * 2 + 1 (if RADIUS is an integer then this is just 3 * RADIUS + 1).

Note: The value of RADIUS must be smaller than one-half of the largest array dimension.

Tip: Use small RADIUS values (such as 3) for small images or images with fine details. Use larger RADIUS values for large images with larger details.


Set this keyword to a non-negative integer (or a floating-point if Image is floating point) giving the clipping threshold. For each element, if the absolute value of the difference between the original image and the low-pass filtered array is greater than or equal to THRESHOLD then the filter is applied to that point. The default is THRESHOLD=0, which implies that every point will be filtered.

Tip: Lower values of THRESHOLD will provide greater sharpening but may cause more speckling, while higher values of THRESHOLD will exclude regions of low contrast and cause less speckling.


If Image is a three-dimensional array (a multichannel image), set this keyword to 1, 2, or 3 to indicate which dimension represents the channels. The default is 1, for pixel interleaving, (3, m, n). A value of 2 indicates line interleaving (m, 3, n), and 3 indicates band interleaving, (m, n, 3).

Version History




Changed the total width definition of Gaussian filter from:

ceil(2 * RADIUS)/2 * 2 +1 


ceil(3 * RADIUS)/2 * 2 +1

See Also