Skip to content

Instantly share code, notes, and snippets.

@acardona
Created April 24, 2013 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acardona/5455754 to your computer and use it in GitHub Desktop.
Save acardona/5455754 to your computer and use it in GitHub Desktop.
# Albert Cardona 2012-09-06
# Animate an Orthoslice view of an image volume in the 3D Viewer
# and record it into an ImageStack.
# Assumes that the Orthoslice view is already present in the 3D Viewer
# and then the scripts limits itself to iterating through the slices in a specific axis
# and to rotate when desired.
from ij3d import Image3DUniverse
from math import radians
univ = Image3DUniverse.universes[0]
univ.select(None)
c = univ.getContents().iterator().next()
print c
orthogroup = c.getContent()
print orthogroup
renderer = orthogroup.getRenderer()
print renderer
width = 282
height = 319
depth = 1189
dims = univ.getCanvas().getBounds()
print dims
stack = ImageStack(dims.width, dims.height)
# adjust Z
renderer.setSlice(2, 174)
renderer.setSlice(0, 0)
def snapshot(univ)
return univ.takeSnapshot().getProcessor().convertToByte()
def record(univ, renderer, stack, axis, first, last):
"""From first to last, inclusive, recorded into stack."""
if first < last:
for i in xrange(first, last + 1):
renderer.setSlice(axis, i)
stack.addSlice(str(i), snapshot(univ))
else:
for i in xrange(first, last -1, -1):
renderer.setSlice(axis, i)
stack.addSlice(str(i), snapshot(univ))
# Acquire movie from X=0 to X=214
record(univ, renderer, stack, 0, 0, 214)
# Rotate and acquire movie
#for i in xrange(40):
# univ.rotateY(radians(-1))
# stack.addSlice(str(i), snapshot(univ))
# Acquire movie from Z=174 to 0
record(univ, renderer, stack, 2, 174, 0)
# Acquire movie from Z=0 to Z=1188 while rotating for the first 800 slices
for i in xrange(0, 1188 + 1):
renderer.setSlice(2, i)
if i < 500:
univ.rotateY(radians(-1 * (40 / 500.0)))
else:
univ.rotateY(radians(-1 * (20 / 688.0)))
stack.addSlice(str(i), snapshot(univ))
ImagePlus("Movie", stack).show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment