Need help for convert recorded ImageJ Macro to Plugin

java
scijava
Tags: #<Tag:0x00007fb87e05dd20> #<Tag:0x00007fb87e05dac8>

#1

Hi everyone, folks
I have throube. I record macro in IntelliJ that looks as:

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("/home/lanabanana/Документы/ДИПЛОМ/Изображения/SI_20160122_1_disp_geo_VD_ql.tif");
        IJ.run(imp, "8-bit", "");
        IJ.run(imp, "Gray Morphology", "radius=5 type=[free form] operator=erode text1=[ 0 0 0 0 0  0 0 255 0 0  0 255 255 255 0  0 0 255 0 0  0 0 0 0 0 ]");
        //IJ.setTool("rectangle");
        imp.setRoi(532,468,1578,742);
        IJ.run(imp, "Find Edges", "");
        IJ.run(imp, "Crop", "");
        IJ.saveAs(imp, "Tiff", "/home/lanabanana/Документы/ДИПЛОМ/Изображения/out.tif");
    }

}

And I need to convert it to @Plugin in IntelliJ IDEA. I created Gauss example, but I dont understand how to convert my Macro to Plugin. My Gauss Plugin example looks so:

@Plugin(type = Command.class, menuPath = "Plugins>LanaBanana")
public class LanaBanana<T extends RealType<T>> implements Command {
    //
    // Feel free to add more parameters here...
    //

    @Parameter
    private Dataset currentData;

    @Parameter
    private UIService uiService;

    @Parameter
    private OpService opService;

    @Override
    public void run() {

        //
        // Enter image processing code here ...
        // The following is just a Gauss filtering example
        //
        final double[] sigmas = {1.0, 3.0, 5.0};

        List<RandomAccessibleInterval<T>> results = new ArrayList<>();


        final Img<T> image = (Img<T>) currentData.getImgPlus();

        for (double sigma : sigmas) {
            results.add(opService.filter().gauss(image, sigma));
        }

        // display result
        for (RandomAccessibleInterval<T> elem : results) {
            uiService.show(elem);

        }
    }


    /**
     * This main function serves for development purposes.
     * It allows you to run the plugin immediately out of
     * your integrated development environment (IDE).
     *
     * @param args whatever, it's ignored
     * @throws Exception
     */
    public static void main(final String... args) throws Exception {
        // create the ImageJ application context with all available services
        final ImageJ ij = new ImageJ();
        ij.ui().showUI();


        // ask the user for a file to open
        final File file = ij.ui().chooseFile(null, "open");

        if (file != null) {
            // load the dataset
            final Dataset dataset = ij.scifio().datasetIO().open(file.getPath());

            // show the image
            ij.ui().show(dataset);


            // invoke the plugin
            ij.command().run(LanaBanana.class, true);


        }

    }
}

Can anyone help to convert or explain how to do it myself. I have limitations in time because it is my project for examination, but I can’t find any examples for converting. My teachers also does’nt may to help me… I’m sorrow. Please, help me…

Thank you very much.


#2

@opsolut

I’m not sure exactly the issue here… Did you read over this “Writing Plugins” page on the ImageJ wiki?? For example… A Command is a plugin - so you are on the right track there.

Perhaps you can be a bit more specific with what you need help with exactly?

eta


#3

Yes, i do, but cannot find examples. I try to explain. I gotta rewrite code from:

ImagePlus imp = IJ.openImage(…) and then series of IJ.run(…) to

series like of results.add(opService.filter().gauss(image, sigma))

But I don’t understand how to rewrite my recorded macro for use existing filters and plugins programmaticaly. May be some example how to use this:

IJ.run(imp, “Gray Morphology”, “radius=5 type=[free form] operator=erode text1=[ 0 0 0 0 0 0 0 255 0 0 0 255 255 255 0 0 0 255 0 0 0 0 0 0 0 ]”)

programmaticaly as Command implementation?
Thanks