From fc96c36c4308fd9fcd5b6f339da9a193d8221455 Mon Sep 17 00:00:00 2001 From: carlosuc3m <100329787@alumnos.uc3m.es> Date: Wed, 20 Nov 2024 12:09:18 +0100 Subject: [PATCH] add possibility of setting eps transformation --- .../transformations/BinarizeTransformation.java | 16 ++++++++++++++++ .../transformations/ClipTransformation.java | 15 +++++++++++++++ .../ScaleLinearTransformation.java | 15 +++++++++++++++ .../ScaleRangeTransformation.java | 16 +++++++++++++++- .../ZeroMeanUnitVarianceTransformation.java | 16 +++++++++++++++- 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/bioimage/modelrunner/transformations/BinarizeTransformation.java b/src/main/java/io/bioimage/modelrunner/transformations/BinarizeTransformation.java index 3d296e82..66ac5de0 100644 --- a/src/main/java/io/bioimage/modelrunner/transformations/BinarizeTransformation.java +++ b/src/main/java/io/bioimage/modelrunner/transformations/BinarizeTransformation.java @@ -30,6 +30,8 @@ public class BinarizeTransformation extends AbstractTensorPixelTransformation private static String name = "binarize"; private Double threshold; + private Double eps = Math.pow(10, -6); + public BinarizeTransformation() { @@ -37,6 +39,20 @@ public BinarizeTransformation() super.setDoubleUnitaryOperator(v -> ( v >= threshold ) ? 1d : 0d); } + public void setEps(Object eps) { + if (eps instanceof Integer) { + this.eps = Double.valueOf((int) eps); + } else if (eps instanceof Double) { + this.eps = (double) eps; + } else if (eps instanceof String) { + this.eps = Double.valueOf((String) eps); + } else { + throw new IllegalArgumentException("'eps' parameter has to be either and instance of " + + Float.class + " or " + Double.class + + ". The provided argument is an instance of: " + eps.getClass()); + } + } + public void setThreshold(Object threshold) { if (threshold instanceof Integer) { this.threshold = Double.valueOf((int) threshold); diff --git a/src/main/java/io/bioimage/modelrunner/transformations/ClipTransformation.java b/src/main/java/io/bioimage/modelrunner/transformations/ClipTransformation.java index fc06b023..39091155 100644 --- a/src/main/java/io/bioimage/modelrunner/transformations/ClipTransformation.java +++ b/src/main/java/io/bioimage/modelrunner/transformations/ClipTransformation.java @@ -31,6 +31,7 @@ public class ClipTransformation extends AbstractTensorPixelTransformation private static String name = "clip"; private Double min; private Double max; + private double eps = Math.pow(10, -6); public ClipTransformation() { @@ -38,6 +39,20 @@ public ClipTransformation() super.setDoubleUnitaryOperator(v -> v >= max ? max.doubleValue() : (v < min ? min.doubleValue() : v)); } + public void setEps(Object eps) { + if (eps instanceof Integer) { + this.eps = Double.valueOf((int) eps); + } else if (eps instanceof Double) { + this.eps = (double) eps; + } else if (eps instanceof String) { + this.eps = Double.valueOf((String) eps); + } else { + throw new IllegalArgumentException("'eps' parameter has to be either and instance of " + + Float.class + " or " + Double.class + + ". The provided argument is an instance of: " + eps.getClass()); + } + } + public void setMin(Object min) { if (min instanceof Integer) { this.min = Double.valueOf((int) min); diff --git a/src/main/java/io/bioimage/modelrunner/transformations/ScaleLinearTransformation.java b/src/main/java/io/bioimage/modelrunner/transformations/ScaleLinearTransformation.java index 1e03aa30..e693fd0c 100644 --- a/src/main/java/io/bioimage/modelrunner/transformations/ScaleLinearTransformation.java +++ b/src/main/java/io/bioimage/modelrunner/transformations/ScaleLinearTransformation.java @@ -41,12 +41,27 @@ public class ScaleLinearTransformation extends AbstractTensorTransformation private double[] gainArr; private double[] offsetArr; private String axes; + private double eps = Math.pow(10, -6); public ScaleLinearTransformation() { super( name ); } + public void setEps(Object eps) { + if (eps instanceof Integer) { + this.eps = Double.valueOf((int) eps); + } else if (eps instanceof Double) { + this.eps = (double) eps; + } else if (eps instanceof String) { + this.eps = Double.valueOf((String) eps); + } else { + throw new IllegalArgumentException("'eps' parameter has to be either and instance of " + + Float.class + " or " + Double.class + + ". The provided argument is an instance of: " + eps.getClass()); + } + } + public void setGain(Object gain) { if (gain instanceof Integer) { this.gainDouble = Double.valueOf((int) gain); diff --git a/src/main/java/io/bioimage/modelrunner/transformations/ScaleRangeTransformation.java b/src/main/java/io/bioimage/modelrunner/transformations/ScaleRangeTransformation.java index 2480916e..ef17a24b 100644 --- a/src/main/java/io/bioimage/modelrunner/transformations/ScaleRangeTransformation.java +++ b/src/main/java/io/bioimage/modelrunner/transformations/ScaleRangeTransformation.java @@ -47,13 +47,27 @@ public class ScaleRangeTransformation extends AbstractTensorTransformation private String axes; private Mode mode = Mode.PER_SAMPLE; private String tensorName; - private float eps = (float) Math.pow(10, -6); + private double eps = Math.pow(10, -6); public ScaleRangeTransformation() { super( name ); } + public void setEps(Object eps) { + if (eps instanceof Integer) { + this.eps = Double.valueOf((int) eps); + } else if (eps instanceof Double) { + this.eps = (double) eps; + } else if (eps instanceof String) { + this.eps = Double.valueOf((String) eps); + } else { + throw new IllegalArgumentException("'eps' parameter has to be either and instance of " + + Float.class + " or " + Double.class + + ". The provided argument is an instance of: " + eps.getClass()); + } + } + public void setMinPercentile(Object minPercentile) { if (minPercentile instanceof Integer) { this.minPercentile = Double.valueOf((int) minPercentile) / 100; diff --git a/src/main/java/io/bioimage/modelrunner/transformations/ZeroMeanUnitVarianceTransformation.java b/src/main/java/io/bioimage/modelrunner/transformations/ZeroMeanUnitVarianceTransformation.java index 8baa8d51..1993de11 100644 --- a/src/main/java/io/bioimage/modelrunner/transformations/ZeroMeanUnitVarianceTransformation.java +++ b/src/main/java/io/bioimage/modelrunner/transformations/ZeroMeanUnitVarianceTransformation.java @@ -46,7 +46,7 @@ public class ZeroMeanUnitVarianceTransformation extends AbstractTensorTransforma private double[] stdArr; private Mode mode = Mode.PER_SAMPLE; private String axes; - private float eps = (float) Math.pow(10, -6); + private double eps = Math.pow(10, -6); private static String FIXED_MODE_ERR = "If the mode is 'fixed', the parameters 'mean' and" + " 'std need to be specified"; @@ -58,6 +58,20 @@ public ZeroMeanUnitVarianceTransformation() super( name ); } + public void setEps(Object eps) { + if (eps instanceof Integer) { + this.eps = Double.valueOf((int) eps); + } else if (eps instanceof Double) { + this.eps = (double) eps; + } else if (eps instanceof String) { + this.eps = Double.valueOf((String) eps); + } else { + throw new IllegalArgumentException("'eps' parameter has to be either and instance of " + + Float.class + " or " + Double.class + + ". The provided argument is an instance of: " + eps.getClass()); + } + } + public void setMean(Object mean) { if (mean instanceof Integer) { this.meanDouble = Double.valueOf((int) mean);