Re: Copy volume from within stack to new stack
Posted by
vbindokas on
Jan 19, 2009; 6:13pm
URL: http://imagej.273.s1.nabble.com/Copy-volume-from-within-stack-to-new-stack-tp3693965p3693983.html
Dear Mike,
Easier route? : Why not do use the Image/Duplicate with the "entire
stack" box checked? (this copies just the ROI)
If the issue was the definition of the size/locale, you can likely feed
that in by the Edit/selection/specify with your derived params.
cheers,
Michael Doube wrote:
> Hi all
>
> I think my brain turned to mush over New Years because I can't get
> this simple task to work. I have a stack, coordinates of a start
> position and a volume of interest's width, height and depth. I want
> to copy the source stack's pixel values into a new stack which has the
> same dimensions of the volume of interest. This code results in a new
> stack ("Target") containing the last slice of the volume of interest
> on all of its slices:
>
> Cheers,
>
> Mike
>
> //copy box of pixels that contains sphere (i.e. is centred on centroid
> //and has 2*radius sides)
> int startX = (int)Math.round((centroid[0]-radius)/vW);
> int startY = (int)Math.round((centroid[1]-radius)/vH);
> int startZ = (int)Math.round((centroid[2]-radius)/vD);
> int roiWidth = (int)Math.round(2*radius/vW);
> int roiHeight = (int)Math.round(2*radius/vH);
> int roiDepth = (int)Math.round(2*radius/vD);
> ImageStack targetStack = new ImageStack(roiWidth,roiHeight);
> short[] roiPixels = new short[roiWidth*roiHeight];
> for (int z = startZ; z <= startZ+roiDepth; z++){
> imp.setSlice(z);
> int nRows = 0;
> for (int y = startY; y < startY+roiHeight; y++){
> int index = nRows*roiWidth;
> int nCols = 0;
> for (int x = startX; x < startX+roiWidth; x++){
> roiPixels[index+nCols] = (short)ip.getPixel(x,y);
> nCols++;
> }
> nRows++;
> }
> targetStack.addSlice("slice "+z, roiPixels);
> }
> ImagePlus target = new ImagePlus("Target", targetStack);
> target.show();
--
__
Vytas Bindokas, Ph.D.
Research Assoc. / Assoc. Prof.,
Director, BSD Light Microscopy Core Facility
Dept Neurobiol Pharmacol Physiol MC0926
947 E 58th Street
The University of Chicago
Chicago IL 60637
Room Abbott 120
773-702-4875
email
[hidden email]
web site for LMCF:
http://digital.bsd.uchicago.edu/index.html