Login  Register

Re: Duplicaing Stacks

Posted by BenTupper on Oct 09, 2009; 12:00am
URL: http://imagej.273.s1.nabble.com/Duplicaing-Stacks-tp3690862p3690867.html

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