public ImageSource apply(ImageSource input) {
        ImageSource originalImage = input;

        int width = originalImage.getWidth();
        int height = originalImage.getHeight();

        boolean[][] matrix = new boolean[width][height]; // black n white boolean matrix; true = blck, false = white

        // Copy
        ImageSource filteredImage = new MatrixSource(input);

        int[] histogram = OtsuBinarize.imageHistogram(originalImage);

        int totalNumberOfpixels = height * width;

        int threshold = OtsuBinarize.threshold(histogram, totalNumberOfpixels);

        int black = 0;
        int white = 255;

        int gray;
        int alpha;
        int newColor;

        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                gray = originalImage.getGray(i, j);

                if (gray > threshold) {
                    matrix[i][j] = false;
                } else {
                    matrix[i][j] = true;
                }

            }
        }

        int blackTreshold = letterThreshold(originalImage, matrix);

        for (int i = 0; i < width; i++) {
            for (int j = 0; j < height; j++) {
                gray = originalImage.getGray(i, j);
                alpha = originalImage.getA(i, j);

                if (gray > blackTreshold) {
                    newColor = white;
                } else {
                    newColor = black;
                }

                newColor = ColorHelper.getARGB(newColor, newColor, newColor, alpha);
                filteredImage.setRGB(i, j, newColor);
            }
        }

        return filteredImage;
    }
public ImageSource apply ( ImageSource input ) { ImageSource originalImage = input ; int width = originalImage . getWidth ( ) ; int height = originalImage . getHeight ( ) ; boolean [ ] [ ] matrix = new boolean [ width ] [ height ] ; ImageSource filteredImage = new MatrixSource ( input ) ; int [ ] histogram = OtsuBinarize . imageHistogram ( originalImage ) ; int totalNumberOfpixels = height * width ; int threshold = OtsuBinarize . threshold ( histogram , totalNumberOfpixels ) ; int black = 0 ; int white = 255 ; int gray ; int alpha ; int newColor ; for ( int i = 0 ; i < width ; i ++ ) { for ( int j = 0 ; j < height ; j ++ ) { gray = originalImage . getGray ( i , j ) ; if ( gray > threshold ) { matrix [ i ] [ j ] = false ; } else { matrix [ i ] [ j ] = true ; } } } int blackTreshold = letterThreshold ( originalImage , matrix ) ; for ( int i = 0 ; i < width ; i ++ ) { for ( int j = 0 ; j < height ; j ++ ) { gray = originalImage . getGray ( i , j ) ; alpha = originalImage . getA ( i , j ) ; if ( gray > blackTreshold ) { newColor = white ; } else { newColor = black ; } newColor = ColorHelper . getARGB ( newColor , newColor , newColor , alpha ) ; filteredImage . setRGB ( i , j , newColor ) ; } } return filteredImage ; }
radi otsu da dobije spojena crna slova i ra

@param input
@return the processed image