Merge branch 'main' into 'apiAlgo'
# Conflicts: # backend/src/main/java/pdl/backend/ImageProcessing.java
This commit is contained in:
commit
55350cde35
3 files changed
+21
-19
No files matched your search
@@ -3,6 +3,8 @@ package pdl.backend;
|
||||
import boofcv.struct.image.GrayU8;
|
||||
import boofcv.struct.image.Planar;
|
||||
|
||||
import boofcv.concurrency.BoofConcurrency;
|
||||
|
||||
public class ImageProcessing {
|
||||
|
||||
/**
|
||||
@@ -44,13 +46,13 @@ public class ImageProcessing {
|
||||
* @param output l'image de sortie en niveaux de gris
|
||||
*/
|
||||
public static void convertColorToGray(Planar<GrayU8> input, Planar<GrayU8> output) {
|
||||
for (int y = 0; y < input.height; y++) {
|
||||
BoofConcurrency.loopFor(0, input.height, y -> {
|
||||
for (int x = 0; x < input.width; x++) {
|
||||
int[] rgb = getRGBValue(input, x, y);
|
||||
int gray = (int) (0.3 * rgb[0] + 0.59 * rgb[1] + 0.11 * rgb[2]);
|
||||
setRGBValue(output, x, y, new int[] { gray, gray, gray });
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +64,7 @@ public class ImageProcessing {
|
||||
* @param delta La valeur du décalage à appliquer à la luminosité de l'image.
|
||||
*/
|
||||
public static void changeLuminosity(Planar<GrayU8> input, int delta) {
|
||||
for (int y = 0; y < input.height; y++) {
|
||||
BoofConcurrency.loopFor(0, input.height, y -> {
|
||||
for (int x = 0; x < input.width; x++) {
|
||||
int[] rgb = getRGBValue(input, x, y);
|
||||
for (int i = 0; i < rgb.length; i++) {
|
||||
@@ -76,7 +78,7 @@ public class ImageProcessing {
|
||||
}
|
||||
setRGBValue(input, x, y, rgb);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,12 +93,12 @@ public class ImageProcessing {
|
||||
convertColorToGray(input, grayInput);
|
||||
// On remplit le tableau avec le nombre de pixels pour chaque niveau de
|
||||
// gris
|
||||
for (int y = 0; y < input.height; y++) {
|
||||
BoofConcurrency.loopFor(0, input.height, y -> {
|
||||
for (int x = 0; x < input.width; x++) {
|
||||
int gl = grayInput.getBand(0).get(x, y);
|
||||
h[gl]++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// On remplit le tableau avec la cumulée de l'histogramme
|
||||
int C[] = new int[256];
|
||||
@@ -113,14 +115,14 @@ public class ImageProcessing {
|
||||
}
|
||||
|
||||
// Transformation de l'image en utilisant la table de LUT
|
||||
for (int y = 0; y < input.height; y++) {
|
||||
BoofConcurrency.loopFor(0, input.height, y -> {
|
||||
for (int x = 0; x < input.width; x++) {
|
||||
for (int j = 0; j < input.getNumBands(); j++) {
|
||||
int val = input.getBand(j).get(x, y);
|
||||
input.getBand(j).set(x, y, LUT[val]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,7 +218,7 @@ public class ImageProcessing {
|
||||
if (hue < 0 || hue > 360) {
|
||||
throw new IllegalArgumentException("Hue doit être compris entre 0 et 360");
|
||||
}
|
||||
for (int j = 0; j < input.height; j++) {
|
||||
BoofConcurrency.loopFor(0, input.height, j -> {
|
||||
for (int i = 0; i < input.width; i++) {
|
||||
float[] hsv = new float[3];
|
||||
int[] pixelValue = getRGBValue(input, i, j);
|
||||
@@ -226,7 +228,7 @@ public class ImageProcessing {
|
||||
hsvToRgb(hsv[0], hsv[1], hsv[2], rgb);
|
||||
setRGBValue(input, i, j, rgb);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,7 +245,7 @@ public class ImageProcessing {
|
||||
int half = h1.length / 2;
|
||||
Planar<GrayU8> inputGray = input.createSameShape();
|
||||
convertColorToGray(input, inputGray);
|
||||
for (int y = 0; y < input.height; y++) {
|
||||
BoofConcurrency.loopFor(0, input.height, y -> {
|
||||
for (int x = 0; x < input.width; x++) {
|
||||
if (y < half || x < half || y >= input.height - half || x >= input.width - half) {
|
||||
int gl = inputGray.getBand(0).get(x, y);
|
||||
@@ -272,7 +274,7 @@ public class ImageProcessing {
|
||||
int[] rgb = { value, value, value };
|
||||
setRGBValue(output, x, y, rgb);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -289,7 +291,7 @@ public class ImageProcessing {
|
||||
throw new IllegalArgumentException("La taille doit être impaire");
|
||||
}
|
||||
// Boucle pour parcourir tous les pixels de l'image d'entrée
|
||||
for (int y = 0; y < input.height; y++) {
|
||||
BoofConcurrency.loopFor(0, input.height, y -> {
|
||||
for (int x = 0; x < input.width; x++) {
|
||||
if (y < size / 2 || x < size / 2 || y >= input.height - size / 2
|
||||
|| x >= input.width - size / 2) {
|
||||
@@ -313,7 +315,7 @@ public class ImageProcessing {
|
||||
}
|
||||
setRGBValue(output, x, y, totalValue);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -361,15 +363,16 @@ public class ImageProcessing {
|
||||
int[][] kernel = { { 1, 2, 3, 2, 1 }, { 2, 6, 8, 6, 2 }, { 3, 8, 10, 8, 3 }, { 2, 6, 8, 6, 2 },
|
||||
{ 1, 2, 3, 2, 1 } };
|
||||
int half = size / 2;
|
||||
int totalCoefs = 0;
|
||||
int coefs = 0;
|
||||
// Calcul du nombre total de coefficients dans le noyau
|
||||
for (int i = 0; i < kernel.length; i++) {
|
||||
for (int j = 0; j < kernel[i].length; j++) {
|
||||
totalCoefs += kernel[i][j];
|
||||
coefs += kernel[i][j];
|
||||
}
|
||||
}
|
||||
final int totalCoefs = coefs;
|
||||
// Parcours de l'image d'entrée et application de la convolution
|
||||
for (int y = 0; y < input.height; y++) {
|
||||
BoofConcurrency.loopFor(0, input.height, y -> {
|
||||
for (int x = 0; x < input.width; x++) {
|
||||
// Vérification si le carré sera à l'intérieur de l'image
|
||||
if (y < half || x < half || y >= input.height - half || x >= input.width -
|
||||
@@ -396,6 +399,6 @@ public class ImageProcessing {
|
||||
}
|
||||
setRGBValue(output, x, y, totalValue);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 314 KiB After Width: | Height: | Size: 295 KiB |
@@ -1,6 +1,5 @@
|
||||
package pdl.backend;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
Reference in new issue
Block a user