Hello List,
I'm developing an application for image processing using ImageJ as a library. So far, I've been able to call ImageJ functionality using macros. For example, if I want to calculate a mean filter of an image, I do something like this: IJ.run(image, "Mean...", "radius="+radius); However, I can't do the same with plugins. I found many plugins for algorithms that I need, but I can't integrate them with this method. The best alternative I've found is to include the plugin's .java into my proyect, and call its functions. The problem I encountered doing this, is that the plugin requires a FloatProcessor and image.getProcessor() would give me a ColorProcessor. So now my questions: 1 - Is there a macro-style way to call a plugin? 2 - How can I get a FloatProcessor if the images I have return a ColorProcessor when calling getProcessor()? I realize these may be dumb questions, but a quick search in this list didn't show any useful advice. Thanks in advance, Pablo. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Pablo,
Normally this is actually very easy. I devlop software using ImageJ as a library using Netbeans, but i guess it works in a similar way in other IDEs. Just add the jar containg the plugin (for instance the AnalyzeSkeleton_.jat) to your libraries folsder (same as for IJ.jar) and you can now call the functions in your plugin straight from your code. This usually involves running a setup step for the plugin and then run it. However, have a good look atthe documentation of the plugin, because many offer functions to run inside java code in a more straightforward way/offer extra options. I've added some snippets of code from one of my own projects. Hope this helps, Rob Example: //import statements import skeleton_analysis.AnalyzeSkeleton_; import skeleton_analysis.SkeletonResult; import Skeletonize3D_.Skeletonize3D_; private ImagePlus getCentreLine(ImagePlus impObject){ //additional code deleted //bit of code to skelonize an image Skeletonize3D_ skeletonize = new Skeletonize3D_(); ImagePlus skelImg = new ImagePlus("skeleton", impObject.getProcessor().duplicate()); ImageProcessor skelProc = skelImg.getProcessor(); int skelRet = skeletonize.setup("", skelImg); //plugins need an ImagePlus for setup skeletonize.run(skelProc); //performs the skeletonize //bit of code to analyze the skeleton AnalyzeSkeleton_ skelAnalysis = new AnalyzeSkeleton_(); skelRet = skelAnalysis.setup("", skelImg); //one of several different ways to run this plugin SkeletonResult skelRes = skelAnalysis.run(AnalyzeSkeleton_.NONE, false, true, skelImg, true, false); //additional code deleted On 05/03/2013 23:31, SUSCRIBE IMAGEJ Pablo wrote: > Hello List, > > I'm developing an application for image processing using ImageJ as a library. > > So far, I've been able to call ImageJ functionality using macros. For example, if I want to calculate a mean filter of an image, I do something like this: > > IJ.run(image, "Mean...", "radius="+radius); > > However, I can't do the same with plugins. I found many plugins for algorithms that I need, but I can't integrate them with this method. > > The best alternative I've found is to include the plugin's .java into my proyect, and call its functions. The problem I encountered doing this, is that the plugin requires a FloatProcessor and image.getProcessor() would give me a ColorProcessor. > > So now my questions: > 1 - Is there a macro-style way to call a plugin? > 2 - How can I get a FloatProcessor if the images I have return a ColorProcessor when calling getProcessor()? > > I realize these may be dumb questions, but a quick search in this list didn't show any useful advice. > > Thanks in advance, > > Pablo. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > _____________________________ Dr. Rob van 't Hof Reader Centre for Molecular Medicine MRC IGMM University of Edinburgh Western General Hospital Crewe Road, Edinburgh EH4 2XU United Kingdom Phone: (+44)-131-6511031 email: [hidden email] _____________________________ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Pablo,
I think your main issue here is not the ability to call a plugin but rather the ability to convert from ColorProcessor to FloatProcessor. Given that a ColorProcessor involves 3 channels of information, the conversion to float processor may or may not be straightforward. The easiest is to get the color processor and then call its convertToFloat() method. This will merge the three color channels into one floating point image. Perhaps a better option is the getChannel(int channel, ByteProcessor bp) method which returns a ByteProcessor for the red, green, or blue channels which you can then run convertToFloat() on without any change in the data. Note that the bp argument can be null. Jay -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Rob van 't Hof Sent: Wednesday, March 06, 2013 5:14 AM To: [hidden email] Subject: Re: Calling a Plug-in from Java application Hi Pablo, Normally this is actually very easy. I devlop software using ImageJ as a library using Netbeans, but i guess it works in a similar way in other IDEs. Just add the jar containg the plugin (for instance the AnalyzeSkeleton_.jat) to your libraries folsder (same as for IJ.jar) and you can now call the functions in your plugin straight from your code. This usually involves running a setup step for the plugin and then run it. However, have a good look atthe documentation of the plugin, because many offer functions to run inside java code in a more straightforward way/offer extra options. I've added some snippets of code from one of my own projects. Hope this helps, Rob Example: //import statements import skeleton_analysis.AnalyzeSkeleton_; import skeleton_analysis.SkeletonResult; import Skeletonize3D_.Skeletonize3D_; private ImagePlus getCentreLine(ImagePlus impObject){ //additional code deleted //bit of code to skelonize an image Skeletonize3D_ skeletonize = new Skeletonize3D_(); ImagePlus skelImg = new ImagePlus("skeleton", impObject.getProcessor().duplicate()); ImageProcessor skelProc = skelImg.getProcessor(); int skelRet = skeletonize.setup("", skelImg); //plugins need an ImagePlus for setup skeletonize.run(skelProc); //performs the skeletonize //bit of code to analyze the skeleton AnalyzeSkeleton_ skelAnalysis = new AnalyzeSkeleton_(); skelRet = skelAnalysis.setup("", skelImg); //one of several different ways to run this plugin SkeletonResult skelRes = skelAnalysis.run(AnalyzeSkeleton_.NONE, false, true, skelImg, true, false); //additional code deleted On 05/03/2013 23:31, SUSCRIBE IMAGEJ Pablo wrote: > Hello List, > > I'm developing an application for image processing using ImageJ as a library. > > So far, I've been able to call ImageJ functionality using macros. For example, if I want to calculate a mean filter of an image, I do something like this: > > IJ.run(image, "Mean...", "radius="+radius); > > However, I can't do the same with plugins. I found many plugins for algorithms that I need, but I can't integrate them with this method. > > The best alternative I've found is to include the plugin's .java into my proyect, and call its functions. The problem I encountered doing this, is that the plugin requires a FloatProcessor and image.getProcessor() would give me a ColorProcessor. > > So now my questions: > 1 - Is there a macro-style way to call a plugin? > 2 - How can I get a FloatProcessor if the images I have return a ColorProcessor when calling getProcessor()? > > I realize these may be dumb questions, but a quick search in this list didn't show any useful advice. > > Thanks in advance, > > Pablo. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- _____________________________ Dr. Rob van 't Hof Reader Centre for Molecular Medicine MRC IGMM University of Edinburgh Western General Hospital Crewe Road, Edinburgh EH4 2XU United Kingdom Phone: (+44)-131-6511031 email: [hidden email] _____________________________ -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
It worked!
I went for Jay's approach, since I already had the code working, and it was a type incompatibility between FloatProcessor and ColorProcessor. I hadn't noticed that in the setup, the plugin raises the flag CONVERT_TO_FLOAT. I'm guessing that ImageJ automatically calls convertToFloat() when it detects that flag. Anyway, it worked. One final detail though, in case anybody goes through the same problem. convertToFloat() returns a new object of type ImageProcessor (which is an instance of FloatProcessor), it DOES NOT set it as the processor for the original image. A complete way to solve this problem would be: ImagePlus image; // image with a ColorProcessor ... ImageProcessor colorProcessor = image.getProcessor(); ImageProcessor floatProcessor = ((ColorProcessor)colorProcessor).convertToFloat(); image.setProcessor(floatProcessor); //same image with a FloatProcessor Thank you! Pablo 2013/3/6 Unruh, Jay <[hidden email]> > Pablo, > > I think your main issue here is not the ability to call a plugin but > rather the ability to convert from ColorProcessor to FloatProcessor. Given > that a ColorProcessor involves 3 channels of information, the conversion to > float processor may or may not be straightforward. The easiest is to get > the color processor and then call its convertToFloat() method. This will > merge the three color channels into one floating point image. Perhaps a > better option is the getChannel(int channel, ByteProcessor bp) method which > returns a ByteProcessor for the red, green, or blue channels which you can > then run convertToFloat() on without any change in the data. Note that the > bp argument can be null. > > Jay > > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Rob > van 't Hof > Sent: Wednesday, March 06, 2013 5:14 AM > To: [hidden email] > Subject: Re: Calling a Plug-in from Java application > > Hi Pablo, > Normally this is actually very easy. I devlop software using ImageJ as a > library using Netbeans, but i guess it works in a similar way in other > IDEs. Just add the jar containg the plugin (for instance the > AnalyzeSkeleton_.jat) to your libraries folsder (same as for IJ.jar) and > you can now call the functions in your plugin straight from your code. > This usually involves running a setup step for the plugin and then run it. > However, have a good look atthe documentation of the plugin, because many > offer functions to run inside java code in a more straightforward way/offer > extra options. > > I've added some snippets of code from one of my own projects. > > Hope this helps, > > Rob > > > Example: > > //import statements > import skeleton_analysis.AnalyzeSkeleton_; > import skeleton_analysis.SkeletonResult; import > Skeletonize3D_.Skeletonize3D_; > > private ImagePlus getCentreLine(ImagePlus impObject){ > > //additional code deleted > > //bit of code to skelonize an image > Skeletonize3D_ skeletonize = new Skeletonize3D_(); > ImagePlus skelImg = new ImagePlus("skeleton", > impObject.getProcessor().duplicate()); > ImageProcessor skelProc = skelImg.getProcessor(); > int skelRet = skeletonize.setup("", skelImg); //plugins > need an ImagePlus for setup > skeletonize.run(skelProc); //performs the skeletonize > > //bit of code to analyze the skeleton > AnalyzeSkeleton_ skelAnalysis = new AnalyzeSkeleton_(); skelRet = > skelAnalysis.setup("", skelImg); > > //one of several different ways to run this plugin SkeletonResult skelRes > = skelAnalysis.run(AnalyzeSkeleton_.NONE, false, true, skelImg, true, > false); > > > //additional code deleted > > On 05/03/2013 23:31, SUSCRIBE IMAGEJ Pablo wrote: > > Hello List, > > > > I'm developing an application for image processing using ImageJ as a > library. > > > > So far, I've been able to call ImageJ functionality using macros. For > example, if I want to calculate a mean filter of an image, I do something > like this: > > > > IJ.run(image, "Mean...", "radius="+radius); > > > > However, I can't do the same with plugins. I found many plugins for > algorithms that I need, but I can't integrate them with this method. > > > > The best alternative I've found is to include the plugin's .java into my > proyect, and call its functions. The problem I encountered doing this, is > that the plugin requires a FloatProcessor and image.getProcessor() would > give me a ColorProcessor. > > > > So now my questions: > > 1 - Is there a macro-style way to call a plugin? > > 2 - How can I get a FloatProcessor if the images I have return a > ColorProcessor when calling getProcessor()? > > > > I realize these may be dumb questions, but a quick search in this list > didn't show any useful advice. > > > > Thanks in advance, > > > > Pablo. > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > -- > _____________________________ > Dr. Rob van 't Hof > Reader > > Centre for Molecular Medicine > MRC IGMM > University of Edinburgh > Western General Hospital > Crewe Road, Edinburgh EH4 2XU > United Kingdom > > > Phone: (+44)-131-6511031 > email: [hidden email] > _____________________________ > > > -- > 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 |
Free forum by Nabble | Edit this page |