@Override
    public ImageSource apply(ImageSource input) {
        width = input.getWidth();
        height = input.getHeight();

        MatrixSource filteredImage = new MatrixSource(input);

        imageM = new int[width][height];

        for (int j = 0; j < height; j++) {
            for (int i = 0; i < width; i++) {
                int col = input.getR(i, j);
                if (blackLetters) {
                    imageM[i][j] = 1 - (col / 255);
                } else {
                    imageM[i][j] = col / 255;
                }
            }
        }

        while (true) {

            int[][] start = new int[width][height];

            for (int j = 0; j < height; j++) {
                for (int i = 0; i < width; i++) {
                    start[i][j] = imageM[i][j];
                }
            }

            thiningGuoHallIteration(0);
            thiningGuoHallIteration(1);

            boolean same = true;
            MainforLoop:
            for (int i = 0; i < width; i++) {
                for (int j = 0; j < height; j++) {
                    if (start[i][j] != imageM[i][j]) {
                        same = false;
                        break MainforLoop;
                    }

                }
            }
            if (same) {
                break;
            }
        }

        for (int j = 0; j < height; j++) {
            for (int i = 0; i < width; i++) {
                int alpha = input.getA(i, j);
                int col;
                if (blackLetters) {
                    col = 255 - imageM[i][j] * 255;
                } else {
                    col = imageM[i][j] * 255;
                }
                int rgb = ColorHelper.getARGB(col, col, col, alpha);

                filteredImage.setRGB(i, j, rgb);
            }
        }

        return filteredImage;
    }
@ Override public ImageSource apply ( ImageSource input ) { width = input . getWidth ( ) ; height = input . getHeight ( ) ; MatrixSource filteredImage = new MatrixSource ( input ) ; imageM = new int [ width ] [ height ] ; for ( int j = 0 ; j < height ; j ++ ) { for ( int i = 0 ; i < width ; i ++ ) { int col = input . getR ( i , j ) ; if ( blackLetters ) { imageM [ i ] [ j ] = 1 - ( col / 255 ) ; } else { imageM [ i ] [ j ] = col / 255 ; } } } while ( true ) { int [ ] [ ] start = new int [ width ] [ height ] ; for ( int j = 0 ; j < height ; j ++ ) { for ( int i = 0 ; i < width ; i ++ ) { start [ i ] [ j ] = imageM [ i ] [ j ] ; } } thiningGuoHallIteration ( 0 ) ; thiningGuoHallIteration ( 1 ) ; boolean same = true ; MainforLoop : for ( int i = 0 ; i < width ; i ++ ) { for ( int j = 0 ; j < height ; j ++ ) { if ( start [ i ] [ j ] != imageM [ i ] [ j ] ) { same = false ; break MainforLoop ; } } } if ( same ) { break ; } } for ( int j = 0 ; j < height ; j ++ ) { for ( int i = 0 ; i < width ; i ++ ) { int alpha = input . getA ( i , j ) ; int col ; if ( blackLetters ) { col = 255 - imageM [ i ] [ j ] * 255 ; } else { col = imageM [ i ] [ j ] * 255 ; } int rgb = ColorHelper . getARGB ( col , col , col , alpha ) ; filteredImage . setRGB ( i , j , rgb ) ; } } return filteredImage ; }
@param input The input image should be binary
@return