Login  Register

Re: how to obtain a sub-hyperstack?

Posted by Arne Seitz on Oct 08, 2010; 12:49pm
URL: http://imagej.273.s1.nabble.com/how-to-obtain-a-sub-hyperstack-tp3686671p3686674.html

Hi Albert,

is the following Plugin doing what you were aiming at?

Cheers Arne

/*Copyright (c) 2010 Arne Seitz"*/

import ij.IJ;
import ij.ImagePlus;
import ij.ImageStack;
import ij.WindowManager;
import ij.gui.GenericDialog;
import ij.plugin.PlugIn;


public class StackReducer_ implements PlugIn {
       
                int subchannel=1,startframe=1,endframe=1;
                int startslice=1;
                int endslice=1;
               
                public void run(String arg) {
                               
                ImagePlus imp=WindowManager.getCurrentImage();
               
                if (imp==null){
                        IJ.showMessage("An image stack is needed");
                        return;
                }
               
                GenericDialog gd = new GenericDialog("Subvolume Opener");
               
                startslice=(imp.getNSlices()/2)-1;
                endslice=(imp.getNSlices()/2)+1;
                       
                gd.addMessage("");
                       
                        if (imp.getNChannels()>1){
                                gd.addMessage(imp.getNChannels()+" Channels");
                                gd.addNumericField("Channel", 1,0);
                        }
                        if (imp.getNSlices()>1) {
                                gd.addMessage(imp.getNSlices()+" Z-Slices");
                                gd.addNumericField("Start Slice", startslice,0);
                                gd.addNumericField("End Slice", endslice, 0);
                        }
                        if (imp.getNFrames()>1){
                                gd.addMessage(imp.getNFrames()+" time frames");
                                gd.addNumericField("Start time-frame",1,0);
                                gd.addNumericField("End time-frame",imp.getNFrames(),0);
                        }
                        gd.showDialog();
                                       
                        if (gd.wasCanceled()) {
                           return;
                        }
                       
                       
                        if (imp.getNChannels()>1){
                                subchannel=(int)gd.getNextNumber();
                                if (subchannel>imp.getNChannels())subchannel=imp.getNChannels();
                                if (subchannel<1)subchannel=1;
                        }
                        if (imp.getNSlices()>1) {
                                startslice=(int)gd.getNextNumber();
                                if (startslice>imp.getNSlices())startslice=imp.getNSlices();
                                if (startslice<1)startslice=1;
                                endslice=(int)gd.getNextNumber();
                                if (endslice>imp.getNSlices())endslice=imp.getNSlices();
                                if (endslice<1)endslice=1;
                                if (endslice<startslice)endslice=startslice;
                        }
                       
                        if (imp.getNFrames()>1){
                                startframe=(int)gd.getNextNumber();
                                if (startframe<1)startframe=1;
                                endframe=(int)gd.getNextNumber();
                                if (endframe>imp.getNFrames())endframe=imp.getNFrames();
                        }
               
                ImageStack newStack= new ImageStack(imp.getWidth(),imp.getHeight());
                               
                for (int slice=startslice;slice<endslice;++slice){
                        for (int frame=startframe;frame<endframe;++frame){
                                imp.setPositionWithoutUpdate(subchannel, slice, frame);
                                newStack.addSlice("slice"+slice+"  frame"+frame, imp.getProcessor());
                                                               
                        }
                       
                }
                ImagePlus newimp= new ImagePlus("New stack",newStack);
                newimp.setOpenAsHyperStack(true);
                newimp.setDimensions(1, endslice-startslice, endframe-startframe);
                newimp.show();
        }
}

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Albert Cardona
Sent: vendredi 8 octobre 2010 11:46
To: [hidden email]
Subject: how to obtain a sub-hyperstack?

Hi all,

Suppose I have a hyperstack with 200 time points, each time point
having 30 sections.

How can I cut out a sub-hyperstack of only 10 time points, each time
point with 30 sections?

For some reason, the "Duplicate" command doesn't offer a range of time
points to preserve.

It would be great if the "Duplicate" dialog contained a range for time
and a range for Z as well.

(Of course all the above can be done trivially with a script, but I am
aiming at a point-and-click solution).

Thanks for any info.

Albert
--
http://albert.rierol.net