pluginsimagejimagej-macro

How to call Z-functions from a plugin on ImageJ


Good Morning

I'm currently doing a plugIn for ImageJ in JAVA that needs to call the function "Maximum Intensity Z-projection", which I know that is already in ImageJ if you go for "Image/Stacks/Z Project...". Documentation here: http://imagej.net/Z-functions#Maximum_Intensity_Z-projection

I know how to call plugins from another plugins, but doing the same thing in this case I get all the time my "Error" message.

public class Maximum_Intensity implements PlugIn{
    ImagePlus img = WindowManager.getCurrentImage();
    @Override
    public void run(String arg0) {
        // TODO Auto-generated method stub
        Object ZProjector = null;
        ZProjector = IJ.runPlugIn(img, "ZProjector", arg0);

        if(ZProjector==null){
            String arg = "Error";
            IJ.showMessage(arg);
        }
    }
}

How can I do it? Thank you so much.


Solution

  • You can easily use the macro recorder for help to record all commands in ImageJ, see:

    https://imagej.nih.gov/ij/docs/guide/146-31.html#sub:Record...

    Enable Java for the recorder and then use the "Create" action to create an ImageJ plugin from the recorded interface actions.

    In the following example (created with the Recorder) I applied the Max. Intensity function on a stack.

    import ij.*;
    import ij.process.*;
    import ij.gui.*;
    import java.awt.*;
    import ij.plugin.*;
    
    public class My_Plugin implements PlugIn {
    
        public void run(String arg) {
            ImagePlus imp = IJ.openImage("http://imagej.nih.gov/ij/images/mri-stack.zip");
            IJ.run(imp, "Z Project...", "projection=[Max Intensity]");
            imp.show();
        }
    
    }
    

    The ZProjector class description can be found here (for instantiation):

    https://imagej.nih.gov/ij/developer/api/ij/plugin/ZProjector.html