Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. clear;
  2. close all;
  3. P = peaks(20);
  4. X = repmat(P,[5 10]);
  5. subplot(3,1,1); imshow(X);
  6. title('Default image');
  7.  
  8. F=fft2(X);
  9. S=abs(F);
  10. subplot(3,1,2); imshow(S, []);
  11. title('Fourier spectrum');
  12.  
  13. Fc=fftshift(F);
  14. subplot(3,1,3);imshow(abs(Fc), [])
  15. title('Fourier spectrum shifted to center');
  16.  
  17. figure()
  18. w=fspecial('sobel');
  19. freqz2(w', [200 100]);
  20. title('Sobel filter');
  21. H = freqz2(w', [200 100]);
  22.  
  23. figure()
  24. L = imfilter(X, w);
  25. subplot(3,1,1); imshow(L);
  26. title('Spatial filtering');
  27.  
  28. G1 = F*H;
  29. g1 = real(ifft2(G1));
  30. gc1 = g1(1 : 20, 1 : 20);
  31. gs1 = imfilter(X, gc1);
  32. subplot(3,2,3); imshow(gs1);
  33. title('Frequency filtering');
  34. subplot(3,2,4); imshow (abs(gs1) >0.2*abs(max(gs1(:))), [ ]);
  35. title('Frequency filtering adjusted');
  36.  
  37. G2 = Fc*H;
  38. g2 = real(ifft2(G2));
  39. gc2 = g2(1 : 10, 1 : 10);
  40. gs2 = imfilter(X, gc2);
  41. subplot(3,2,5); imshow(gs2);
  42. title('Frequency filtering centred');
  43. subplot(3,2,6); imshow (abs(gs2) >0.2*abs(max(gs2(:))), [ ]);
  44. title('Frequency filtering centred adjusted');
  45.  
  46. dif1 = norm(X-L)
  47. dif2 = norm(X-gs1)
  48. dif3 = norm(X-gs2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement