szymcio10

Filtr uśredniający

May 8th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.77 KB | None | 0 0
  1. close all;
  2. clear all;
  3.  
  4. A1 = imread('plansza.tif');
  5. H = fspecial('average',3);
  6. H5 = fspecial('average',5);
  7. H9 = fspecial('average',9);
  8. H15 = fspecial('average',15);
  9. H35 = fspecial('average',35);
  10.  
  11. A1s = uint8(conv2(A1,H,'same'));
  12. A1s1 = uint8(conv2(A1,H5,'same'));
  13. A1s2 = uint8(conv2(A1,H9,'same'));
  14. A1s3 = uint8(conv2(A1,H15,'same'));
  15. A1s4 = uint8(conv2(A1,H35,'same'));
  16. A1d = imabsdiff(A1,A1s);
  17. A1d1 = imabsdiff(A1,A1s1);
  18. A1d2 = imabsdiff(A1,A1s2);
  19. A1d3 = imabsdiff(A1,A1s3);
  20. A1d4 = imabsdiff(A1,A1s4);
  21.  
  22. figure(1)
  23.  
  24. subplot(1,3,1)
  25. imshow(A1);
  26. title("obraz startowy")
  27.  
  28. subplot(1,3,2);
  29. imshow(A1s);
  30. title("obraz po filtracji")
  31.  
  32. subplot(1,3,3);
  33. imshow(A1d);
  34. title("obraz po różnicy")
  35.  
  36. figure(2)
  37.  
  38. subplot(1,3,1)
  39. imshow(A1);
  40. title("obraz startowy")
  41.  
  42. subplot(1,3,2);
  43. imshow(A1s1);
  44. title("obraz po filtracji")
  45.  
  46. subplot(1,3,3);
  47. imshow(A1d1);
  48. title("obraz po różnicy")
  49.  
  50. figure(3)
  51.  
  52. subplot(1,3,1)
  53. imshow(A1);
  54. title("obraz startowy")
  55.  
  56. subplot(1,3,2);
  57. imshow(A1s2);
  58. title("obraz po filtracji")
  59.  
  60. subplot(1,3,3);
  61. imshow(A1d2);
  62. title("obraz po różnicy")
  63.  
  64. figure(4)
  65.  
  66. subplot(1,3,1)
  67. imshow(A1);
  68. title("obraz startowy")
  69.  
  70. subplot(1,3,2);
  71. imshow(A1s3);
  72. title("obraz po filtracji")
  73.  
  74. subplot(1,3,3);
  75. imshow(A1d3);
  76. title("obraz po różnicy")
  77.  
  78. figure(5)
  79.  
  80. subplot(1,3,1)
  81. imshow(A1);
  82. title("obraz startowy")
  83.  
  84. subplot(1,3,2);
  85. imshow(A1s4);
  86. title("obraz po filtracji")
  87.  
  88. subplot(1,3,3);
  89. imshow(A1d4);
  90. title("obraz po różnicy")
  91.  
  92. %filtracja dolno przepustowa poprawia obraz wygładza jego krawędzie
  93.  
  94. A2 = imread('lena.bmp');
  95. M = [1 2 1; 2 4 2; 1 2 1];
  96. M = M/sum(sum(M));
  97.  
  98. A2s = uint8(conv2(A2,M,'same'));
  99.  
  100. figure(6)
  101. subplot(1,2,1)
  102. imshow(A2)
  103. title("obraz startowy")
  104.  
  105. subplot(1,2,2)
  106. imshow(A2s);
  107. title("po filtracji")
Advertisement
Add Comment
Please, Sign In to add comment