Motion blur image not working

8 views (last 30 days)
peymanTGH
peymanTGH on 25 Mar 2020
Commented: Eirik Kvernevik on 7 Mar 2021
I want to simulate motion blur kernel as in Gonzalez book.My code below works perfectly well for horizontal and vertical direction but doesn't work in diagonal direction.
Does anyone know where is the problem?
% Degrade the image to produce motion blurred images
% shown in Figures 5.26 of text book
clear; clc;
f=imread('cover.jpg');
[M N] = size(f);
%[u,v]=freqspace([M N]);
%[u,v]=meshgrid(u,v);
T=1;a=0.1;b=0.1;r=(-1)^.5;
%center=ceil(N/2);
for u=1:M
for v=1:N
s=(pi*(a*u+b*v));
H(u,v)=(T/s)*sin(s)*exp(-r*s);
end
end
F=(fft2(f));
%Degrading the original image by multiplying H by F in frequency domain.
G=F.*H;
g=abs(ifft2(G));
%Displaying results
subplot(2,2,1);imshow(mat2gray(f)); title('f: Original');
subplot(2,2,2);imshow(mat2gray(g));title('Degraded Image by motion');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Vertical Motion
for u=1:M
for v=1:N
H1(u,v)=(T/(pi*(a*u)))*sin(pi*(a*u))*exp(-r*pi*(a*u));
end
end
%Degrading the original image by multiplying H by F in frequency domain.
G1=F.*H1;
g1=abs(ifft2(G1));
%Displaying results
subplot(2,2,3);imshow(g1,[]); title('Vertical Motion');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Horizontal Motion
for u=1:M
for v=1:N
H2(u,v)=(T/(pi*(b*v)))*sin(pi*(b*v))*exp(-r*pi*(b*v));
end
end
%Degrading the original image by multiplying H by F in frequency domain.
G2=F.*H2;
g2=abs(ifft2(G2));
%Displaying results
subplot(2,2,4);imshow(g2,[]); title('Horizontal Motion');

Answers (0)

Community Treasure Hunt

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

Start Hunting!