apply algo on a zone
This commit is contained in:
1 parent
4360405c8f
commit
21424f0b62
4 files changed
+98
-14
No files matched your search
@@ -10,6 +10,10 @@ import boofcv.struct.image.GrayU8;
|
||||
import boofcv.struct.image.Planar;
|
||||
import pdl.backend.Algorithm.Parameters.Parameter;
|
||||
import pdl.backend.Algorithm.Parameters.ParameterNullPointerException;
|
||||
import pdl.backend.Area;
|
||||
import pdl.backend.Algorithm.Parameters.AreaParameter;
|
||||
|
||||
import pdl.backend.Image.ImageProcessing;
|
||||
|
||||
public class Algorithm {
|
||||
private final String name;
|
||||
@@ -26,12 +30,35 @@ public class Algorithm {
|
||||
|
||||
public void apply(Planar<GrayU8> image) {
|
||||
List<Object> para = this.parameters.stream().map(p -> p.getValue()).toList();
|
||||
boolean cropImage = false;
|
||||
for (Object p : para) {
|
||||
if (p == null) {
|
||||
throw new ParameterNullPointerException("Parameter not set");
|
||||
}
|
||||
}
|
||||
this.function.apply(image, para);
|
||||
for (var p : this.parameters) {
|
||||
if (p instanceof AreaParameter) {
|
||||
if (((AreaParameter) p).isCropImage()) {
|
||||
cropImage = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cropImage) {
|
||||
var aPara = (AreaParameter) this.parameters.stream().filter(p -> p instanceof AreaParameter).findFirst()
|
||||
.get();
|
||||
Area area = (Area) aPara.getValue();
|
||||
if (area.isEmpty()) {
|
||||
this.function.apply(image, para);
|
||||
} else {
|
||||
var tmp = image.clone();
|
||||
ImageProcessing.crop(tmp, area);
|
||||
this.function.apply(tmp, para);
|
||||
ImageProcessing.paste(tmp, image, area);
|
||||
}
|
||||
} else {
|
||||
this.function.apply(image, para);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -8,10 +8,22 @@ import pdl.backend.Area;
|
||||
public class AreaParameter extends Parameter {
|
||||
|
||||
private final Area area;
|
||||
private final boolean cropImage;
|
||||
|
||||
public AreaParameter(String name, String path) {
|
||||
super(name, path, "area");
|
||||
area = new Area(0, 0, 0, 0);
|
||||
this.cropImage = true;
|
||||
}
|
||||
|
||||
public AreaParameter(String name, String path, boolean cropImage) {
|
||||
super(name, path, "area");
|
||||
area = new Area(0, 0, 0, 0);
|
||||
this.cropImage = cropImage;
|
||||
}
|
||||
|
||||
public boolean isCropImage() {
|
||||
return this.cropImage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,19 +41,23 @@ public class AlgorithmController {
|
||||
final String[] newColors = { "RED", "GREEN", "BLUE", "YELLOW", "CYAN", "MAGENTA", "GREY" };
|
||||
ArrayList<Algorithm> algorithms = new ArrayList<Algorithm>();
|
||||
algorithms.add(new Algorithm("Changement de luminosité", "changeLuminosity",
|
||||
Arrays.asList(new IntegerParameter("Delta", "delta", -255, 255, 1)),
|
||||
Arrays.asList(new IntegerParameter("Delta", "delta", -255, 255, 1),
|
||||
new AreaParameter("Zone", "area")),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.changeLuminosity(input, (int) para.get(0));
|
||||
}));
|
||||
|
||||
algorithms.add(new Algorithm("Changement de teinte", "colorFilter",
|
||||
Arrays.asList(new IntegerParameter("Teinte", "hue", 0, 359, 1)),
|
||||
Arrays.asList(new IntegerParameter("Teinte", "hue", 0, 359, 1),
|
||||
new AreaParameter("Zone", "area")),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.colorFilter(input, (int) para.get(0));
|
||||
}));
|
||||
|
||||
algorithms.add(new Algorithm("Filtre Moyenneur", "meanFilter", Arrays.asList(
|
||||
new IntegerParameter("Taille du filtre", "size", 1, 21, 2),
|
||||
new SelectParameter("borderType", "Type de bordure", borderTypes)),
|
||||
new SelectParameter("borderType", "Type de bordure", borderTypes),
|
||||
new AreaParameter("Zone", "area")),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.meanFilter(input, (int) para.get(0), BorderType.valueOf((String) para.get(1)));
|
||||
}));
|
||||
@@ -61,34 +65,37 @@ public class AlgorithmController {
|
||||
algorithms.add(new Algorithm("Filtre Gaussien", "gaussienFilter", Arrays.asList(
|
||||
new IntegerParameter("Taille du filtre", "size", 1, 21, 2),
|
||||
new DoubleParameter("Sigma", "sigma", 0.1, 2, 0.1),
|
||||
new SelectParameter("Type de bordure", "borderType", borderTypes)),
|
||||
new SelectParameter("Type de bordure", "borderType", borderTypes),
|
||||
new AreaParameter("Zone", "area")),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.gaussienFilter(input, (int) para.get(0), (double) para.get(1),
|
||||
BorderType.valueOf((String) para.get(2)));
|
||||
}));
|
||||
|
||||
algorithms.add(new Algorithm("Détection de contours", "contours", new ArrayList<Parameter>(),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.gradientImageSobel(input);
|
||||
}));
|
||||
algorithms.add(
|
||||
new Algorithm("Détection de contours", "contours", Arrays.asList(new AreaParameter("Zone", "area")),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.gradientImageSobel(input);
|
||||
}));
|
||||
|
||||
algorithms.add(new Algorithm("Égalisation d'histogramme", "histogram", new ArrayList<Parameter>(),
|
||||
algorithms.add(new Algorithm("Égalisation d'histogramme", "histogram",
|
||||
Arrays.asList(new AreaParameter("Zone", "area")),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.histogram(input);
|
||||
}));
|
||||
|
||||
algorithms.add(new Algorithm("Filtre négatif", "negative", new ArrayList<Parameter>(),
|
||||
algorithms.add(new Algorithm("Filtre négatif", "negative", Arrays.asList(new AreaParameter("Zone", "area")),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.negativeFilter(input);
|
||||
}));
|
||||
|
||||
algorithms.add(new Algorithm("Filtre sépia", "sepia", new ArrayList<Parameter>(),
|
||||
algorithms.add(new Algorithm("Filtre sépia", "sepia", Arrays.asList(new AreaParameter("Zone", "area")),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.sepiaFilter(input);
|
||||
}));
|
||||
|
||||
algorithms.add(new Algorithm("Suppression zone", "deleteArea",
|
||||
Arrays.asList(new AreaParameter("Zone", "area"),
|
||||
Arrays.asList(new AreaParameter("Zone", "area", false),
|
||||
new SelectParameter("Type de remplissage", "fillingType", fillingTypes)),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.deleteArea(input, (Area) para.get(0),
|
||||
@@ -102,7 +109,7 @@ public class AlgorithmController {
|
||||
}));
|
||||
|
||||
algorithms.add(new Algorithm("Rognage", "crop",
|
||||
Arrays.asList(new AreaParameter("Zone", "area")),
|
||||
Arrays.asList(new AreaParameter("Zone", "area", false)),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.crop(input, (Area) para.get(0));
|
||||
}));
|
||||
@@ -117,6 +124,17 @@ public class AlgorithmController {
|
||||
(String) para.get(2), (boolean) para.get(3));
|
||||
}));
|
||||
|
||||
algorithms.add(new Algorithm("Saturation", "saturation",
|
||||
Arrays.asList(new DoubleParameter("Intensité", "intensity", 0, 1, 0.05)),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.saturation(input, (double) para.get(0));
|
||||
}));
|
||||
|
||||
algorithms.add(new Algorithm("Vignette", "vignette",
|
||||
Arrays.asList(new DoubleParameter("Puissance", "power", 0.05, 4, 0.05)),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.vignette(input, (double) para.get(0));
|
||||
}));
|
||||
return algorithms;
|
||||
}
|
||||
|
||||
|
||||
@@ -856,6 +856,33 @@ public final class ImageProcessing {
|
||||
input.setTo(output);
|
||||
}
|
||||
|
||||
/**
|
||||
* colle l'image input sur l'image output à partir de area
|
||||
*
|
||||
* @param input l'image à coller
|
||||
* @param output l'image sur laquelle on colle
|
||||
* @param area l'area à partir de laquelle on colle
|
||||
*/
|
||||
public static void paste(Planar<GrayU8> input, Planar<GrayU8> output, Area area) {
|
||||
if (area.isEmpty())
|
||||
throw new IllegalArgumentException("La zone est vide");
|
||||
int xMin = area.getxMin();
|
||||
int xMax = area.getxMax();
|
||||
int yMin = area.getyMin();
|
||||
int yMax = area.getyMax();
|
||||
if (xMin < 0 || xMax > output.width || yMin < 0 || yMax > output.height) {
|
||||
throw new IllegalArgumentException("Les coordonnées sont en dehors de l'image");
|
||||
}
|
||||
nbSteps = xMax - xMin + 1;
|
||||
BoofConcurrency.loopFor(xMin, xMax, i -> {
|
||||
for (int j = yMin; j <= yMax; j++) {
|
||||
setRGBValue(output, i, j, getRGBValue(input, i - xMin, j - yMin));
|
||||
}
|
||||
counter.incrementAndGet();
|
||||
});
|
||||
counter.set(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* retorune la valeur seuil d'en dessous (0-60-120-180-240-300)
|
||||
|
||||
Reference in new issue
Block a user