Area delete zone crop
This commit is contained in:
1 parent
db2269f26c
commit
e101341549
10 files changed
+199
-53
No files matched your search
@@ -3,23 +3,21 @@ package pdl.backend.Algorithm.Parameters;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
|
||||
import pdl.backend.Area;
|
||||
|
||||
public class AreaParameter extends Parameter {
|
||||
|
||||
private final Area area;
|
||||
|
||||
public AreaParameter(String name, String path) {
|
||||
super(name, path, "area");
|
||||
area = new Area(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(String value) {
|
||||
String[] values = value.split(";");
|
||||
if (values.length != 4) {
|
||||
throw new IllegalArgumentException("Area parameter must have 4 values");
|
||||
}
|
||||
int[] intValues = new int[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
intValues[i] = Integer.parseInt(values[i]);
|
||||
}
|
||||
super.setValueObject(intValues);
|
||||
this.area.setValues(value);
|
||||
super.setValueObject(this.area);
|
||||
}
|
||||
|
||||
public ObjectNode getNode(ObjectMapper mapper) {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package pdl.backend;
|
||||
|
||||
public class Area {
|
||||
private int xMin;
|
||||
private int yMin;
|
||||
private int xMax;
|
||||
private int yMax;
|
||||
|
||||
public Area(int xMin, int yMin, int xMax, int yMax) {
|
||||
this.xMin = xMin;
|
||||
this.yMin = yMin;
|
||||
this.xMax = xMax;
|
||||
this.yMax = yMax;
|
||||
}
|
||||
|
||||
public Area(String str) {
|
||||
this.setValues(str);
|
||||
}
|
||||
|
||||
public void setValues(String str) {
|
||||
String[] values = str.split(";");
|
||||
if (values.length != 4) {
|
||||
throw new IllegalArgumentException("Area parameter must have 4 values");
|
||||
}
|
||||
int[] intValues = new int[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
intValues[i] = Integer.parseInt(values[i]);
|
||||
}
|
||||
this.xMin = intValues[0];
|
||||
this.yMin = intValues[1];
|
||||
this.xMax = intValues[2];
|
||||
this.yMax = intValues[3];
|
||||
}
|
||||
|
||||
public int getxMin() {
|
||||
return xMin;
|
||||
}
|
||||
|
||||
public void setxMin(int xMin) {
|
||||
this.xMin = xMin;
|
||||
}
|
||||
|
||||
public int getyMin() {
|
||||
return yMin;
|
||||
}
|
||||
|
||||
public void setyMin(int yMin) {
|
||||
this.yMin = yMin;
|
||||
}
|
||||
|
||||
public int getxMax() {
|
||||
return xMax;
|
||||
}
|
||||
|
||||
public void setxMax(int xMax) {
|
||||
this.xMax = xMax;
|
||||
}
|
||||
|
||||
public int getyMax() {
|
||||
return yMax;
|
||||
}
|
||||
|
||||
public void setyMax(int yMax) {
|
||||
this.yMax = yMax;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return xMin == 0 && yMin == 0 && xMax == 0 && yMax == 0;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import boofcv.struct.border.BorderType;
|
||||
import boofcv.struct.image.GrayU8;
|
||||
import boofcv.struct.image.Planar;
|
||||
import pdl.backend.Area;
|
||||
import pdl.backend.Algorithm.Algorithm;
|
||||
import pdl.backend.Algorithm.Parameters.AreaParameter;
|
||||
import pdl.backend.Algorithm.Parameters.DoubleParameter;
|
||||
@@ -30,7 +31,9 @@ public class AlgorithmController {
|
||||
@Autowired
|
||||
private ObjectMapper mapper;
|
||||
|
||||
public static List<Algorithm> algorithmList() {
|
||||
public final static List<Algorithm> ALGORITHMS = algorithmList();
|
||||
|
||||
private final static List<Algorithm> algorithmList() {
|
||||
final String[] borderTypes = { "SKIP", "ZERO", "NORMALIZED", "REFLECT", "EXTENDED", "WRAP" };
|
||||
final String[] fillingTypes = { "SKIP", "CONVOLUTION", "LEFT", "RIGHT", "TOP", "BOTTOM" };
|
||||
ArrayList<Algorithm> algorithms = new ArrayList<Algorithm>();
|
||||
@@ -81,16 +84,22 @@ public class AlgorithmController {
|
||||
ImageProcessing.sepiaFilter(input);
|
||||
}));
|
||||
algorithms.add(new Algorithm("Suppression zone", "deleteArea",
|
||||
Arrays.asList(new AreaParameter("area", "Zone"),
|
||||
Arrays.asList(new AreaParameter("Zone", "area"),
|
||||
new SelectParameter("fillingType", "Type de remplissage", fillingTypes)),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.deleteArea(input, (int[]) para.get(0), FillingType.valueOf((String) para.get(1)));
|
||||
ImageProcessing.deleteArea(input, (Area) para.get(0),
|
||||
FillingType.valueOf((String) para.get(1)));
|
||||
}));
|
||||
algorithms.add(new Algorithm("Filtre de bruit", "noise",
|
||||
Arrays.asList(new IntegerParameter("intensity", "Intensité", 1, 100, 1)),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.gaussianNoiseFilter(input, (int) para.get(0));
|
||||
}));
|
||||
algorithms.add(new Algorithm("Rognage", "crop",
|
||||
Arrays.asList(new AreaParameter("Zone", "area")),
|
||||
(Planar<GrayU8> input, List<Object> para) -> {
|
||||
ImageProcessing.crop(input, (Area) para.get(0));
|
||||
}));
|
||||
return algorithms;
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ public class ImageController {
|
||||
return ResponseEntity.ok().contentType(imageToFilter.getMediaType())
|
||||
.body(new InputStreamResource(inputStream));
|
||||
}
|
||||
final List<Algorithm> algos = AlgorithmController.algorithmList();
|
||||
final List<Algorithm> algos = AlgorithmController.ALGORITHMS;
|
||||
// Vérifie la présence du paramètre "algorithm"
|
||||
if (!parameters.containsKey("algorithm")) {
|
||||
return JSONError("First parameter should be 'algorithm'", HttpStatus.BAD_REQUEST);
|
||||
@@ -211,7 +211,6 @@ public class ImageController {
|
||||
}
|
||||
try {
|
||||
a.apply(input);
|
||||
|
||||
} catch (Exception e) {
|
||||
return JSONError("There was an internal server error", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package pdl.backend.Image;
|
||||
import boofcv.struct.border.BorderType;
|
||||
import boofcv.struct.image.GrayU8;
|
||||
import boofcv.struct.image.Planar;
|
||||
import pdl.backend.Area;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -673,14 +674,14 @@ public final class ImageProcessing {
|
||||
* @param area Les coordonnées de la zone à supprimer
|
||||
* @param filling Le type de remplissage
|
||||
*/
|
||||
public static void deleteArea(Planar<GrayU8> input, int[] area, FillingType filling) {
|
||||
if (area.length != 4) {
|
||||
throw new IllegalArgumentException("Les coordonnées sont incorrectes");
|
||||
public static void deleteArea(Planar<GrayU8> input, Area area, FillingType filling) {
|
||||
if (area.isEmpty()) {
|
||||
throw new IllegalArgumentException("La zone est vide");
|
||||
}
|
||||
int xMin = area[0];
|
||||
int xMax = area[1];
|
||||
int yMin = area[2];
|
||||
int yMax = area[3];
|
||||
int xMin = area.getxMin();
|
||||
int xMax = area.getxMax();
|
||||
int yMin = area.getyMin();
|
||||
int yMax = area.getyMax();
|
||||
if (xMin < 0 || xMax > input.width || yMin < 0 || yMax > input.height) {
|
||||
throw new IllegalArgumentException("Les coordonnées sont en dehors de l'image");
|
||||
}
|
||||
@@ -796,4 +797,29 @@ public final class ImageProcessing {
|
||||
});
|
||||
counter.set(-1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rogne l'image en fonction de l'area donnée en paramètre
|
||||
*
|
||||
* @param input L'image à rogner
|
||||
* @param area L'area à utiliser pour rogner l'image
|
||||
*/
|
||||
public static void crop(Planar<GrayU8> input, 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 > input.width || yMin < 0 || yMax > input.height) {
|
||||
throw new IllegalArgumentException("Les coordonnées sont en dehors de l'image");
|
||||
}
|
||||
Planar<GrayU8> output = new Planar<>(GrayU8.class, xMax - xMin + 1, yMax - yMin + 1, input.getNumBands());
|
||||
for (int i = xMin; i <= xMax; i++) {
|
||||
for (int j = yMin; j <= yMax; j++) {
|
||||
setRGBValue(output, i - xMin, j - yMin, getRGBValue(input, i, j));
|
||||
}
|
||||
}
|
||||
input.setTo(output);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user