TeamCode/src/main/java/org/firstinspires/ftc/teamcode/opmodes/demo/OpenCVTest.java
public int[][] doZhangSuenThinning(final int[][] givenImage, boolean changeGivenImage) {
        int[][] binaryImage;
        if (changeGivenImage) {
            binaryImage = givenImage;
        } else {
            binaryImage = givenImage.clone();
        }
        int a, b;
        List<mPoint> pointsToChange = new LinkedList();
        boolean hasChange;
        do {
            hasChange = false;
            for (int y = 1; y + 1 < binaryImage.length; y++) {
                for (int x = 1; x + 1 < binaryImage[y].length; x++) {
                    a = getA(binaryImage, y, x);
                    b = getB(binaryImage, y, x);
                    if (binaryImage[y][x] == 1 && 2 <= b && b <= 6 && a == 1
                            && (binaryImage[y - 1][x] * binaryImage[y][x + 1] * binaryImage[y + 1][x] == 0)
                            && (binaryImage[y][x + 1] * binaryImage[y + 1][x] * binaryImage[y][x - 1] == 0)) {
                        pointsToChange.add(new mPoint(x, y));
//binaryImage[y][x] = 0;
                        hasChange = true;
                    }
                }
            }
            for (mPoint point : pointsToChange) {
                binaryImage[point.getY()][point.getX()] = 0;
            }
            pointsToChange.clear();
            for (int y = 1; y + 1 < binaryImage.length; y++) {
                for (int x = 1; x + 1 < binaryImage[y].length; x++) {
                    a = getA(binaryImage, y, x);
                    b = getB(binaryImage, y, x);
                    if (binaryImage[y][x] == 1 && 2 <= b && b <= 6 && a == 1
                            && (binaryImage[y - 1][x] * binaryImage[y][x + 1] * binaryImage[y][x - 1] == 0)
                            && (binaryImage[y - 1][x] * binaryImage[y + 1][x] * binaryImage[y][x - 1] == 0)) {
                        pointsToChange.add(new mPoint(x, y));
                        hasChange = true;
                    }
                }
            }
            for (mPoint point : pointsToChange) {
                binaryImage[point.getY()][point.getX()] = 0;
            }
            pointsToChange.clear();
        } while (hasChange);
        return binaryImage;
    }
/**
     * @param givenImage
     * @param changeGivenImage decides whether the givenArray should be modified or a clone should be used
     * @return a 2D array of binary image after thinning using zhang-suen thinning algo.
     */
@param givenImage
@param changeGivenImage decides whether the givenArray should be modified or a clone should be used
@return a 2D array of binary image after thinning using zhang-suen thinning algo.
@param givenImage @param changeGivenImage decides whether the givenArray should be modified or a clone should be used @return a 2D array of binary image after thinning using zhang - suen thinning algo .
public int[][] doZhangSuenThinning(final int[][] givenImage, boolean changeGivenImage) {
        int[][] binaryImage;
        if (changeGivenImage) {
            binaryImage = givenImage;
        } else {
            binaryImage = givenImage.clone();
        }
        int a, b;
        List<mPoint> pointsToChange = new LinkedList();
        boolean hasChange;
        do {
            hasChange = false;
            for (int y = 1; y + 1 < binaryImage.length; y++) {
                for (int x = 1; x + 1 < binaryImage[y].length; x++) {
                    a = getA(binaryImage, y, x);
                    b = getB(binaryImage, y, x);
                    if (binaryImage[y][x] == 1 && 2 <= b && b <= 6 && a == 1
                            && (binaryImage[y - 1][x] * binaryImage[y][x + 1] * binaryImage[y + 1][x] == 0)
                            && (binaryImage[y][x + 1] * binaryImage[y + 1][x] * binaryImage[y][x - 1] == 0)) {
                        pointsToChange.add(new mPoint(x, y));
                        hasChange = true;
                    }
                }
            }
            for (mPoint point : pointsToChange) {
                binaryImage[point.getY()][point.getX()] = 0;
            }
            pointsToChange.clear();
            for (int y = 1; y + 1 < binaryImage.length; y++) {
                for (int x = 1; x + 1 < binaryImage[y].length; x++) {
                    a = getA(binaryImage, y, x);
                    b = getB(binaryImage, y, x);
                    if (binaryImage[y][x] == 1 && 2 <= b && b <= 6 && a == 1
                            && (binaryImage[y - 1][x] * binaryImage[y][x + 1] * binaryImage[y][x - 1] == 0)
                            && (binaryImage[y - 1][x] * binaryImage[y + 1][x] * binaryImage[y][x - 1] == 0)) {
                        pointsToChange.add(new mPoint(x, y));
                        hasChange = true;
                    }
                }
            }
            for (mPoint point : pointsToChange) {
                binaryImage[point.getY()][point.getX()] = 0;
            }
            pointsToChange.clear();
        } while (hasChange);
        return binaryImage;
    }
