Posted by
BenTupper on
URL: http://imagej.273.s1.nabble.com/Infinity-values-tp3686956p3686960.html
Hi,
On Sep 12, 2010, at 2:54 PM, Francis Burton wrote:
> Hi,
>
> I'm running a plugin (Ratio Plus) that creates an image with pixel
> values equal to Infinity, as a result of zero divisions. I would
> like these pixels to have some other value, so that I can decide
> what colour they will appear as. Setting the "Divide by zero value"
> in Edit/Options/Misc... doesn't work, presumably because it only
> applies to the built-in image arithmetic and not variables in
> plugins. So is there an easy (i.e. menu item ) way I can turn all
> Infinity values into some other value? Alternatively, could this
> function be implemented in a macro? Or would I have to write a
> plugin to do it (or modify the original plugin)?
>
I think it would be fastest to update your plugin and recompile. But
in lieu of that, the attached macro will replace a target value with
some replacement value. In a 32-bit is required for this to work with
Infinity. You can call this from a plugin and optionally specify the
target and replacement values.
Cheers,
Ben
//// Replace_Value.ijm - save it in ImageJ/macros directory
args = getArgument();
repValue = 0.0;
targetValue = 1.0;
Infinity = 1.0/0.0;
if (lengthOf(args) == 0){
Dialog.create("Pixel replacement value");
Dialog.addNumber("Target value", targetValue);
Dialog.addNumber("Replacement value", repValue);
Dialog.show();
targetValue = Dialog.getNumber();
repValue = Dialog.getNumber();
} else {
s = split(args);
for (i = 0; i < s.length; i++){
t = split(toLowerCase(s[i]), "=");
if (t[0] == "target"){
if (t[1] == "infinity") {
targetValue = Infinity;
} else {
targetValue = parseFloat(t[1]);
}
}
if (t[0] == "replacement"){
if (t[1] == "infinity") {
repValue = Infinity;
} else {
repValue = parseFloat(t[1]);
}
}
} // i-loop
} //args??
h = getHeight();
w = getWidth();
for (y = 0; y < h; y++){
for ( x = 0; x < w; x++){
p = getPixel(x,y);
if (p == targetValue){ setPixel(x,y,repValue); }
}
}
////// Example Plugin
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.filter.*;
public class Filter_Plugin implements PlugInFilter {
ImagePlus imp;
public int setup(String arg, ImagePlus imp) {
this.imp = imp;
return DOES_32;
}
public void run(ImageProcessor ip) {
//IJ.runMacroFile("Replace_Value.ijm", "target=Infinity
replacement=30.0");
IJ.runMacroFile("Replace_Value.ijm");
}
}