虹膜灰度極座標直方圖
阿新 • • 發佈:2018-11-05
灰度極座標的直方圖,可以比較方便的看到灰度的分佈圖,直觀的看出瞳孔、虹膜邊緣特點
虹膜的256灰度圖如下:
經過極座標的直方圖轉換後,如果如下:
100個點,64灰度直方圖
200點,32灰度直方圖
400點,32灰度直方圖
通過對比,可以看出,用32灰度的瞳孔灰度集中度非常高,一致性很好;
邊緣效果上,點數越多,識別的效果越精細,400點的邊緣識別越準確。
再給出400點的平均灰度直方圖的結果:
直觀的看出影象以圓點為中心,顏色越來越明亮;
分別對6張不同虹膜圖片的進行直方圖計算,原圖如下:
對應的直方圖計算結果如下:
參考程式碼如下:
void GenPlaneHistogram() { PlaneHistogram planeHistogram = new PlaneHistogram(); int c = 100; //可取不同的值,看到不同的效果100/200/400等 int count[] = new int[c + 1]; int countgray[][] = new int[c + 1][(int) (px * py / (Math.sqrt(c)))]; int countgraymax[] = new int[c + 1]; int countgraymaxgray[] = new int[c + 1]; int countgraymaxratio[] = new int[c + 1]; String text[] = new String[c + 1]; Color color[] = new Color[c + 1]; //找出半徑最大值,根據半徑按照100等分顯示 double maxr = 0; double rr = 0; for (int i = 0; i < px; i++) { for (int j = 0; j < py; j++) { if (pixelpolar[i][j] > maxr) { maxr = pixelpolar[i][j]; } } } rr = maxr / c; System.out.println("maxr=" + maxr + ", rr=" + rr); //找出各段的計數 int cc; for (int i = 0; i < px; i++) { for (int j = 0; j < py; j++) { cc = (int) (pixelpolar[i][j] / rr); countgray[cc][count[cc]] = pixelgray[i][j]; count[cc]++; } } float bb; for (int i = 0; i < c + 1; i++) { // System.out.println("count[" + i + "]=" + count[i]); //尋找該區域灰度最大值 //分為32個灰度區 (可取不同的值,看不同的效果,如64,128,256等,有三處地方需要修改,注意!) int countgraycount[] = new int[32]; for (int j = 0; j < count[i]; j++) { // System.out.println("countgray[" + j + "]=" + countgray[i][j]); countgraycount[countgray[i][j]/8]++; } countgraymax[i] = 0; for (int j = 0; j < 32; j++) { // System.out.println("countgraycount[" + j + "]=" + countgraycount[j]); if (countgraymax[i] < countgraycount[j]) { countgraymax[i] = countgraycount[j]; countgraymaxgray[i] = j; // System.out.println("111 [" + i + "]=" + countgraymax[i] + "," + countgraymaxgray[i]); } } countgraymaxratio[i] = countgraymax[i]*100/count[i]; // System.out.println("222 [" + i + "]=" + countgraymax[i] + "," + countgraymaxgray[i]); } for (int i = 0; i < c + 1; i++) { bb = (float) (Math.round(rr * i * 100)) / 100; text[i] = bb + ""; color[i] = Color.GREEN; } //極座標半徑直方圖 BufferedImage image = planeHistogram.paintPlaneHistogram("極座標半徑直方圖", count, text, color); File output = new File("111.jpg"); try { ImageIO.write(image, "jpg", output); } catch (IOException e) { e.printStackTrace(); } for (int i = 0; i < c + 1; i++) { text[i] = countgraymaxgray[i] + ""; color[i] = Color.GREEN; } //灰度極座標的直方圖,X軸是極座標,Y軸是對應灰度密集區最大值的灰度值 BufferedImage image2 = planeHistogram.paintPlaneHistogram("灰度極座標直方圖", countgraymaxratio, text, color); File output2 = new File("222.jpg"); try { ImageIO.write(image2, "jpg", output2); } catch (IOException e) { e.printStackTrace(); } }