Sem 7‎ > ‎Digital Image Processing‎ > ‎

WAP to show filtered image after passing through ideal low pass filter

posted Oct 30, 2013, 4:49 PM by Neil Mathew
a=imread('C:\Users\Desktop\lena2.png');

b=double(a);

[m n]=size(a);

d0=input('enter the cut off frequency');

for u=1:1:m
    for v=1:1:n
        d=((u-m/2)^2+(v-n/2)^2)^0.5;
  
      if(d<d0)
            H(u,v)=1;
        else
            H(u,v)=0;

        end
    end
end

fouriertrans=fft2(b,size(H,1),size(H,2));

shiftedfouriertrans=fftshift(fouriertrans);

x=shiftedfouriertrans.*H;

X=abs(ifft2(x));

filtered_image=uint8(X);

filtered_image = filtered_image(1:size(a, 1), 1:size(a, 2));
subplot(2,2,1);
imshow(a);

title('original image');
subplot(2,2,2);
imshow(filtered_image);
title('Filtered Image'); 

subplot(2,2,3);
imshow(H);
title('Ideal low pass filter');

subplot(2,2,4);
mesh(H),colormap(gray);
title 'Ideal low pass frequency response';


Comments