public int [ ] [ ] doZhangSuenThinning ( final int [ ] [ ] givenImage , boolean changeGivenImage ) { int [ ] [ ] binaryImage ; if ( changeGivenImage ) { binaryImage = givenImage ; } else { binaryImage = givenImage . clone ( ) ; } int a , b ; List < mPoint > pointsToChange = new LinkedList ( ) ; boolean hasChange ; do { hasChange = false ; for ( int y = 1 ; y + 1 < binaryImage . length ; y ++ ) { for ( int x = 1 ; x + 1 < binaryImage [ y ] . length ; x ++ ) { a = getA ( binaryImage , y , x ) ; b = getB ( binaryImage , y , x ) ; if ( binaryImage [ y ] [ x ] == 1 && 2 <= b && b <= 6 && a == 1 && ( binaryImage [ y - 1 ] [ x ] * binaryImage [ y ] [ x + 1 ] * binaryImage [ y + 1 ] [ x ] == 0 ) && ( binaryImage [ y ] [ x + 1 ] * binaryImage [ y + 1 ] [ x ] * binaryImage [ y ] [ x - 1 ] == 0 ) ) { pointsToChange . add ( new mPoint ( x , y ) ) ; hasChange = true ; } } } for ( mPoint point : pointsToChange ) { binaryImage [ point . getY ( ) ] [ point . getX ( ) ] = 0 ; } pointsToChange . clear ( ) ; for ( int y = 1 ; y + 1 < binaryImage . length ; y ++ ) { for ( int x = 1 ; x + 1 < binaryImage [ y ] . length ; x ++ ) { a = getA ( binaryImage , y , x ) ; b = getB ( binaryImage , y , x ) ; if ( binaryImage [ y ] [ x ] == 1 && 2 <= b && b <= 6 && a == 1 && ( binaryImage [ y - 1 ] [ x ] * binaryImage [ y ] [ x + 1 ] * binaryImage [ y ] [ x - 1 ] == 0 ) && ( binaryImage [ y - 1 ] [ x ] * binaryImage [ y + 1 ] [ x ] * binaryImage [ y ] [ x - 1 ] == 0 ) ) { pointsToChange . add ( new mPoint ( x , y ) ) ; hasChange = true ; } } } for ( mPoint point : pointsToChange ) { binaryImage [ point . getY ( ) ] [ point . getX ( ) ] = 0 ; } pointsToChange . clear ( ) ; } while ( hasChange ) ; return binaryImage ; }
@param givenImage
 @param changeGivenImage decides whether the givenArray should be modified or a clone should be used
 @return a 2D array of binary image after thinning using zhang-suen thinning algo.
@param givenImage @param changeGivenImage decides whether the givenArray should be modified or a clone should be used @return a 2D array of binary image after thinning using zhang - suen thinning algo .
//binaryImage[y][x] = 0;