Skip to content

Commit

Permalink
Add filter for affine intensity transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
minnerbe committed Nov 27, 2024
1 parent b4f051d commit 6c353cf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<String, String> params) {
this.a = Filter.getDoubleParameter("a", params);
this.b = Filter.getDoubleParameter("b", params);
}

@Override
public Map<String, String> toParametersMap() {
final Map<String, String> 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));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,4 @@ public void process(final ImageProcessor ip, final double scale) {
}
}
}

}

0 comments on commit 6c353cf

Please sign in to comment.