How to convert an ideal filter to a non-ideal filter?

1 次查看(过去 30 天)
Hey, everyone! My goal on this code is making non ideal filter with doing convolution of the notch filter and average filter. My teacher said this method. However,I do not know how to use 'C' part (convolution) to show as 'Output of Notch Filter'. (I know it will not be notch filter anymore after convolution but don't mind the name of the output). Please help me, this is for lab report and so important. I've tried to replace filt to C in 'imshow(log(1+abs( fftshift(I2).*filt)),[]);' part but I've got a error, can you fix this problem? Thanks for your attention.
Image is attached.
I = imread('woman-1_3.bmp');
I2=fft2(I);
imshow(log(1+abs(fftshift(I2))),[]);
%Notch Filter (Ideal Filter)
filt=ones(200);
filt(87:1:91,87:1:91)=0;
filt(112:1:116,87:1:91)=0;
filt(113:1:115,111:1:113)=0;
filt(87:1:91,111:1:113)=0;
imshow(filt);
% Making non-ideal filter using convolution
filter_av = ones(3,3)/9;
C = conv2(filter_av,filt,'same');
imshow(log(1+abs( fftshift(I2).*filt)),[]);
subplot(121),imshow(I),title('Noisy Image');
subplot(122),imshow(log(1+abs(ifft2( fftshift(I2).*filt))),[]),title('Output of Notch Filter');

采纳的回答

Devineni Aslesha
Devineni Aslesha 2020-2-24
In the above code, the size of C is 3*3 due to the selection of the ‘shape’ in ‘conv2’ function as ‘same’. However, selecting the ‘shape’ in ‘conv2’ function as ‘full’, gives 'C' as output with size 202*202. Please use the below code to solve the error occurred while using 'C' in imshow.
C = conv2(filter_av,filt,'full');
Also, replace 'filt' with 'C' as shown below.
imshow(log(1+abs(ifft2( fftshift(I2).*C(1:200,1:200)))),[])
  2 个评论
Ayberk Ay
Ayberk Ay 2020-2-24
thank you so much, it worked so well and it has better result than ideal filter (I wanted to see this anyways).However PNSR value between original img and noisy img is bigger than the value between original img and filtered img and it is not good at all for filtering.How can I make a better notch filter to remove periodic noises at 'woman-1_3.bmp'?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Filter Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by