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.



Similar Reads

Creating Apps Using App Designer in MATLAB
MATLAB is a powerful, high-level programming language. Matlab is widely used for designing systems by engineers and scientists and we all know that the best way to represent any idea is by using a simple but effective GUI. Matlab app builder provides you the power to build different apps, to represent your idea in a GUI-friendly manner. In this art
3 min read
Matlab | Edge Detection of an image without using in-built function
Problem Statement: Write a matlab code for edge detection of a grayscale image without using in-built function of edge detection. About Edge Detection: Edge detection is an image processing technique for finding the boundaries of objects within images. It works by detecting discontinuities in brightness. Edge detection is used for image segmentatio
3 min read
How to vertically flip an Image using MATLAB
Prerequisite: Image representation in MATLAB In MATLAB, Images are stored in matrices, in which each element of the matrix corresponds to a single discrete pixel of the image. We can flip the given image vertically (along the x-axis), if we reverse the order of the pixels (elements of the matrix) in each column as illustrated in the below image. Co
2 min read
Matlab program to rotate an image 180 degrees clockwise without using function
An image is defined as two-dimensional function, f(x, y), where x and y are spatial (plane) coordinates, and the amplitude of f at any pair of coordinates(x, y) is called the Intensity or the Gray level of the image at that point. When x, y and the intensity values of f are all finite, discrete quantities, the image is digital image. Digital image
2 min read
How To Detect Face in Image Processing Using MATLAB?
MATLAB is a programming platform that is mainly used by engineers and scientists to analyze and design systems. Image processing is a process to perform some operations on an image to get an enhanced image or to extract some useful information from it. Each picture is stored as an array and each pixel is an element of the array. Face Detection:Face
5 min read
MATLAB - Image Edge Detection using Prewitt Operator from Scratch
Prewitt Operator: It is a gradient-based operator. It is one of the best ways to detect the orientation and magnitude of an image. It computes the gradient approximation of image intensity function for image edge detection. At the pixels of an image, the Prewitt operator produces either the normal to a vector or the corresponding gradient vector. I
3 min read
MATLAB - Image Edge Detection using Sobel Operator from Scratch
Sobel Operator: It is a discrete differentiation gradient-based operator. It computes the gradient approximation of image intensity function for image edge detection. At the pixels of an image, the Sobel operator produces either the normal to a vector or the corresponding gradient vector. It uses two 3 x 3 kernels or masks which are convolved with
3 min read
MATLAB - Image Edge Detection using Robert Operator from Scratch
Robert Operator: This gradient-based operator computes the sum of squares of the differences between diagonally adjacent pixels in an image through discrete differentiation. Then the gradient approximation is made. It uses the following 2 x 2 kernels or masks – [Tex]\[M_{x}=\left[\begin{array}{ccc}1 &amp; 0 \\ 0 &amp; -1\end{array}\right] \quad M_{
2 min read
Arithmetic Encoding and Decoding Using MATLAB
Arithmetic coding is a type of entropy encoding utilized in lossless data compression. Ordinarily, a string of characters, for example, the words "hey" is represented for utilizing a fixed number of bits per character. In the most straightforward case, the probability of every symbol occurring is equivalent. For instance, think about a set of three
6 min read
Edge detection using in-built function in MATLAB
Edge detection: In an image, an edge is a curve that follows a path of rapid change in intensity of that image. Edges are often associated with the boundaries of the object in a scene environment. Edge detection is used to identify the edges in an image to make image processing easy. Edge detection works by detecting discontinuities in brightness.
2 min read
Article Tags :