Search code examples
javapluginsimagej

Implementing ImageJ macro commands into an existing Plugin


I'm trying to change the existing plugin OpenComet for ImageJ. I'm not into Java, so perhaps it's an easy task.

What I'm trying to implement are the following things

  1. run("Bio-Formats Windowless Importer", "open=path autoscale color_mode=Default view=Hyperstack stack_order=XYCZT");
    opening my files with the help of the Bioformat Importer plugin

  2. run("Flip Horizontally");

This is supposed to be placed into the following code:

// Iterate over each input file
            for(int i=0;i<inFiles.length;i++){
                // Try to open file as image
//NUMBER 1 BIOFORMAT IMPORT AT THIS POINT               
                ImagePlus imp = IJ.openImage(inFiles[i].getPath());
                                // If image could be opened, run comet analysis
                if(imp!=null){
//NUMBER 2 FLIPPING AT THIS POINT
                    String imageKey =  inFiles[i].getName();

Moreover I would need to import the class of the BioFormat Importer or something like this. Wouldn't I?

Thanks a lot in advance.


Solution

    1. run("Bio-Formats Windowless Importer", "open=path autoscale color_mode=Default view=Hyperstack stack_order=XYCZT");

      opening my files with the help of the Bioformat Importer plugin

    You can achieve this using the BF helper class of bio-formats (see its API documentation). For a javascript example, have a look here. In Java, this could look like:

    import loci.plugins.BF;
      [...]
    ImagePlus[] imps = BF.openImagePlus(inFiles[i].getPath());
    ImagePlus imp = imps[0];
    
    1. run("Flip Horizontally");

    Use the recorder (Plugins > Macros > Record...) in Java mode to get the required command:

    import ij.IJ;
     [...]
    IJ.run(imp, "Flip Horizontally", "");
    

    If you want to know the Java command at a lower level, use the Command Finder (press [L] or Plugins > Utilities > Find Commands...) and type "flip" and you'll find the class that implements the command:

    ij.plugin.filter.Transformer("fliph")
    

    Hope that helps.