@Override
    public ImageSource apply(ImageSource input) {

        int a, b;
        List<Vector2i> pointsToChange = new LinkedList<>();
        boolean hasChange = false;


        do {
            for (int y = border; y < input.getHeight() - border; y++) {
                for (int x = border; x < input.getWidth() - border; x++) {
                    a = getA(input, x, y);
                    b = getB(input, x, y);
                    if (input.getGray(x, y) == FOREGROUND && 2 <= b && b <= 6 && a == FOREGROUND
                            && (input.getGray(x, y - 1) == BACKGROUND || input.getGray(x + 1, y) == BACKGROUND || input.getGray(x, y + 1) == BACKGROUND)
                            && (input.getGray(x + 1, y) == BACKGROUND || input.getGray(x, y + 1) == BACKGROUND || input.getGray(x - 1, y) == BACKGROUND)) {

                        pointsToChange.add(new Vector2i(x, y));
                        hasChange = true;
                    }
                }
            }

            for (Vector2i point : pointsToChange) {
                //input.setRGB(point.getX(), point.getY(), BACKGROUND_COLOR);
                input.setGray(point.getX(), point.getY(), BACKGROUND);
            }
            pointsToChange.clear();

            for (int y = border; y < input.getHeight() - border; y++) {
                for (int x = border; x < input.getWidth() - border; x++) {
                    a = getA(input, x, y);
                    b = getB(input, x, y);
                    if (input.getRGB(x, y) == FOREGROUND && 2 <= b && b <= 6 && a == FOREGROUND
                            && (input.getGray(x, y - 1) == BACKGROUND || input.getGray(x + 1, y) == BACKGROUND || input.getGray(x - 1, y) == BACKGROUND)
                            && (input.getGray(x, y - 1) == BACKGROUND || input.getGray(x, y + 1) == BACKGROUND || input.getGray(x - 1, y) == BACKGROUND)) {

                        pointsToChange.add(new Vector2i(x, y));
                        hasChange = true;
                    }
                }
            }

            for (Vector2i point : pointsToChange) {
                //input.setRGB(point.getX(), point.getY(), BACKGROUND_COLOR);
                input.setRGB(point.getX(), point.getY(), BACKGROUND);
            }
            pointsToChange.clear();
        } while (hasChange);


        return input;
    }
@ Override public ImageSource apply ( ImageSource input ) { int a , b ; List < Vector2i > pointsToChange = new LinkedList < > ( ) ; boolean hasChange = false ; do { for ( int y = border ; y < input . getHeight ( ) - border ; y ++ ) { for ( int x = border ; x < input . getWidth ( ) - border ; x ++ ) { a = getA ( input , x , y ) ; b = getB ( input , x , y ) ; if ( input . getGray ( x , y ) == FOREGROUND && 2 <= b && b <= 6 && a == FOREGROUND && ( input . getGray ( x , y - 1 ) == BACKGROUND || input . getGray ( x + 1 , y ) == BACKGROUND || input . getGray ( x , y + 1 ) == BACKGROUND ) && ( input . getGray ( x + 1 , y ) == BACKGROUND || input . getGray ( x , y + 1 ) == BACKGROUND || input . getGray ( x - 1 , y ) == BACKGROUND ) ) { pointsToChange . add ( new Vector2i ( x , y ) ) ; hasChange = true ; } } } for ( Vector2i point : pointsToChange ) { input . setGray ( point . getX ( ) , point . getY ( ) , BACKGROUND ) ; } pointsToChange . clear ( ) ; for ( int y = border ; y < input . getHeight ( ) - border ; y ++ ) { for ( int x = border ; x < input . getWidth ( ) - border ; x ++ ) { a = getA ( input , x , y ) ; b = getB ( input , x , y ) ; if ( input . getRGB ( x , y ) == FOREGROUND && 2 <= b && b <= 6 && a == FOREGROUND && ( input . getGray ( x , y - 1 ) == BACKGROUND || input . getGray ( x + 1 , y ) == BACKGROUND || input . getGray ( x - 1 , y ) == BACKGROUND ) && ( input . getGray ( x , y - 1 ) == BACKGROUND || input . getGray ( x , y + 1 ) == BACKGROUND || input . getGray ( x - 1 , y ) == BACKGROUND ) ) { pointsToChange . add ( new Vector2i ( x , y ) ) ; hasChange = true ; } } } for ( Vector2i point : pointsToChange ) { input . setRGB ( point . getX ( ) , point . getY ( ) , BACKGROUND ) ; } pointsToChange . clear ( ) ; } while ( hasChange ) ; return input ; }
@param input
@return a 2D array of binary image after thinning using zhang-suen thinning algo.