Olá a todos! Estou desenvolvendo a aplicação do meu TCC, é um login que utiliza comparação entre duas digitais. Estou seguindo o método de extração de minúcias, porém, estou com um problema em aplicar o filtro de esqueletização na imagem.
O algorítmo que escolhi para esse filtro é o de Zhang-Suen, mas não estou conseguindo fazê-lo funcionar. segue o código:
método de pré-processamento da imagem:
private void pré_processamento(BufferedImage img, JLabel label) {
float[] matrix = { 0f, -1f, 0f, -1f, +5f, -1f, 0f, -1f, 0f, };
img = ManipularImagem.escalaDeCinza(img);
new Convolucao(matrix);
img = Convolucao.filtro(img, null);
new FiltroGabor(16, new double[] { 0, Math.PI / 4, Math.PI }, 0, 0.5, 10, 5, 5);
img = (BufferedImage) FiltroGabor.filtro(img, null);
Raster raster = img.getData();
DataBuffer buffer = raster.getDataBuffer();
DataBufferByte byteBuffer = (DataBufferByte) buffer;
byte[] srcData = byteBuffer.getData(0);
byte[] dstData = new byte[srcData.length];
OtsuThresholder otsu = new OtsuThresholder();
int limiar = otsu.Limiar(srcData, dstData);
img = ManipularImagem.binarizacao(img, limiar);
img = Histograma.equalizacao(img);
/*int[] imagem = Sobel.FiltroSobel(PegarPixels(img), img.getWidth(), img.getHeight(), 16, 0);
img.setRGB(0, 0, img.getWidth(), img.getHeight(),imagem, 0, img.getWidth());*/
ZhangSuen zs = new ZhangSuen();
int[][]pixels = zs.filtro(ImagemPmatriz(img));
System.out.println("Matriz de saída: ");
for (int i = 0; i < img.getWidth(); i++) {
for (int j = 0; j < img.getHeight(); j++) {
System.out.print(pixels[i][j]);
}
}
img = MatrizPimagem(pixels);
ManipularImagem.exibiImagemLabel(ManipularImagem.getImgBytes(img), label);
}
aqui está a classe do filtro de esqueletização:
public class ZhangSuen {
public int[][] filtro(final int[][] givenImage) {
int a, b;
List<Point> pointsToChange = new LinkedList<Point>();
boolean hasChange;
do {
hasChange = false;
for (int y = 1; y + 1 < givenImage.length; y++) {
for (int x = 1; x + 1 < givenImage[y].length; x++) {
a = getA(givenImage, y, x);
b = getB(givenImage, y, x);
if (givenImage[y][x] == 1 && 2 <= b && b <= 6 && a == 1
&& (givenImage[y - 1][x] * givenImage[y][x + 1] * givenImage[y + 1][x] == 0)
&& (givenImage[y][x + 1] * givenImage[y + 1][x] * givenImage[y][x - 1] == 0)) {
pointsToChange.add(new Point(x, y));
// givenImage[y][x] = 0;
hasChange = true;
}
}
}
for ( int i = 0; i < pointsToChange.size(); i++) {
Point point = (Point)pointsToChange.get(i);
givenImage[(int) point.getY()][(int) point.getX()] = 0;
}
pointsToChange.clear();
for (int y = 1; y + 1 < givenImage.length; y++) {
for (int x = 1; x + 1 < givenImage[y].length; x++) {
a = getA(givenImage, y, x);
b = getB(givenImage, y, x);
if (givenImage[y][x] == 1 && 2 <= b && b <= 6 && a == 1
&& (givenImage[y - 1][x] * givenImage[y][x + 1] * givenImage[y][x - 1] == 0)
&& (givenImage[y - 1][x] * givenImage[y + 1][x] * givenImage[y][x - 1] == 0)) {
pointsToChange.add(new Point(x, y));
hasChange = true;
}
}
}
for ( int i = 0; i < pointsToChange.size(); i++) {
Point point = (Point)pointsToChange.get(i);
givenImage[(int) point.getY()][(int) point.getX()] = 0;
}
pointsToChange.clear();
} while (hasChange);
return givenImage;
}
private static int getA(int[][] binaryImage, int y, int x) {
int count = 0;
//p2 p3
if (y - 1 >= 0 && x + 1 < binaryImage[y].length && binaryImage[y - 1][x] == 0 && binaryImage[y - 1][x + 1] == 1) {
count++;
}
//p3 p4
if (y - 1 >= 0 && x + 1 < binaryImage[y].length && binaryImage[y - 1][x + 1] == 0 && binaryImage[y][x + 1] == 1) {
count++;
}
//p4 p5
if (y + 1 < binaryImage.length && x + 1 < binaryImage[y].length && binaryImage[y][x + 1] == 0 && binaryImage[y + 1][x + 1] == 1) {
count++;
}
//p5 p6
if (y + 1 < binaryImage.length && x + 1 < binaryImage[y].length && binaryImage[y + 1][x + 1] == 0 && binaryImage[y + 1][x] == 1) {
count++;
}
//p6 p7
if (y + 1 < binaryImage.length && x - 1 >= 0 && binaryImage[y + 1][x] == 0 && binaryImage[y + 1][x - 1] == 1) {
count++;
}
//p7 p8
if (y + 1 < binaryImage.length && x - 1 >= 0 && binaryImage[y + 1][x - 1] == 0 && binaryImage[y][x - 1] == 1) {
count++;
}
//p8 p9
if (y - 1 >= 0 && x - 1 >= 0 && binaryImage[y][x - 1] == 0 && binaryImage[y - 1][x - 1] == 1) {
count++;
}
//p9 p2
if (y - 1 >= 0 && x - 1 >= 0 && binaryImage[y - 1][x - 1] == 0 && binaryImage[y - 1][x] == 1) {
count++;
}
return count;
}
private static int getB(int[][] binaryImage, int y, int x) {
return binaryImage[y - 1][x] + binaryImage[y - 1][x + 1] + binaryImage[y][x + 1]
+ binaryImage[y + 1][x + 1] + binaryImage[y + 1][x] + binaryImage[y + 1][x - 1]
+ binaryImage[y][x - 1] + binaryImage[y - 1][x - 1];
}
}
Aqui são os métodos de converter a imagem em sua matriz inteiro e vice-versa:
public BufferedImage MatrizPimagem(int[][] matriz) {
int largura = matriz.length, altura = matriz[0].length;
BufferedImage image = new BufferedImage(largura, altura, BufferedImage.TYPE_BYTE_GRAY);
WritableRaster raster = image.getRaster();
for (int h = 0; h < largura; h++) {
for (int w = 0; w < altura; w++) {
raster.setSample(h, w, 0, matriz[h][w]);
}
}
return image;
}
private int[][] ImagemPmatriz(BufferedImage image){
int w = image.getWidth();
int h = image.getHeight();
int[][] matriz = new int[w][h];
System.out.println("Matriz da entrada: ");
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
matriz[i][j] = image.getRGB(i, j);
System.out.print(matriz[i][j]);
}
}
System.out.println();
return matriz;
}
Quando eu rodo a aplicação, é como se eu não tivesse chamado a classe do filtro, não muda nada na imagem nem na matriz da imagem de entrada em relação com a da de saída.
Alguém por favor consegue me ajuda a encontrar o que está errado?
Agradeço a atenção.