Login  Register

Re: launch functions in java

Posted by Rasband, Wayne (NIH/NIMH) [E] on Jun 11, 2016; 3:01pm
URL: http://imagej.273.s1.nabble.com/launch-functions-in-java-tp5016624p5016626.html

> On Jun 10, 2016, at 11:11 AM, Philippe CARL <[hidden email]> wrote:
>
> Dear all,
>
> In a plugin the function crop can be launched through: IJ.run("Crop”);

It is best to use the recorder (Plugins>Macros>Record) to generate code. This is the code recorded when you open the Boats sample image and crop it:

  imp = IJ.openImage("http://wsr.imagej.net/images/boats.gif");
  imp.setRoi(136,185,125,177);
  IJ.run(imp, "Crop", "”);
  imp.show();

> But given that the crop corresponds (Ctrl +l) to the function:
> ij.plugin.Resizer("crop")
>
> How can it be launched through a call?

The Resizer class is not designed to be called directly. Instead, call the ImageProcessor.crop() method. Here is an example:

  imp = IJ.openImage("http://wsr.imagej.net/images/boats.gif");
  ip = imp.getProcessor();
  ip.setRoi(136,185,125,177);
  ip = ip.crop();
  new ImagePlus("Lighthouse",ip).show();

> And is it better to use a call rather than a IJ.run instruction or inverse?

It is better to use IJ.run(imp,"Crop","”); since it works with stacks and overlays, and it preserves spatial calibration.

-wayne

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