how image sharpening is perform in matlab?
Show older comments
please suggest.
% Filter 1
kernel3 = [-1 -1 -1; -1 8 -1; -1 -1 -1]/3;
% Filter the image. Need to cast to single so it can be floating point
% which allows the image to have negative values.
filteredImage = imfilter(single(im), kernel3);
filteredImage =im2double(filteredImage);
filteredImage =1.5 .*filteredImage;
figure(),imshow(filteredImage);
out1=imadd(im,filteredImage);
figure(), imshow(out1);
Z = imabsdiff(im,out1);
% figure(),
imtool(Z);
Answers (1)
Jaimin
on 17 Sep 2024
There are three methods to perform image sharpening which are as follows:
Using a Sharpening Kernel : This method enhances edges by using a high-pass filter. Refer to the following code snippet to learn more about implementing high-pass filter.
% Read the image
im = imread('example.jpg');
% Convert the image to grayscale if it's not already
if size(im, 3) == 3
im = rgb2gray(im);
end
% Define a Laplacian kernel for sharpening
sharpeningKernel = [-1 -1 -1; -1 8 -1; -1 -1 -1];
% Apply the filter using imfilter
sharpenedImage = imfilter(double(im), sharpeningKernel, 'replicate');
% Display the original and sharpened images
figure;
subplot(1, 2, 1), imshow(im), title('Original Image');
subplot(1, 2, 2), imshow(uint8(sharpenedImage)), title('Sharpened Image');
Using Unsharp Masking: Unsharp masking is a popular technique that enhances edges by subtracting a blurred version of the image from the original.
Refer to the following code snippet to learn more about unsharp masking.
% Read the image
im = imread('example.jpg');
% Convert the image to grayscale if it's not already
if size(im, 3) == 3
im = rgb2gray(im);
end
% Perform Gaussian blur
blurredImage = imgaussfilt(im, 2);
% Calculate the mask
mask = double(im) - double(blurredImage);
% Add the mask to the original image to get the sharpened image
sharpenedImage = double(im) + 1.5 * mask;
% Display the original and sharpened images
figure;
subplot(1, 2, 1), imshow(im), title('Original Image');
subplot(1, 2, 2), imshow(uint8(sharpenedImage)), title('Sharpened Image');
Using Built-in MATLAB Function : MATLAB provides a built-in function “imsharpen” for image sharpening.
Refer to the following code snippet to learn more about “imsharpen” function.
% Read the image
im = imread('example.jpg');
% Sharpen the image using imsharpen
sharpenedImage = imsharpen(im);
% Display the original and sharpened images
figure;
subplot(1, 2, 1), imshow(im), title('Original Image');
subplot(1, 2, 2), imshow(sharpenedImage), title('Sharpened Image');
For more information regarding “imsharpen” please follow this MathWorks Documentation.
I hope it helps.
Categories
Find more on Matched Filter and Ambiguity Function in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!