From 6c353cf4a1526c3dab2f510721d9f81ed309a6e4 Mon Sep 17 00:00:00 2001 From: Michael Innerberger Date: Wed, 27 Nov 2024 16:19:09 -0500 Subject: [PATCH] Add filter for affine intensity transformation --- .../filter/AffineIntensityFilter.java | 50 +++++++++++++++++++ .../filter/ExponentialIntensityFilter.java | 1 - 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 render-app/src/main/java/org/janelia/alignment/filter/AffineIntensityFilter.java diff --git a/render-app/src/main/java/org/janelia/alignment/filter/AffineIntensityFilter.java b/render-app/src/main/java/org/janelia/alignment/filter/AffineIntensityFilter.java new file mode 100644 index 000000000..f5f93ac44 --- /dev/null +++ b/render-app/src/main/java/org/janelia/alignment/filter/AffineIntensityFilter.java @@ -0,0 +1,50 @@ +package org.janelia.alignment.filter; + +import ij.process.ImageProcessor; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * A simple filter that applies an affine transformation y = a*x + b to the intensity values of an image. + */ +public class AffineIntensityFilter implements Filter { + + private double a; + private double b; + + // empty constructor required to create instances from specifications + @SuppressWarnings("unused") + public AffineIntensityFilter() { + this(0.0, 0.0); + } + + public AffineIntensityFilter(final double a, final double b) { + this.a = a; + this.b = b; + } + + @Override + public void init(final Map params) { + this.a = Filter.getDoubleParameter("a", params); + this.b = Filter.getDoubleParameter("b", params); + } + + @Override + public Map toParametersMap() { + final Map map = new LinkedHashMap<>(); + map.put("a", String.valueOf(a)); + map.put("b", String.valueOf(b)); + return map; + } + + @Override + public void process(final ImageProcessor ip, final double scale) { + for (int y = 0; y < ip.getHeight(); y++) { + for (int x = 0; x < ip.getWidth(); x++) { + final float intensity = ip.getf(x, y); + ip.setf(x, y, (float) (a * intensity + b)); + } + } + } +} diff --git a/render-app/src/main/java/org/janelia/alignment/filter/ExponentialIntensityFilter.java b/render-app/src/main/java/org/janelia/alignment/filter/ExponentialIntensityFilter.java index 6b4201f46..817526257 100644 --- a/render-app/src/main/java/org/janelia/alignment/filter/ExponentialIntensityFilter.java +++ b/render-app/src/main/java/org/janelia/alignment/filter/ExponentialIntensityFilter.java @@ -60,5 +60,4 @@ public void process(final ImageProcessor ip, final double scale) { } } } - }