All,
If I want to duplicate a Stack, I assume I must do it either slice by slice or use; IJ.run(imp, "Duplicate...", "title=myimage duplicate range=1-maxslice"); where imp is an ImagePlus object. If I use the IJ.run() how do I get the ImagePlus reference for the reult. Is there an easier way to do this? I may be missing it again, but I don't see anything in Plugins/Stacks that obviously does this. David Webster |
Hi,
On Oct 8, 2009, at 2:58 PM, David William Webster wrote: > All, > > If I want to duplicate a Stack, I assume I must do it either slice by > slice or use; > > IJ.run(imp, "Duplicate...", "title=myimage duplicate range=1- > maxslice"); > > where imp is an ImagePlus object. > > If I use the IJ.run() how do I get the ImagePlus reference for the > reult. > Is there an easier way to do this? I may be missing it again, but I > don't > see anything in Plugins/Stacks that obviously does this. I think you have a couple of choices. Using IJ you can imp = IJ.getImage() ... which assumes that the new image is the one you created and is active. Alternatively, you can use imp = WindowManager.getImage("myimage"); which works of there really is just one "myimage" instantiated. Cheers, Ben |
I'm trying imp = IJ.getImage().
David Webster On Thu, Oct 8, 2009 at 12:40 PM, Ben Tupper <[hidden email]> wrote: > Hi, > > > On Oct 8, 2009, at 2:58 PM, David William Webster wrote: > > All, >> >> If I want to duplicate a Stack, I assume I must do it either slice by >> slice or use; >> >> IJ.run(imp, "Duplicate...", "title=myimage duplicate range=1-maxslice"); >> >> where imp is an ImagePlus object. >> >> If I use the IJ.run() how do I get the ImagePlus reference for the reult. >> Is there an easier way to do this? I may be missing it again, but I don't >> see anything in Plugins/Stacks that obviously does this. >> > > I think you have a couple of choices. Using IJ you can > > imp = IJ.getImage() > > ... which assumes that the new image is the one you created and is active. > > Alternatively, you can use > > imp = WindowManager.getImage("myimage"); > > which works of there really is just one "myimage" instantiated. > > > > Cheers, > Ben > |
Hi again,
Hmmm. That is unexpected and it certainly was a bum steer. The following plugin works around this by simply copying the ImageProcessor for each slice in the original stack to the newly formed one. It is a punt, but it works here. //**BEGIN HERE import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.filter.*; public class Filter_Plugin implements PlugInFilter { ImagePlus imp; public int setup(String arg, ImagePlus imp) { this.imp = imp; return DOES_ALL; } public void run(ImageProcessor ip) { ImageStack origStack = imp.getImageStack(); ImageStack newStack = new ImageStack(imp.getWidth(), imp.getHeight()); int slice = 1; for (int i = 0; i< imp.getNSlices(); i++){ slice = i+1; imp.setSlice(slice); newStack.addSlice("slice="+slice, (origStack.getProcessor(slice)).duplicate() ); } //i-loop ImagePlus newImp = new ImagePlus("myimage", newStack); newImp.show(); } } //** END HERE On Oct 8, 2009, at 6:44 PM, David Webster wrote: > I'm trying imp = IJ.getImage(). > > David Webster > > On Thu, Oct 8, 2009 at 12:40 PM, Ben Tupper <[hidden email]> > wrote: > >> Hi, >> >> >> On Oct 8, 2009, at 2:58 PM, David William Webster wrote: >> >> All, >>> >>> If I want to duplicate a Stack, I assume I must do it either slice >>> by >>> slice or use; >>> >>> IJ.run(imp, "Duplicate...", "title=myimage duplicate range=1- >>> maxslice"); >>> >>> where imp is an ImagePlus object. >>> >>> If I use the IJ.run() how do I get the ImagePlus reference for the >>> reult. >>> Is there an easier way to do this? I may be missing it again, but >>> I don't >>> see anything in Plugins/Stacks that obviously does this. >>> >> >> I think you have a couple of choices. Using IJ you can >> >> imp = IJ.getImage() >> >> ... which assumes that the new image is the one you created and is >> active. >> >> Alternatively, you can use >> >> imp = WindowManager.getImage("myimage"); >> >> which works of there really is just one "myimage" instantiated. >> >> >> >> Cheers, >> Ben >> Cheers, Ben |
In reply to this post by David Webster
All,
Wayne's sugestion You can also call the internal plugin that implements the Duplicate command directly ImagePlus img1 = IJ.getImage(); ImagePlus img2 = (new Duplicater()).duplicateStack(img1, "title"); works like gangbusters. This is a good illustration of why familiarity with the APi is a must as this doesn't show up in tutorials. David Webster |
Hi David
Thanks for posting this; it's something I've been looking for for ages! Mike ________________________________________ From: ImageJ Interest Group [[hidden email]] On Behalf Of David William Webster [[hidden email]] Sent: 09 October 2009 03:58 To: [hidden email] Subject: Re: Duplicaing Stacks All, Wayne's sugestion You can also call the internal plugin that implements the Duplicate command directly ImagePlus img1 = IJ.getImage(); ImagePlus img2 = (new Duplicater()).duplicateStack(img1, "title"); works like gangbusters. This is a good illustration of why familiarity with the APi is a must as this doesn't show up in tutorials. David Webster |
Free forum by Nabble | Edit this page |