Guest User

Untitled

a guest
Jan 17th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. // Hilditch
  2. public void getHilditchThinningImage(Bitmap img) {
  3. int a, b;
  4. boolean hasChange;
  5.  
  6. int width = img.getWidth();
  7. int height = img.getHeight();
  8.  
  9. getBlackAndWhite(img, 128);
  10.  
  11. do {
  12. hasChange = false;
  13.  
  14. for (int i = 1; (i + 2) < width; i++) {
  15. for (int j = 1; (j + 2) < height; j++) {
  16. a = getA(img, i, j);
  17. b = getB(img, i, j);
  18.  
  19. int p1 = get01Pixel(img.getPixel(i, j));
  20. int p2 = get01Pixel(img.getPixel(i, j - 1));
  21. int p4 = get01Pixel(img.getPixel(i + 1, j));
  22. int p6 = get01Pixel(img.getPixel(i, j + 1));
  23. int p8 = get01Pixel(img.getPixel(i - 1, j));
  24.  
  25. if (p1 == 1 && b >= 2 && b <= 6 && a == 1
  26. && ((p2 * p4 * p8) == 0 || getA(img, i, j - 1) != 1)
  27. && ((p2 * p4 * p6) == 0 || getA(img, i + 1, j) != 1))
  28. {
  29. int color = Color.rgb(255, 255, 255);
  30. img.setPixel(i, j, color);
  31.  
  32. hasChange = true;
  33. }
  34. }
  35. }
  36. } while (hasChange);
  37. }
  38.  
  39. // ZhangSuen
  40. public void getZhangSuenThinningImage(Bitmap img) {
  41. int a, b;
  42. ArrayList<Point> pointsToChange = new ArrayList<>();
  43. boolean hasChange;
  44.  
  45. int width = img.getWidth();
  46. int height = img.getHeight();
  47.  
  48. getBlackAndWhite(img, 128);
  49.  
  50. do {
  51. hasChange = false;
  52.  
  53. for (int i = 1; (i + 1) < width; i++) {
  54. for (int j = 1; (j + 1) < height; j++) {
  55. a = getA(img, i, j);
  56. b = getB(img, i, j);
  57.  
  58. int p1 = get01Pixel(img.getPixel(i, j));
  59. int p2 = get01Pixel(img.getPixel(i, j - 1));
  60. int p4 = get01Pixel(img.getPixel(i + 1, j));
  61. int p6 = get01Pixel(img.getPixel(i, j + 1));
  62. int p8 = get01Pixel(img.getPixel(i - 1, j));
  63.  
  64. if (p1 == 1 && b >= 2 && b <= 6 && a == 1
  65. && ((p2 * p4 * p6) == 0)
  66. && ((p4 * p6 * p8) == 0))
  67. {
  68. pointsToChange.add(new Point(i, j));
  69. hasChange = true;
  70. }
  71. }
  72. }
  73.  
  74. for (Point point : pointsToChange) {
  75. int color = Color.rgb(255, 255, 255);
  76. img.setPixel(point.getI(), point.getJ(), color);
  77. }
  78.  
  79. pointsToChange.clear();
  80.  
  81. for (int i = 1; (i + 1) < width; i++) {
  82. for (int j = 1; (j + 1) < height; j++) {
  83. a = getA(img, i, j);
  84. b = getB(img, i, j);
  85.  
  86. int p1 = get01Pixel(img.getPixel(i, j));
  87. int p2 = get01Pixel(img.getPixel(i, j - 1));
  88. int p4 = get01Pixel(img.getPixel(i + 1, j));
  89. int p6 = get01Pixel(img.getPixel(i, j + 1));
  90. int p8 = get01Pixel(img.getPixel(i - 1, j));
  91.  
  92. if (p1 == 1 && b >= 2 && b <= 6 && a == 1
  93. && ((p2 * p4 * p8) == 0)
  94. && ((p2 * p6 * p8) == 0))
  95. {
  96. pointsToChange.add(new Point(i, j));
  97. hasChange = true;
  98. }
  99. }
  100. }
  101.  
  102. for (Point point : pointsToChange) {
  103. int color = Color.rgb(255, 255, 255);
  104. img.setPixel(point.getI(), point.getJ(), color);
  105. }
  106.  
  107. pointsToChange.clear();
  108. } while (hasChange);
  109. }
Add Comment
Please, Sign In to add comment