我有一个从指纹设备获取数据的应用程序。手指细节提取有 3 个步骤:
- 指纹图像二值化
- 图像细化
- 细节提取
我完成了图像二值化和图像细化部分。现在我已经实现了细节提取的代码。代码如下所示:
byte[][] outSkeleton = BasicOperations.copy(fingerprint.getSkeleton());
int margin = 50;
int bif = 0;
int eol = 0;
for(int i=margin+20; i<width-margin-20; i++){
for(int j=margin; j<height-margin; j++){
int patterns = BasicOperations.timesPattern01(i,j,fingerprint.getSkeleton());
if(fingerprint.getSkeleton()[i][j]==1){
if(patterns==1){
outSkeleton = drawRectangle(i,j,outSkeleton,2);
eol++;
}
if(patterns==3){
outSkeleton = drawRectangle(i,j,outSkeleton,3);
bif++;
}
}
}
}
…………
public static int timesPattern01(int i, int j, byte[][] image){
int pattern01 = 0;
//Counting threads[0,1]
if(image[i-1][j]==0 && image[i-1][j+1]==1) pattern01++;
if(image[i-1][j+1]==0 && image[i][j+1]==1) pattern01++;
if(image[i][j+1]==0 && image[i+1][j+1]==1) pattern01++;
if(image[i+1][j+1]==0 && image[i+1][j]==1) pattern01++;
if(image[i+1][j]==0 && image[i+1][j-1]==1) pattern01++;
if(image[i+1][j-1]==0 && image[i][j-1]==1) pattern01++;
if(image[i][j-1]==0 && image[i-1][j-1]==1) pattern01++;
if(image[i-1][j-1]==0 && image[i-1][j]==1) pattern01++;
return pattern01;
}
......
private static byte[][] drawRectangle(int x, int y, byte[][] skeleton, int color){
int size = 3;
for(int i=-size; i<=size; i++){
skeleton[x-i][y+size] = (byte)color;
skeleton[x+i][y-size] = (byte)color;
skeleton[x-size][y+i] = (byte)color;
skeleton[x+size][y-i] = (byte)color;
}
return skeleton;
}
但是这段代码计算出平均 300 左右END OF LINES
。它考虑了线的每个端点。
谁能帮我优化代码?