Laplacian sharpening filter in frequency domain

8 visualizzazioni (ultimi 30 giorni)
Ali
Ali il 27 Giu 2024
Risposto: Hassaan il 27 Giu 2024

Hello everybody, I have written a code to do sharpening in frequency domain with Laplacian filter. The point is theLaplacian must be be between-1,1. Therefore it was divided to its max. I don’t know why it doesn’t work. I was wondering if anyone has any experience how to fix this problem? clear close all clc

a=imread('moon.tif'); a=im2double(a);

subplot(2,3,1); imshow(a); title('Input image');

[m,n]=size(a); A=fft2(a); subplot(2,3,2); imshow(uint8(abs(A))); title('F.T. of i/p without shift');

A_shift=fftshift(A); A_real=abs(A_shift); subplot(2,3,3); imshow(uint8(A_real)); title('F.T. of i/p after shift');

A_high=zeros(m,n); D=zeros(m,n);

for u=1:m for v=1:n H(u,v)=-4*(pi^2)*((u-(m./2))^2+(v-(n./2))^2);

    end
end

% Get maximum value of Laplacian max_val = max(abs(H),[],'all');

% Normalize Laplacian to range [-1,1] H_normalized = H / max_val;

% Compute inverse Fourier transform Laplacian_inverse = ifft2((H_normalized.*A_shift));

% Get real part of Laplacian inverse Laplacian_real = abs(Laplacian_inverse);

subplot(2,3,4); imshow(H); title('Laplacian filter');

subplot(2,3,5); mesh(H) title('Surface plot BHPF');

subplot(2,3,6); imshow(uint8(Laplacian_real)); title('Laplacian HP filtered image');

Risposte (1)

Hassaan
Hassaan il 27 Giu 2024
clear; close all; clc;
% Read and convert the image
a = imread('moon.tif');
a = im2double(a);
% Display the input image
subplot(2,3,1); imshow(a); title('Input image');
% Perform Fourier Transform
A = fft2(a);
subplot(2,3,2); imshow(log(1 + abs(A)), []); colormap gray; title('F.T. of i/p without shift');
A_shift = fftshift(A);
subplot(2,3,3); imshow(log(1 + abs(A_shift)), []); colormap gray; title('F.T. of i/p after shift');
% Get the size of the image
[m, n] = size(a);
% Initialize the Laplacian filter in the frequency domain
H = zeros(m, n);
for u = 1:m
for v = 1:n
H(u,v) = -4 * (pi^2) * (((u - (m/2))^2) + ((v - (n/2))^2));
end
end
% Normalize the Laplacian filter to range [-1, 1]
max_val = max(abs(H), [], 'all');
H_normalized = H / max_val;
% Apply the Laplacian filter in the frequency domain
Laplacian_filtered = H_normalized .* A_shift;
% Perform inverse Fourier Transform
Laplacian_inverse = ifft2(ifftshift(Laplacian_filtered));
% Get the real part of the inverse Fourier transform
Laplacian_real = real(Laplacian_inverse);
% Normalize the filtered image to the range [0, 1] for better visualization
Laplacian_real_norm = mat2gray(Laplacian_real);
% Display the Laplacian filter
subplot(2,3,4); imshow(H_normalized, []); title('Laplacian filter');
% Surface plot of the Laplacian filter
subplot(2,3,5); mesh(H_normalized); title('Surface plot of Laplacian filter');
% Display the Laplacian filtered image
subplot(2,3,6); imshow(Laplacian_real_norm); title('Laplacian HP filtered image');

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by