Login  Register

Re: launch functions in java

Posted by Michael Schmid on Jun 13, 2016; 9:09am
URL: http://imagej.273.s1.nabble.com/launch-functions-in-java-tp5016624p5016633.html

Hi Philippe,

for "Images to Stack", you have to show the images first.
This command uses the open images, i.e., those that are shown.

   imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
   //imp.setTitle("blobs1.gif"); //would be nicer with this
   imp.show();
   imp2 = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
   imp2.show();
   IJ.run(imp, "Images to Stack", "name=Stack title=[] use");

As an alternative, you can do it like the following without showing the
images:

   imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
   is = imp.getStack();
   imp2 = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
   ip = imp2.getProcessor();
   is.addSlice(ip);
   IJ.log("Stack size: "+is.getSize());
   stackImp = new ImagePlus("The stack", is);
   stackImp.show();

---

 > Besides this, within a macro, it is possible to import data from a
 > launched plugin by using a defined "Ext." through the macro extensions
 > features.
 > But how can this be done by launching the plugin from an another
 > plugin?

Usually, the easiest way is having a public method of the plugin that
gets called.  If you can't modify that plugin, have a look at
   ij.macro.ExtensionDescriptor
and the
   ij.macro.Functions.doExt() method
to get some inspirations on how the macro extensions it can be called.
(I have no experience with this, however).

Michael
________________________________________________________________
On 2016-06-12 23:43, CARL Philippe (PHA) wrote:

> Hi Wayne,
>
> How are you doing?
>
> I thank you very much for your answer and I indeed confirm (i.e. by
> checking it) all what you had written.
> Nevertheless, please find the following java code of a quite small
> plugin which had as well been generated by using the recorder (i.e. by
> using Plugins>Macros>Record):
> ImagePlus imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
> imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
> IJ.run(imp, "Images to Stack", "name=Stack title=[] use");
> imp.show();
> Which is given the error message: "No images are open.". What is the
> issue about it?
>
> Besides this, within a macro, it is possible to import data from a
> launched plugin by using a defined "Ext." through the macro extensions
> features.
> But how can this be done by launching the plugin from an another
> plugin?
>
> I thank you very much in advance fir your help and wish you a nice
> end  of week-end.
>
> Kindest regards,
>
> Philippe
>
> Le Samedi 11 Juin 2016 17:14 CEST, "Rasband, Wayne (NIH/NIMH) [E]"  <[hidden email]> a écrit:
>
>>> 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
>
>
>
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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