Posted by
Albert Cardona-2 on
Oct 31, 2013; 7:06pm
URL: http://imagej.273.s1.nabble.com/Using-results-from-plugins-in-scripts-tp5005391p5005414.html
A fragile workaround when confronted with these uncontrollable plugins is
to register an ImagePlus listener. Assuming nothing else is running in
Fiji, the next few opened images are the ones produced by the plugin.
A more robust hack is to add an custom ij.ImagePlus class before the ij.jar
in the class path. All the class has to do is copy the body of the
ImagePlus class and add extra code at the constructors that are able to
then notify your code in some way, for example by throwing an Exception and
catching it, and parsing its caller class/method. While awful, this is
sometimes the only recourse when only .class files exist for
application-critical plugins.
As Curtis said, though, this one specific plugin has its source code
available, and fixing it is easier than any workaround.
Albert
2013/10/31 Curtis Rueden <
[hidden email]>
> Hi Marcello,
>
> > What I want is access to one (or all) of these result images in my
> > calling script. Is there a way (in Jython) to 'drill down' into the
> > plugin in order to get the ImagePlus objects for these results?
>
> Let's look at the source code for Colour_Deconvolution:
>
>
https://github.com/fiji/fiji/blob/master/src-plugins/Colour_Deconvolution/src/main/java/Colour_Deconvolution.java>
> You can see that all work is done in the run(String) method and three
> ImagePlus objects are created and shown at the end. There is no recourse.
> The plugin would need to be refactored to split the work into helper
> methods which return the ImagePlus objects without showing them. Then you
> could call that Java API from Jython to use it as a library.
>
> I encourage you to make these changes and then file a pull request on
> GitHub so that we can improve the plugin in the core Fiji distribution.
> See:
>
https://help.github.com/articles/using-pull-requests>
> Regards,
> Curtis
>
>
> On Wed, Oct 30, 2013 at 5:17 PM, Marcello DiStasio <
[hidden email]
> >wrote:
>
> > Hello ImageJ list, and apologies if this isn't the appropriate venue for
> > this question, but I have been unable to come up with an obvious answer
> > elsewhere.
> >
> > I want to use a plugin (one that is a standard plugin bundled with Fiji
> as
> > a *.jar in the ./Fiji.app/plugins directory -- specifically
> > 'Colour_Deconvolution') as part of an image processing pipeline that I am
> > writing using Jython. I am able to run the command as recorded by the
> > Macro Recorder using the IJ.run method:
> >
> > IJ.run(imp, "Colour Deconvolution", "vectors=H&E")
> >
> > The problem is that this method returns nothing to the calling script.
> The
> > method runs the command in Fiji, and 3 result images are generated and
> > shown. What I want is access to one (or all) of these result images in
> my
> > calling script. Is there a way (in Jython) to 'drill down' into the
> plugin
> > in order to get the ImagePlus objects for these results?
> >
> > Thanks!
> > -Marcello
> >
> > --
> > ImageJ mailing list:
http://imagej.nih.gov/ij/list.html> >
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
--
http://albert.rierol.nethttp://www.ini.uzh.ch/~acardona/--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html