title: Fingerprint Image Binarization
body: <p>I have an finger print scanner application which takes finger image data from device.</p>
  
  <p>Now I am trying to binarize the image.</p>
  
  <p>I am Using the <a href="https://i.stack.imgur.com/jkeYt.png" rel="nofollow noreferrer">Otsu's algorithm</a> to binarize the image i.e. pixel's values either 0 or 255.</p>
  
  <p>Threshold is calculated around 160 using same algorithm.
  Here is my code:</p>
  
  <pre><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&lt;width; i++){
          for(int j=0; j&lt;height; j++){
              Color c = new Color(bfImage.getRGB(i,j));
              int red = c.getRed();
              int green = c.getGreen();
              int blue = c.getBlue();
              if(red&lt;THRESHOLD &amp;&amp; green&lt;THRESHOLD &amp;&amp; blue&lt;THRESHOLD){
                  image[i][j] = 1;
              }else{
                  image[i][j] = 0;
              }
          }
      }
      return image;
  }
  </code></pre>
  
  <p>But the resulting image is not of the desired output.</p>
  
  <p><img src="https://i.stack.imgur.com/jkeYt.png" alt="enter image description here"></p>
  
  <p>Could anyone help me with this.</p>