Quantcast

Infinity values

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Infinity values

Francis Burton-2
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)?

Cheers,
Francis
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Infinity values

BenTupper
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");
        }

}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Infinity values

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by Francis Burton-2
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)?

You can use the changeValues() macro function to do this. For example

  changeValues(1/0, 1/0, 0);

changes all the Infinity values in the current image to zero.

-wayne
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Infinity values

Michael Schmid-3
In reply to this post by Francis Burton-2
Hi Francis,

you can use Process>Math>Max so set infinity pixels to a high value  
(e.g. 1e10). Of course, pixels with a value larger than this value  
will be also set to the maximum chosen by you.

Michael
________________________________________________________________

On 12 Sep 2010, at 20:54, 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)?
>
> Cheers,
> Francis
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Infinity values

Francis Burton-2
In reply to this post by Rasband, Wayne (NIH/NIMH) [E]
Many thanks to Ben, Wayne and Michael for their answers. This really is
a
most responsive and helpful forum.

I followed Ben's suggestion and modified the plugin source. I added a
field
to allow the user to specify which value should be used to represent the
ratio when the divisor is 0, with the default value taken from
preferences:

import ij.process.*;
...
// Use "divide by zero" value from Edit/Options/Misc... as default
dz = (float)FloatBlitter.divideByZeroValue;

So I didn't use Ben's macro in the end, though it might prove useful to
someone else. Everything from "h = getHeight();" onwards can presumably
be
replaced with

changeValues(targetValue, targetValue, repValue);

as per Wayne's suggestion.

Francis
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Infinity values

Javier Casas
Dear Francis,

Could you share the Ratio Plus plugin? I´m trying to modify it in order to set infinity values to zero, but I´m not getting any improvement.
 

Javier Casas
Loading...