how image sharpening is perform in matlab?

조회 수: 11 (최근 30일)
Durgesh Naik
Durgesh Naik 2016년 4월 12일
답변: Jaimin 2024년 9월 17일
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);

답변 (1개)

Jaimin
Jaimin 2024년 9월 17일
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.

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by