DIP EXP -9 [ IMAGE RESTORATION ]

 close all;

clear all;
clc;
% Read the input image and convert it to grayscale
x = imread('sample.jpg');
x = double(rgb2gray(x));
% Get the size of the input image
[M, N] = size(x);
% Define a blur filter (a 11x11 averaging filter)
h = ones(11, 11) / 121;
% Calculate the standard deviation for the Wiener filter
sigma = sqrt(4 * 10^(.7));
% Perform FFT (Fast Fourier Transform) on the input image and the blur filter
freqx = fft2(x, M, N);
freqh = fft2(h, M, N);
% Convolve the input image with the blur filter in the frequency domain
y = real(ifft2(freqh .* freqx));
% Calculate the FFT of the degraded image
freqy = fft2(y);
% Calculate the power spectrum of the input image
powfreqx = freqx.^2 / (M * N);
% Define the Wiener filter transfer function
alpha = 0.5;
fregg = (freqh .* abs(powfreqx)) ./ (abs(freqh.^2) .* abs(powfreqx) + alpha * sigma^2);
% Apply the Wiener filter in the frequency domain
Resfreqx = fregg .* freqy;
% Perform inverse FFT to obtain the restored image
Resa = real(ifft2(Resfreqx));
% Display the original image, degraded image, and restored image using subplot
subplot(1,3,1);
imshow(uint8(x)), title('Original Image');
subplot(1,3,2);
imshow(uint8(y)), title('Degraded Image');
subplot(1,3,3);
imshow(uint8(Resa)), title('Restored Image');
Previous Post
No Comment
Add Comment
comment url