image restoration matlab code

Illustration
aziz alfares - 2022-12-30T12:04:54+00:00
Question: image restoration matlab code

hello i am trying to implement this code to get the result in figure 5.26(b) but still something wrong could you help me in that  Refernce: digital image processing gonzalez third edition c = im2double(imread('Fig0526(a)(original_DIP).tif')); figure,imshow(c) a = 0.1; b = 0.1; T=1; [M, N] = size(c); h = zeros(M,N); for u = 1:M for v = 1:N h(u,v) = (T/(pi*(u*a + v*b)))*... sin(pi*(u*a + v*b))*... exp(-1i*pi*(u*a + v*b)); end end cf=(fft2(c)); c1 = cf.*h; c1a=(ifft2(c1)); figure,imshow(abs(log(c1a)+1), []);  

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

The origin was not at the right place. Try this:

 

clc;    % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all;  % Close all figures (except those of imtool.)
clear;  % Erase all existing variables. Or clearvars if you want.
workspace;  % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
grayImage = im2double(imread('logo.tif'));
% Make sure it's 688 like the book says.
grayImage = imresize(grayImage, [688, 688]);
subplot(2, 3, 1);
imshow(grayImage, [])
impixelinfo
axis('on', 'image')
title('Original Image', 'FontSize', fontSize)
% Make a filter for the spectral domain.
a = 0.1;
b = a;
T=1;
[rows, columns] = size(grayImage);
h = zeros(rows, columns);
for u = 1 : rows
    for v = 1 : columns
        rx = v - columns/2;
        ry = u - rows/2;
        h(u,v) = (T/(pi*(ry*a + rx*b))) *...
            sin(pi*(ry*a + rx*b))*...
            exp(-1i*pi*(ry*a + rx*b));
    end
end
% Print the max value of h.
absh = real(h);
fprintf('Max h = %f.\n', max(absh(:)))
subplot(2, 3, 2);
imshow(log(absh), []);
impixelinfo;
axis('on', 'image')
title('h Frequency Domain Filter', 'FontSize', fontSize)
% Compute fft of the image.
fftOrig = fftshift(fft2(grayImage));
subplot(2, 3, 3);
imshow(log(abs(fftOrig)), []);
impixelinfo;
axis('on', 'image')
title('FFT of original image', 'FontSize', fontSize)
% Multiply it by the filter.  fftOrig and h have DC position at center of image.
c1 = fftOrig .* h;
% There are some nan's which mess up the inverse transform.  Set nan's to zero.
rc = real(c1);
ic = imag(c1);
rc(isnan(rc)) = 0;
ic(isnan(ic)) = 0;
c1 = rc + 1i * ic;
subplot(2, 3, 4);
imshow(abs(log(c1)+1), []);
title('Filtered Spectrum', 'FontSize', fontSize)
% Inverse transform from frequency domain back to space domain.
% After multiplication, shift back.
c1Spatial = ifft2(ifftshift(c1));
subplot(2, 3, 5);
imshow(real(c1Spatial), []);
title('Filtered Image', 'FontSize', fontSize)
g = gcf;
g.WindowState = 'maximized'

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!