0

I have an finger print scanner application which takes finger image data from device.

Now I am trying to binarize the image.

I am Using the Otsu's algorithm to binarize the image i.e. pixel's values either 0 or 255.

Threshold is calculated around 160 using same algorithm. Here is my code:

public static byte[][] binarizeImage(BufferedImage bfImage){
    final int THRESHOLD = 160;
    int height = bfImage.getHeight();
    int width = bfImage.getWidth();
    byte[][] image = new byte[width][height];

    for(int i=0; i<width; i++){
        for(int j=0; j<height; j++){
            Color c = new Color(bfImage.getRGB(i,j));
            int red = c.getRed();
            int green = c.getGreen();
            int blue = c.getBlue();
            if(red<THRESHOLD && green<THRESHOLD && blue<THRESHOLD){
                image[i][j] = 1;
            }else{
                image[i][j] = 0;
            }
        }
    }
    return image;
}

But the resulting image is not of the desired output.

enter image description here

Could anyone help me with this.

code_fish
  • 3,381
  • 5
  • 47
  • 90
  • Shouldn't you use values `255` and `0` instead of `1` and `0`? Also you might want to apply the threshold in each channel separately (it really depends on how you use the resulting `byte[]`). [This wiki](http://www.labbookpages.co.uk/software/imgProc/otsuThreshold.html) has a java demo, maybe it helps – c.s. Aug 30 '13 at 09:12
  • Did you have a look at http://stackoverflow.com/questions/18503412/convert-buffered-image-to-the-2d-byte-array-with-the-same-data? – Harald K Aug 30 '13 at 15:15

0 Answers0