2013-08-30 30 views
0

我有一個指紋掃描儀應用程序,它從設備獲取手指圖像數據。指紋圖像二值化

現在我試圖對圖像進行二值化處理。

我使用Otsu's algorithm二值化圖像即像素的值是0或者255

閾值是利用相同的算法約160計算。 這裏是我的代碼:

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; 
} 

但由此產生的圖像所需的輸出不是。

enter image description here

誰能幫我這。

+0

你不應該使用值'255'和'0',而不是'1'和'0'?你也可能想分別在每個通道中應用閾值(這實際上取決於你如何使用生成的byte []')。 [這個wiki](http://www.labbookpages.co.uk/software/imgProc/otsuThreshold.html)有一個java演示,也許它有幫助 –

+0

你看看http://stackoverflow.com/questions/ 18503412 /轉換緩衝圖像到所述-2D-字節陣列與最相同數據? – haraldK

回答

1

大津法對指紋圖像不好。嘗試使用這個下面的過濾:

  • 布拉德利局部閾值
  • 伯恩森閾值。
  • 最大熵閾值。

你會發現,這裏:http://code.google.com/p/catalano-framework/

例子:

FastBitmap fb = new FastBitmap(bufferedImage); 
fb.toGrayscale(); 

BradleyLocalThreshold b = new BradleyLocalThreshold(); 
b.applyInPlace(fb); 

bufferedImage = fb.toBufferedImage();