Login  Register

Re: launch functions in java

Posted by CARL Philippe (LBP) on Jun 13, 2016; 12:35pm
URL: http://imagej.273.s1.nabble.com/launch-functions-in-java-tp5016624p5016635.html

Hi Michael,
How are you doing?
I had finally figured out the first version (i.e. with the imp.show() added after each IJ.openImage) but the alternative version is what I was actually looking for (to be faster since the pictures are not shown).
Nevertheless, I didn't expect the needed code to be so complicated, thus thanks a lot for sharing it!!!
I can modify the plugin I working on, thus all options are open and I would prefer to choose the most adapted and efficient one.
Also would you have an example to link me with where there is a "public method of the plugin that gets called"?
The issue is that the plugin has already " ij.macro.MacroExtension" features and when I try to launch it through a "IJ.run" I get the "Macro must be running to install macro extensions" error which corresponds to the case (interp==null) of the "registerExtensions" method within the " ij.macro.Functions.java" class.
Which obviously means that I'm doing something wrong here and I'm kind of stuck...
I thank you very much in advance for your help.
Kindest regards,
Philippe

-----Message d'origine-----
De : ImageJ Interest Group [mailto:[hidden email]] De la part de Michael Schmid
Envoyé : lundi 13 juin 2016 11:22
À : [hidden email]
Objet : Re: launch functions in java

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

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