front ok back ok just borders

This commit is contained in:
Theophyl Hoguet committed 2023-04-01 17:10:33 +02:00
1 parent 922eb0a905
commit 539af71440
7 files changed
+38 -53

No files matched your search

@@ -29,7 +29,7 @@ public class AlgorithmController {
private ObjectMapper mapper;
public static List<Algorithm> algorithmList() {
final String[] borderTypes = { "SKIP", "ZERO", "NORMALIZED", "REFLECT", "EXTEND", "WRAP" };
final String[] borderTypes = { "SKIP", "ZERO", "NORMALIZED", "REFLECT", "EXTENDED", "WRAP" };
ArrayList<Algorithm> algorithms = new ArrayList<Algorithm>();
algorithms.add(new Algorithm("Changement de luminosité", "changeLuminosity",
Arrays.asList(new IntegerParameter("delta", "delta", -255, 255, 1)),
@@ -202,9 +202,17 @@ public class ImageController {
if (!parameters.containsKey(p.getName())) {
return JSONError("Parameter '" + p.getName() + "' is missing", HttpStatus.BAD_REQUEST);
}
p.setValue(parameters.get(p.getName()));
try {
p.setValue(parameters.get(p.getName()));
} catch (Exception e) {
return JSONError("Parameter '" + p.getName() + "' is invalid", HttpStatus.BAD_REQUEST);
}
}
try {
a.apply(input);
} catch (Exception e) {
return JSONError("There was an internal server error", HttpStatus.INTERNAL_SERVER_ERROR);
}
a.apply(input);
break;
}
}
@@ -295,7 +295,6 @@ public final class ImageProcessing {
* @param borderType type de bord à utiliser pour la convolution
*/
public static void meanFilter(Planar<GrayU8> input, int size, BorderType borderType) {
Planar<GrayU8> output = input.createSameShape();
// Vérification que la taille est impaire
if (size % 2 == 0 || size < 0) {
throw new IllegalArgumentException(
@@ -308,12 +307,6 @@ public final class ImageProcessing {
}
}
convolution(input, kernel, borderType);
for (int i = 0; i < input.width; i++) {
for (int j = 0; j < input.height; j++) {
int[] rgb = getRGBValue(output, i, j);
setRGBValue(input, i, j, rgb);
}
}
}
/**
@@ -327,7 +320,6 @@ public final class ImageProcessing {
* @param borderType Le type de bord à utiliser pour la convolution
*/
public static void gaussienFilter(Planar<GrayU8> input, int size, double sigma, BorderType borderType) {
Planar<GrayU8> output = input.createSameShape();
if (size % 2 == 0 || size < 0 || sigma <= 0) {
throw new IllegalArgumentException(
"La taille doit être impaire et positive et sigma doit être strictement positif");
@@ -364,13 +356,6 @@ public final class ImageProcessing {
}
}
convolution(input, kernelInt, borderType);
// copy all output pixels to input
for (int i = 0; i < input.width; i++) {
for (int j = 0; j < input.height; j++) {
int[] rgb = getRGBValue(output, i, j);
setRGBValue(input, i, j, rgb);
}
}
}
/**
@@ -383,7 +368,7 @@ public final class ImageProcessing {
* @param borderType Le type de bord à utiliser pour la convolution
*/
public static void convolution(Planar<GrayU8> input, int[][] kernel, BorderType borderType) {
Planar<GrayU8> output = input.createSameShape();
Planar<GrayU8> copy = input.clone();
int size = kernel.length;
int half = kernel.length / 2;
int coefs = 0;
@@ -401,9 +386,9 @@ public final class ImageProcessing {
if (y < half || x < half || y >= input.height - half || x >= input.width -
half) {
if (borderType == BorderType.SKIP) {
setRGBValue(output, x, y, getRGBValue(input, x, y));
setRGBValue(input, x, y, getRGBValue(copy, x, y));
} else if (borderType == BorderType.ZERO) {
setRGBValue(output, x, y, new int[] { 0, 0, 0 });
setRGBValue(input, x, y, new int[] { 0, 0, 0 });
} else {
int totalValue[] = new int[3];
int coefsUsed = 0;
@@ -434,8 +419,7 @@ public final class ImageProcessing {
}
}
for (int k = 0; k < totalValue.length; k++) {
totalValue[k] += input.getBand(k).get(tmpi, tmpj)
* kernel[tmpi][tmpj];
totalValue[k] += copy.getBand(k).get(tmpi, tmpj) * kernel[tmpi][tmpj];
}
coefsUsed += kernel[tmpi][tmpj];
}
@@ -454,7 +438,7 @@ public final class ImageProcessing {
for (int j = y - half; j <= y + half; j++) {
for (int i = x - half; i <= x + half; i++) {
for (int k = 0; k < totalValue.length; k++) {
totalValue[k] += input.getBand(k).get(i, j) * kernel[currentJ][currentI];
totalValue[k] += copy.getBand(k).get(i, j) * kernel[currentJ][currentI];
}
currentI++;
}
@@ -464,14 +448,8 @@ public final class ImageProcessing {
for (int k = 0; k < totalValue.length; k++) {
totalValue[k] /= totalCoefs;
}
setRGBValue(output, x, y, totalValue);
setRGBValue(input, x, y, totalValue);
}
});
for (int i = 0; i < input.width; i++) {
for (int j = 0; j < input.height; j++) {
int[] rgb = getRGBValue(output, i, j);
setRGBValue(input, i, j, rgb);
}
}
}
}
+2 -4
View File
@@ -112,10 +112,8 @@ html {
}
:deep(.imageContainer) {
max-width: 60%;
width: auto;
height: auto;
max-height: 60vh;
max-width: min(60vh, 60vw);
max-height: min(60vh, 60vw);
transform: none;
}
</style>
+6 -5
View File
@@ -29,11 +29,11 @@ export default defineComponent({
for (const arg of filter.parameters) {
if (arg.type === FilterType.range) {
const range = arg as RangeParameters;
range.value = (range.max - Math.abs(range.min)) / 2;
range.value = range.min;
}
else if (arg.type === FilterType.select) {
const select = arg as SelectParameters;
select.value = 0;
select.value = select.options[0];
}
}
}
@@ -94,12 +94,13 @@ export default defineComponent({
:step="(parameter as RangeParameters).step" v-model.number="parameter.value" :id="parameter.name" />
</div>
<input type="range" :min="(parameter as RangeParameters).min" :max="(parameter as RangeParameters).max"
:step="(parameter as RangeParameters).step" v-model.number="parameter.value" />
:step="(parameter as RangeParameters).step" v-model.number="(parameter as RangeParameters).value" />
</div>
<div v-else-if="parameter.type === FilterType.select" class="selectParam">
<label>{{ parameter.name }}: </label>
<CustomSelector :list="(parameter as SelectParameters).options" :selected="parameter.value"
@update-selected="parameter.value = $event" />
<CustomSelector :list="(parameter as SelectParameters).options"
:selected="(parameter as SelectParameters).options.findIndex((o) => o === (parameter as SelectParameters).value)"
@update-selected="parameter.value = (parameter as SelectParameters).options[$event]" />
</div>
</div>
<button @mouseenter="error = areInputValid()" @mouseleave="error = areInputValid()" class="button"
+1 -3
View File
@@ -73,9 +73,7 @@ export default defineComponent({
<style>
.imageContainer img {
max-width: 100%;
max-height: 100vh;
height: auto;
width: auto;
max-height: 100%;
object-fit: contain;
}
+12 -10
View File
@@ -7,13 +7,12 @@ export enum FilterType {
export abstract class Parameters {
name: string
displayName: string
value: number
type: FilterType
value: any
constructor(name: string, displayName: string, value: any = undefined, type: FilterType) {
constructor(name: string, displayName: string, type: FilterType) {
this.name = name
this.displayName = displayName
this.value = value
this.type = type
}
@@ -23,9 +22,10 @@ export class RangeParameters extends Parameters {
min: number
max: number
step: number
constructor(name: string, displayName: string, min: number, max: number, step: number) {
const value = max / 2;
super(name, displayName, value, FilterType.range)
value: number
constructor(name: string, displayName: string, min: number, max: number, step: number, value: number = min) {
super(name, displayName, FilterType.range)
this.value = value;
this.min = min
this.max = max
this.step = step
@@ -34,8 +34,10 @@ export class RangeParameters extends Parameters {
export class SelectParameters extends Parameters {
options: string[]
constructor(name: string, displayName: string, options: string[]) {
super(name, displayName, 0, FilterType.select)
value: string
constructor(name: string, displayName: string, options: string[], value = options[0]) {
super(name, displayName, FilterType.select)
this.value = value;
this.options = options
}
}
@@ -73,10 +75,10 @@ export function clone(f: Filter): Filter {
switch (param.type) {
case FilterType.range:
const paramCastRange = param as RangeParameters
return new RangeParameters(param.name, param.displayName, paramCastRange.min, paramCastRange.max, paramCastRange.step)
return new RangeParameters(param.name, param.displayName, paramCastRange.min, paramCastRange.max, paramCastRange.step, paramCastRange.value)
case FilterType.select:
const paramCastSelect = param as SelectParameters
return new SelectParameters(param.name, param.displayName, paramCastSelect.options)
return new SelectParameters(param.name, param.displayName, paramCastSelect.options, paramCastSelect.value)
}
}))
}