-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filter for affine intensity transformation
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
render-app/src/main/java/org/janelia/alignment/filter/AffineIntensityFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,5 +60,4 @@ public void process(final ImageProcessor ip, final double scale) { | |
} | ||
} | ||
} | ||
|
||
} |