public void deleteVerticaltwoPath() { this.interest = this.verticalInterest(image); Suurballe sb = new Suurballe(); Graph g = this.verticalToGraph2(interest); // recherche des chemins ArrayList<Integer> chemin = sb.rechercheChemin(g, 0, g.vertices() - 1, this.interest); ArrayList<Integer> chemin1 = new ArrayList<>(); ArrayList<Integer> chemin2 = new ArrayList<>(); boolean end1 = false; for (int i = 0; i < chemin.size(); i++) { if (!end1) { if (chemin.get(i) != -1) { chemin1.add(chemin.get(i)); } else { end1 = true; } } else { chemin2.add(chemin.get(i)); } } this.tabDeleteColum(chemin1, chemin2); }
public void deleteLines() { this.interest = this.HorizontalInterest(image); int nbPixels = height * width; Dijkstra d = new Dijkstra(); Graph g = this.horizontalToGraph(this.interest); ArrayList<Integer> res = d.rechercheChemin(g, 0, g.vertices() - 1); int[][] newImage = new int[height - 1][width]; int[][][] newImageColor = new int[height - 1][width][3]; int line; int column = width - 1; boolean equals; int pos, k; for (int l : res) { line = 0; pos = l % this.height - 1; if (pos == -1) { pos = this.height - 1; } equals = false; if (l != 0 && l != (nbPixels + 1)) { while (line != this.height - 1) { if (pos == line) { equals = true; } if (equals == false) { if (color) { for (k = 0; k < 3; k++) newImageColor[line][column][k] = this.imageRgb[line][column][k]; } else newImage[line][column] = this.image[line][column]; } else if (equals == true) { if (column < width) { if (color) { for (k = 0; k < 3; k++) newImageColor[line][column][k] = this.imageRgb[line + 1][column][k]; } else newImage[line][column] = this.image[line + 1][column]; } } else { System.err.println("Error 0x087A4E652"); } line++; } } column--; } if (color) this.imageRgb = newImageColor; else this.image = newImage; this.height = height - 1; }
/** * @param itr - tableau contenant les facteurs d'intérêt de l'image * @return un graphe représentant ce tableau */ public Graph horizontalToGraph(int[][] itr) { int nbSommets = width * height + 2; int i, j; Graph g = new Graph(nbSommets); // sommet tout en haut for (j = 0; j < height; j++) g.addEdge(new Edge(0, j + 1, 0)); for (i = 0; i < width - 1; i++) { for (j = 0; j < height; j++) { // arête vers le haut if (j > 0) { g.addEdge(new Edge(height * i + j + 1, height * (i + 1) + j - 1 + 1, itr[j][i])); } // arête vers le bas if (j < height - 1) { g.addEdge(new Edge(height * i + j + 1, height * (i + 1) + j + 1 + 1, itr[j][i])); } // arête centrale g.addEdge(new Edge(height * i + j + 1, height * (i + 1) + j + 1, itr[j][i])); } } // sommet tout en bas for (j = 0; j < height; j++) g.addEdge(new Edge(height * (width - 1) + j + 1, height * width + 1, itr[j][i])); return g; }
/** * @param itr - tableau contenant les facteurs d'intérêt de l'image * @return un graphe représentant ce tableau */ public Graph verticalToGraph(int[][] itr) { int nbSommets = width * height + 2; int i, j; Graph g = new Graph(nbSommets); // sommet tout en haut for (j = 0; j < width; j++) g.addEdge(new Edge(0, j + 1, 0)); for (i = 0; i < height - 1; i++) { for (j = 0; j < width; j++) { // arête vers la gauche if (j > 0) { g.addEdge(new Edge(width * i + j + 1, width * (i + 1) + (j - 1) + 1, itr[i][j])); } // arête vers la droite if (j < width - 1) { g.addEdge(new Edge(width * i + j + 1, width * (i + 1) + (j + 1) + 1, itr[i][j])); } // arête centrale g.addEdge(new Edge(width * i + j + 1, width * (i + 1) + j + 1, itr[i][j])); } } // sommet tout en bas for (j = 0; j < width; j++) g.addEdge(new Edge(width * (height - 1) + j + 1, height * width + 1, itr[i][j])); return g; }
/** * Graphe vertical pour l'algorithme de Suurballe * * @param itr - facteurs d'intérêts de l'image * @return - graphe vertical des facteurs d'intérêts */ public Graph verticalToGraph2(int[][] itr) { int h = (height - 2) * 2 + 2; int nbSommets = h * width + 2; int i, j; Graph g = new Graph(nbSommets); // sommet tout en haut for (j = 0; j < width; j++) g.addEdge(new Edge(0, j + 1, 0)); int iCourant = 0; // lignes centrales for (i = 0; i < h; i++) { if (i != h - 1) { if (i % 2 == 0) { for (j = 0; j < width; j++) { // arête vers la gauche if (j > 0) { g.addEdge(new Edge(i * width + j + 1, (i + 1) * width + j, itr[iCourant][j])); } // arête vers la droite if (j < width - 1) { g.addEdge(new Edge(i * width + j + 1, (i + 1) * width + j + 2, itr[iCourant][j])); } // arête centrale g.addEdge(new Edge(i * width + j + 1, (i + 1) * width + j + 1, itr[iCourant][j])); } iCourant++; } else { for (j = 0; j < width; j++) { g.addEdge(new Edge(i * width + j + 1, (i + 1) * width + j + 1, 0)); } } } } // derniere ligne for (j = (nbSommets - 1) - width; j < nbSommets - 1; j++) { int pos = j % this.width - 1; if (pos == -1) { pos = this.width - 1; } g.addEdge(new Edge(j, nbSommets - 1, itr[height - 1][pos])); } return g; }
public void addLines() { this.interest = this.HorizontalInterest(image); int nbPixels = height * width; Dijkstra d = new Dijkstra(); Graph g = this.horizontalToGraph(this.interest); ArrayList<Integer> res = d.rechercheChemin(g, 0, g.vertices() - 1); int[][] newImage = new int[height + 1][width]; int line; int column = width - 1; boolean equals; int pos; for (int l : res) { line = 0; pos = l % this.height - 1; if (pos == -1) { pos = this.height - 1; } equals = false; if (l != 0 && l != (nbPixels + 1)) { while (line != this.height + 1) { if (pos == line) { equals = true; } if (equals == false) { newImage[line][column] = this.image[line][column]; } else if (equals == true) { // Ajout premiere ligne de pixels if (line == pos) { if (line > 0) { int highPixel = this.image[line - 1][column]; int currentPixel = this.image[line][column]; newImage[line][column] = (highPixel + currentPixel) / 2; } else { newImage[line][column] = this.image[line][column]; } } // ajout deuxieme ligne de pixels else if (line == pos + 1) { if (line < this.height) { int lowPixel = this.image[line][column]; int currentPixel = this.image[line - 1][column]; newImage[line][column] = (lowPixel + currentPixel) / 2; } else { newImage[line][column] = this.image[line][column]; } } else if (line < width + 1) { newImage[line][column] = this.image[line - 1][column]; } } else { System.err.println("Error 0x087A4E652"); } line++; } } column--; } this.image = newImage; this.height = height + 1; }
public void addColumns() { this.interest = this.verticalInterest(image); int nbPixels = height * width; Dijkstra d = new Dijkstra(); Graph g = this.verticalToGraph(this.interest); ArrayList<Integer> res = d.rechercheChemin(g, 0, g.vertices() - 1); int[][] newImage = new int[height][width + 1]; int line = height - 1; int column; boolean equals; int pos; for (int l : res) { column = 0; pos = l % this.width - 1; if (pos == -1) { pos = this.width - 1; } equals = false; if (l != 0 && l != (nbPixels + 1)) { while (column != this.width + 1) { if (pos == column) { equals = true; } if (equals == false) { newImage[line][column] = this.image[line][column]; } else if (equals == true) { // Ajout premiere colonne de pixels if (column == pos) { if (column > 0) { int leftPixel = this.image[line][column - 1]; int currentPixel = this.image[line][column]; newImage[line][column] = (leftPixel + currentPixel) / 2; } else { newImage[line][column] = this.image[line][column]; } } // ajout deuxieme colonne de pixels else if (column == pos + 1) { if (column < this.width) { int rightPixel = this.image[line][column]; int currentPixel = this.image[line][column - 1]; newImage[line][column] = (rightPixel + currentPixel) / 2; } else { newImage[line][column] = this.image[line][column]; } } else if (column < width + 1) { newImage[line][column] = this.image[line][column - 1]; } } else { System.err.println("Error 0x087A4E652"); } column++; } } line--; } this.image = newImage; this.width = width + 1; }