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 |
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 |
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.net http://www.ini.uzh.ch/~acardona/ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
> 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? The names of the output images are predictable and follow the order of the stains names. Eg for H&E title+"-(Colour_1)" is the haemtoxylin image title+"-(Colour_2)" is the eosin image title+"-(Colour_3)" is the 3rd component So if you know the name of the input image, you could select the predicted- image window and then get the ImagePlus. Sorry I never used Jython so I cannot suggest any further. Cheers Gabriel -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by ctrueden
Thanks Curtis! I will take a crack at refactoring the java code into the
recommended run and exec methods and if it works I'll file a pull request. -Marcello On Oct 31, 2013 2:57 PM, "Curtis Rueden" <[hidden email]> wrote: > 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 > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
A further question about developing a plugin: I am trying to edit this
java plugin so that it can be called from a Jython script. Where should I place the *.java/*.class/*.jar file in the Fiji directory so that it can be imported into my Jython script? Do I need to specify a particular package/namespace in my java code? Thanks! -Marcello On Fri, Nov 1, 2013 at 12:52 PM, Marcello DiStasio <[hidden email]>wrote: > Thanks Curtis! I will take a crack at refactoring the java code into the > recommended run and exec methods and if it works I'll file a pull request. > -Marcello > On Oct 31, 2013 2:57 PM, "Curtis Rueden" <[hidden email]> wrote: > >> 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 >> > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Marcello,
On Fri, 1 Nov 2013, Marcello DiStasio wrote: > A further question about developing a plugin: I am trying to edit this > java plugin so that it can be called from a Jython script. > > Where should I place the *.java/*.class/*.jar file in the Fiji directory > so that it can be imported into my Jython script? Do I need to specify > a particular package/namespace in my java code? You can place the .class file anywhere into the plugins/ directory. Alternatively, you can wrap the .class file into a .jar file (this is especially convenient if your code uses inner/anonymous classes). Personally, if I have to code something up real quick, I start the Script Editor and create a .java file in the plugins/ directory. It can be compiled using Run>Compile. After that, you need to call Help>Refresh Menus before your Jython script can make use of that class. Ciao, Johannes -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |