Search code examples
javascriptimagej

ImageJ script: "This command requires a selection" when there is one


I am trying to write a script in javascript. It uses a plugin called Radial Profile, but I believe the problem is somewhere lese.

I have:

IJ.run("Select All", "");
IJ.run(imp, "Radial Profile", "x=524 y=524 radius=524");

but this yields the error This command requires a selection (while it runs fine if I use the menu from the point after the "Select all" step in the script).

I actually also get an error This command requires a rectangular selection if I use only built-in commands as:

IJ.run("Select All", "");
IJ.run(imp, "Make rectangular selection rounded", "");

What am I doing wrong? Shall I pass the selection to IJ.run in some way?


Solution

  • The line IJ.run(imp, "Make rectangular selection rounded", ""); tells me you are using Fiji, as this command is included in Fiji_Plugins.

    Are you sure your Fiji installation is up to date? (via Help > Update Fiji)

    The following script works as expected (on the currently active imgae) when run from the script editor in an up-to-date Fiji installation:

    importClass(Packages.ij.IJ);
    
    imp = IJ.getImage();
    IJ.run("Select All", "");
    IJ.run(imp, "Make rectangular selection rounded", "radius=5");
    

    If it does not work on your machine, please report a bug via Help > Report a bug in the menu. This allows the developers to know some (possibly important) details about your local installation.