szymcio10

Binaryzacja - histogram

May 3rd, 2020
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.96 KB | None | 0 0
  1. A1=imread('coins.png')
  2. figure(1)
  3. subplot(2,2,1)
  4. imshow(A1)
  5. subplot(2,2,2)
  6. imhist(A1)
  7. A2=im2bw(A1,0.41)
  8. subplot(2,2,3)
  9. imshow(A2)
  10.  
  11. O1=imread('figura.tif')
  12. O2=imread('figura2.tif')
  13. O3=imread('figura3.tif')
  14. O4=imread('figura4.tif')
  15. figure(2)
  16. subplot(2,2,1)
  17. imhist(O1)
  18. subplot(2,2,2)
  19. imhist(O2)
  20. subplot(2,2,3)
  21. imhist(O3)
  22. subplot(2,2,4)
  23. imhist(O4)
  24.  
  25. %Nie da sie jedno zanczenie określić czy tak czy nie, zależy to od metody
  26. %wpyłnęlo w taki sposób że zmniejszyło wartości i rozłożyło na grupy
  27. %Tak jest możliwe wyznaczenie progu na podstawie histogramu, ale tak ja
  28. %wczesniej pisałem zależy od metody
  29. %tak, zalezy do metody
  30.  
  31. figure(3)
  32. level=graythresh(A1)
  33. level1=clusterKittler(A1)
  34. level2=entropyYen(A1)
  35. BW=im2bw(A1,level)
  36. BW1=im2bw(A1,level1/255)
  37. BW2=im2bw(A1,level2/255)
  38. BW3=im2bw(A1,0.49)
  39. %probi były obliczanie dla obrazu coins.png
  40. %moj próg 0.49
  41. %próg otrzymany metoda otshu 0.5137
  42. %próg otrzymany metoda kittlera 0.6313
  43. %próg otrzymany meyoda yeana 0.4588
  44. subplot(2,3,1)
  45. imshow(A1)
  46. title('obraz startowy')
  47. subplot(2,3,2)
  48. imhist(A1)
  49. title('histogram')
  50. subplot(2,3,3)
  51. imshow(BW)
  52. title(['prog graythresha, ',num2str(level)])
  53. subplot(2,3,4)
  54. imshow(BW1)
  55. title(['prog kittlera, ',num2str(level1/255)])
  56. subplot(2,3,5)
  57. imshow(BW2)
  58. title(['prog yena, ',num2str(level2/255)])
  59. subplot(2,3,6)
  60. imshow(BW3)
  61. title(['moj prog, ',num2str(0.49)])
  62.  
  63.  
  64. A3=imread('rice.png')
  65. figure(4)
  66. level=graythresh(A3)
  67. level1=clusterKittler(A3)
  68. level2=entropyYen(A3)
  69. BW=im2bw(A3,level)
  70. BW1=im2bw(A3,level1/255)
  71. BW2=im2bw(A3,level2/255)
  72. BW3=im2bw(A3,0.41)
  73. subplot(2,3,1)
  74. imshow(A3)
  75. title('obraz startowy')
  76. subplot(2,3,2)
  77. imhist(A3)
  78. title('histogram')
  79. subplot(2,3,3)
  80. imshow(BW)
  81. title(['prog graythresha, ',num2str(level)])
  82. subplot(2,3,4)
  83. imshow(BW1)
  84. title(['prog kittlera, ',num2str(level1/255)])
  85. subplot(2,3,5)
  86. imshow(BW2)
  87. title(['prog yena, ',num2str(level2/255)])
  88. subplot(2,3,6)
  89. imshow(BW3)
  90. title(['moj prog, ',num2str(0.49)])
Advertisement
Add Comment
Please, Sign In to add comment