Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Hilditch
- public void getHilditchThinningImage(Bitmap img) {
- int a, b;
- boolean hasChange;
- int width = img.getWidth();
- int height = img.getHeight();
- getBlackAndWhite(img, 128);
- do {
- hasChange = false;
- for (int i = 1; (i + 2) < width; i++) {
- for (int j = 1; (j + 2) < height; j++) {
- a = getA(img, i, j);
- b = getB(img, i, j);
- int p1 = get01Pixel(img.getPixel(i, j));
- int p2 = get01Pixel(img.getPixel(i, j - 1));
- int p4 = get01Pixel(img.getPixel(i + 1, j));
- int p6 = get01Pixel(img.getPixel(i, j + 1));
- int p8 = get01Pixel(img.getPixel(i - 1, j));
- if (p1 == 1 && b >= 2 && b <= 6 && a == 1
- && ((p2 * p4 * p8) == 0 || getA(img, i, j - 1) != 1)
- && ((p2 * p4 * p6) == 0 || getA(img, i + 1, j) != 1))
- {
- int color = Color.rgb(255, 255, 255);
- img.setPixel(i, j, color);
- hasChange = true;
- }
- }
- }
- } while (hasChange);
- }
- // ZhangSuen
- public void getZhangSuenThinningImage(Bitmap img) {
- int a, b;
- ArrayList<Point> pointsToChange = new ArrayList<>();
- boolean hasChange;
- int width = img.getWidth();
- int height = img.getHeight();
- getBlackAndWhite(img, 128);
- do {
- hasChange = false;
- for (int i = 1; (i + 1) < width; i++) {
- for (int j = 1; (j + 1) < height; j++) {
- a = getA(img, i, j);
- b = getB(img, i, j);
- int p1 = get01Pixel(img.getPixel(i, j));
- int p2 = get01Pixel(img.getPixel(i, j - 1));
- int p4 = get01Pixel(img.getPixel(i + 1, j));
- int p6 = get01Pixel(img.getPixel(i, j + 1));
- int p8 = get01Pixel(img.getPixel(i - 1, j));
- if (p1 == 1 && b >= 2 && b <= 6 && a == 1
- && ((p2 * p4 * p6) == 0)
- && ((p4 * p6 * p8) == 0))
- {
- pointsToChange.add(new Point(i, j));
- hasChange = true;
- }
- }
- }
- for (Point point : pointsToChange) {
- int color = Color.rgb(255, 255, 255);
- img.setPixel(point.getI(), point.getJ(), color);
- }
- pointsToChange.clear();
- for (int i = 1; (i + 1) < width; i++) {
- for (int j = 1; (j + 1) < height; j++) {
- a = getA(img, i, j);
- b = getB(img, i, j);
- int p1 = get01Pixel(img.getPixel(i, j));
- int p2 = get01Pixel(img.getPixel(i, j - 1));
- int p4 = get01Pixel(img.getPixel(i + 1, j));
- int p6 = get01Pixel(img.getPixel(i, j + 1));
- int p8 = get01Pixel(img.getPixel(i - 1, j));
- if (p1 == 1 && b >= 2 && b <= 6 && a == 1
- && ((p2 * p4 * p8) == 0)
- && ((p2 * p6 * p8) == 0))
- {
- pointsToChange.add(new Point(i, j));
- hasChange = true;
- }
- }
- }
- for (Point point : pointsToChange) {
- int color = Color.rgb(255, 255, 255);
- img.setPixel(point.getI(), point.getJ(), color);
- }
- pointsToChange.clear();
- } while (hasChange);
- }
Add Comment
Please, Sign In to add comment