Login  Register

Image calculator behaves differently in plug in

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Image calculator behaves differently in plug in

jvander
Image calculator behaves differently in plug in

I have some 8 bit images which happen to be binary valued, 0 and 255.  White is 255 and Black is zero.  When I use Image calculator from the menu I get expected results for all the operators including AND, Mult, OR , and Add.  

Right now I am trying to do the following
mask image called A with 1   result is image called A1
mask image called B with 2 result is image called B2
OR together A1 and B2

The first time I run the plug in the masking works and the OR gives unexpected results
The second time I run things the masking is inverted compared to the first run.

Clearly I have some bad syntax.  Help is appreciated.  Below is my code


import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import ij.plugin.frame.*;

public class kinetic_combine_three implements PlugIn {

        public void run(String arg) {
                IJ.run("Image Calculator...", "image1=1 AND image2=A create");
                IJ.run("Rename...","title=A1");
                IJ.run("Image Calculator...", "image1=B AND image2=2 create");
                IJ.run("Rename...","title=B2");
                    IJ.run("Image Calculator...", "image1=A1 OR image2=B2 create");
                IJ.run("Rename...","title=A1B2");
     
        }

}

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Image calculator behaves differently in plug in

Rasband, Wayne (NIH/NIMH) [E]
On May 2, 2013, at 12:49 PM, Joe Vandergracht wrote:

> Image calculator behaves differently in plug in
>
> I have some 8 bit images which happen to be binary valued, 0 and 255.  White is 255 and Black is zero.  When I use Image calculator from the menu I get expected results for all the operators including AND, Mult, OR , and Add.  
>
> Right now I am trying to do the following
> mask image called A with 1   result is image called A1
> mask image called B with 2 result is image called B2
> OR together A1 and B2
>
> The first time I run the plug in the masking works and the OR gives unexpected results
> The second time I run things the masking is inverted compared to the first run.
>
> Clearly I have some bad syntax.  Help is appreciated.  Below is my code

Use the command recorder (Plugins>Macros>Record) to generate the needed code. Here is an example, created using the recorder, that creates two test images and uses the Image Calculator to AND and OR them. You can run it by copying the code to the clipboard, switching to ImageJ, typing shift-n (File>New>Text Window), typing ctrl-v (Edit>Paste) and typing ctrl-b (Macro>Evaluate BeanShell). You will need to be running at least ImageJ 1.47e, which adds support for BeanShell scripting.

  ImagePlus imp1 = IJ.createImage("imp1", "8-bit Black", 500, 500, 1);
  imp1.setRoi(new OvalRoi(47, 40, 218, 219));
  IJ.run(imp1, "Invert", "slice");
  imp1.setRoi(new OvalRoi(229, 215, 218, 219));
  IJ.run(imp1, "Invert", "slice");
  ImagePlus imp2 = IJ.createImage("imp2", "8-bit Black", 500, 500, 1);
  imp2.setRoi(new OvalRoi(156, 127, 208, 208));
  IJ.run(imp2, "Invert", "slice");
  ImageCalculator ic = new ImageCalculator();
  ImagePlus imp3 = ic.run("AND create", imp1, imp2);
  imp3.setTitle("imp1 AND imp2");
  imp3.show();
  imp3 = ic.run("OR create", imp1, imp2);
  imp3.setTitle("imp1 OR imp2");
  imp3.show();
  imp1.show();
  imp2.show();

-wayne


> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import ij.plugin.*;
> import ij.plugin.frame.*;
>
> public class kinetic_combine_three implements PlugIn {
>
> public void run(String arg) {
> IJ.run("Image Calculator...", "image1=1 AND image2=A create");
> IJ.run("Rename...","title=A1");
> IJ.run("Image Calculator...", "image1=B AND image2=2 create");
> IJ.run("Rename...","title=B2");
>                    IJ.run("Image Calculator...", "image1=A1 OR image2=B2 create");
> IJ.run("Rename...","title=A1B2");
>
> }
>
> }

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html