Open In App

Unsharp Masking Using MATLAB

Last Updated : 22 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Unsharp Masking or USM is a technique developed to sharpen images, using a blurer or unsharp version of the same image and then, in the common tongue, subtracting it from the original image thus, sharpening the actual image. This method was first used in darkroom photography however, it is commonly used in Digital Image Processing tools nowadays. 

In this article, we shall see how to perform unsharp masking in MATLAB with the help of some examples. 

imsharpen()

MATLAB provides the imsharpen function to sharpen an image using the unsharp masking technique. The syntax of the same is given below:

out_img = imsharpen(in_img, <Optional Parameters>)

Here, 

  1.  out_img holds the sharpened image.
  2. in_img is the input image.

There are also some optional parameters which are discussed in the later sections. Now, let us see different implementations of the imsharpen() function.

In this example, we shall perform the unsharp masking using the default parameters i.e., without any optional arguments. 

Example 1:

Matlab




% reading input image using imread function
in_img = imread("logo.jpg");
%displaying the original image with title
imshow(in_img)
title('Original Image');
%performing unsharp masking
out_img = imsharpen(in_img);
%displaying the sharpened image in a new figure simultaneously;
%with title
figure,imshow(out_img)
title('Sharpened Image');


In the above code, we read the image logo.jpg and display it for comparison. Then, the unsharp masking is done on the in_img object using the imsharpen function and it is displayed simultaneously with the original image for comparison.

Output:

 

MATLAB provides optional arguments with imsharpen function to control the behavior of image sharpening around the edges and contrasts. In this example, we shall explore the same parameters. 

  1. Radius – This parameter decides the region around the edges which is to be sharpen. The higher the radius, the wider the sharpening region around edge pixels. Default value = 1.
  2. Amount – This controls the strength of sharpening effect. The larger the value, the greater the contrast for sharpened pixels. Default Value = 0.8.
  3. Threshold – This controls the regions where sharpening is done. Its value range is [0,1]. If the value is on the lower side, it will sharpen even the smooth regions else, if the value is on the higher end, this allows the sharpening of high-contrast regions only. Default Value = 0.

Now, let us see these parameters in combined action. 

Example 2:

Matlab




% reading input image using imread function
in_img = imread("logo.jpg");
 
% displaying the original image with title
imshow(in_img)
title('Original Image');
 
% performing unsharp masking with different parameters
out_img = imsharpen(in_img,"Radius",
5.3,"Amount",5.3,"Threshold",0.23);
 
% displaying the sharpened image
% in a new figure simultaneously;
% with title
figure,imshow(out_img)
title('Sharpened Image');


We have used the same image as previous example however, we have changed the default values of the optional parameters. This edition in the imsharpen function will sharpen the pixels around edges and increase their contrast to the rest of the image. See the output below.

Output:

 

Conclusion

This article explained what is unsharp masking and how it is performed in MATLAB. The same technique is implemented in MATLAB using the imsharpen function. Then, we explained the imsharpen function with its various parameters.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads