Facebook
From Speedy Prairie Dog, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 142
  1. close all;
  2. clear all;
  3. ertka = imread("ertka.bmp");
  4. se1 = strel('square', 3);
  5. se2 = strel('line',10, 45);
  6. se3 = strel('diamond',3);
  7. ertkaErozja1 = imerode(ertka,se1);
  8. ertkaErozja11 = imerode(ertkaErozja1,se1);
  9. ertkaErozja111 = imerode(ertkaErozja11,se1);
  10. ertkaErozja2 = imerode(ertka,se2);
  11. ertkaErozja3 = imerode(ertka,se3);
  12. figure(1);
  13. subplot(1,4,1);
  14. imshow(ertka);
  15. title("obraz oryginalny");
  16. subplot(1,4,2);
  17. imshow(ertkaErozja1);
  18. title("obraz po erozji kwadrat 3x3");
  19.  
  20. subplot(1,4,3);
  21. imshow(ertkaErozja2);
  22. title("obraz po erozji linia 10, kąt 45");
  23. subplot(1,4,4);
  24. imshow(ertkaErozja3);
  25. title("obraz po erozji diament 3");
  26. figure(2);
  27. subplot(1,3,1);
  28. imshow(ertkaErozja1);
  29. title("obraz po jednej erozji kwadrat 3x3");
  30. subplot(1,3,2);
  31. imshow(ertkaErozja11);
  32. title("obraz po dwóch erozji");
  33. subplot(1,3,3);
  34. imshow(ertkaErozja111);
  35. title("obraz po trzech erozjach");
  36.  
  37. sebuska = [0 0 0;0 1 1; 0 0 0];
  38. buska = imread("buska.bmp");
  39. figure(3);
  40. subplot(1,2,1);
  41. imshow(buska)
  42. title("obraz oryginalny")
  43. buskaErozja = imerode(buska,sebuska);
  44. subplot(1,2,2);
  45. imshow(buskaErozja)
  46. title("obraz po erozji")
  47.  
  48. figure(4);
  49. ertkaDylatacja = imdilate(ertka,se1);
  50. imshow(ertkaDylatacja);
  51.  
  52.  
  53. ertkaOpen = imopen(ertka,se1);
  54. ertkaClose = imclose(ertka,se1);
  55. imshow(ertkaDylatacja);
  56.  
  57. figure(5);
  58. subplot(3,2,1);
  59. imshow(ertka);
  60. title("obraz oryginalny")
  61.  
  62. subplot(3,2,2);
  63. imshow(ertkaErozja1);
  64. title("Erozja")
  65.  
  66. subplot(3,2,3);
  67. imshow(ertkaDylatacja);
  68. title("Dylatacja")
  69.  
  70.  
  71. subplot(3,2,4);
  72. imshow(ertkaOpen);
  73. title("Open")
  74.  
  75. subplot(3,2,5);
  76. imshow(ertkaClose);
  77. title("close")
  78.  
  79.  
  80. subplot(3,2,6);
  81. imshow(imclose(ertkaOpen,se1));
  82. title("open a potem close")
  83.  
  84. hom = imread("hom.bmp");
  85.  
  86. figure(6);
  87. subplot(2,1,1);
  88. imshow(hom);
  89. subplot(2,1,2);
  90. SE11= [ 0 1 0; 1 1 1; 0 1 0];
  91. SE22= [ 1 0 1; 0 0 0; 1 0 1];
  92. homBWHitMiss = bwhitmiss(hom,SE11,SE22);
  93. imshow(homBWHitMiss);
  94.  
  95. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  96.  
  97. close all; clear all;
  98. fingerprint = imread("fingerprint.bmp");
  99. figure(1);
  100. FPthin1 = bwmorph(fingerprint,'thin');
  101. FPthin2 = bwmorph(FPthin1,'thin');
  102. FPthin3 = bwmorph(FPthin2,'thin');
  103. FPthin4 = bwmorph(FPthin3,'thin');
  104. FPthinInf = bwmorph(FPthin1,'thin',Inf);
  105. subplot(2,3,1);
  106. imshow(fingerprint);
  107. title("oryginalny")
  108. subplot(2,3,2);
  109. imshow(FPthin1);
  110. title("FPthin raz")
  111. subplot(2,3,3);
  112. imshow(FPthin2);
  113. title("FPthin 2 razy")
  114. subplot(2,3,4);
  115. imshow(FPthin3);
  116. title("FPthin 3 razy")
  117. subplot(2,3,5);
  118. imshow(FPthin4);
  119. title("FPthin 4 razy")
  120. subplot(2,3,6);
  121. imshow(FPthinInf);
  122. title("FPthin Inf")
  123.  
  124. kosc = imread("kosc.bmp");
  125. figure(2);
  126. imshow(kosc);
  127. SpookyScarySkeleton = bwmorph(kosc,'skel',Inf);
  128. figure(3);
  129. imshow(SpookyScarySkeleton)
  130. tekst = imread("text.png");
  131. SE = ones(51,1);
  132. tekstOpen = imopen(tekst,SE);
  133. figure(4);
  134. subplot(3,1,1);
  135. imshow(tekst)
  136. subplot(3,1,2);
  137. imshow(tekstOpen);
  138. subplot(3,1,3);
  139. Wynik = imreconstruct(tekstOpen,tekst);
  140. imshow(Wynik);
  141.  
  142. figure(5);
  143. WynikFill = imfill(tekst,'holes');
  144. imshow(WynikFill);
  145.  
  146. figure(6);
  147. subplot(2,1,1)
  148. imshow(tekst);
  149. subplot(2,1,2)
  150. WynikClear = imclearborder(tekst);
  151. imshow(WynikClear);
  152.  
  153. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  154.  
  155. close all;
  156. clear all;
  157. ferrari = imread("ferrari.bmp");
  158. se1 = strel('square', 3);
  159. ferrariErozja = imerode(ferrari,se1);
  160. ferrariDylatacja = imdilate(ferrari,se1);
  161. ferrariabsdiff = imabsdiff(ferrariErozja,ferrariDylatacja);
  162. subplot(2,2,1);
  163. imshow(ferrari);
  164. title("obraz oryginalny");
  165. subplot(2,2,2);
  166. imshow(ferrariErozja);
  167. title("po erozji");
  168. subplot(2,2,3);
  169. imshow(ferrariDylatacja);
  170. title("po dylatacji");
  171. subplot(2,2,4);
  172. imshow(ferrariabsdiff);
  173. title("różnica");
  174. figure(2);
  175. subplot(2,1,1);
  176. ferrariopen = imopen(ferrari,se1);
  177. imshow(ferrariopen);
  178. title("imopen");
  179. subplot(2,1,2);
  180. ferrariclose = imclose(ferrari,se1);
  181. imshow(ferrariclose);
  182. title("imclose");
  183.  
  184. ferraritophat = imtophat(ferrari,se1);
  185. ferraribothat = imbothat(ferrari,se1);
  186.  
  187. figure(3);
  188. imshow(ferraritophat);
  189. title('top-hat');
  190. %%Operacja Top-Hat wydobywa małe elementy z obrazów czy też naprawia oświetlenie
  191. %%Wykonuje imopen a następnie odejmuje obraz oryginalny od wyniku.
  192. %%Bottom hat, to samo tylko z funkcja imclose. Poprawia kontrast.
  193. figure(4);
  194. imshow(ferraribothat);
  195. title('bottom-hat');
  196. se2 = strel('disk', 10);
  197. rice = imread("rice.png");
  198. figure(5);
  199. subplot(2,1,1);
  200. imshow(rice);
  201. riceTopHat = imtophat(rice,se2);
  202. subplot(2,1,2);
  203. imshow(riceTopHat);
  204. %oświetlenie stało się jednorodne
  205.  
  206. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  207.  
  208. clear all;
  209. close all;
  210. calc = imread("calculator.png");
  211. figure(1);
  212. imshow(calc);
  213. ce1 = ones(1,71);
  214. calcErozja = imerode(calc,ce1);
  215. calcReconst = imreconstruct(calcErozja,calc);
  216. figure(2);
  217. subplot(1,2,1);
  218. imshow(calcReconst);
  219. title("otwarcie przez rekonstreukcje");
  220. subplot(1,2,2);
  221. calcopen = imopen(calc,ce1);
  222. imshow(calcopen);
  223. title("otwarcie klasyczne");
  224. %otwarcie przez rekonstrukcje zwraca nam całe kształty, nie same kreski.
  225. figure(3);
  226. wynikimabsdiff = imabsdiff(calc,calcReconst);
  227. imshow(wynikimabsdiff);
  228. figure(4);
  229. tophat = imtophat(calc,ce1);
  230. imshow(tophat);
  231. ce2 = ones(1,11);
  232. calcErozja2 = imerode(wynikimabsdiff,ce2);
  233. calcReconst2 = imreconstruct(calcErozja2,wynikimabsdiff);
  234. figure(5);
  235. imshow(calcReconst2);
  236. dylatacja = imdilate(calcReconst2,ones(1,21));
  237. wynikkoncowy = imreconstruct(min(dylatacja,wynikimabsdiff),wynikimabsdiff);
  238. figure(6);
  239. imshow(wynikkoncowy);
  240. figure(7);
  241. wynikkoncowy2 = im2bw(wynikkoncowy,0.30);
  242. wynikkoncowy2 = medfilt2(wynikkoncowy2,[4 4]);
  243. imshow(wynikkoncowy2);
  244. title("bonus")
  245. %udało się uzyskać ekstrakcje pożądanych napisów.