Supercomputing Institute Technical User Support

 

IDL: Animation

  1. Animating a Series of Images
  2. Displaying Animation as a Wire Mesh
  3. Aniamation with XINTERANIMATE
  4. Cleaning Up Animation Windows

Animating a Series of Images

To create an animation that shows a series of images that represent an abnormal heartbeat, first read in the images to be displayed. The file holds 16 images of a human heart as 64 by 64 element arrays of bytes.
1. Enter:
heart=read_binary('/usr/local/rsi/idl_5.4/idl_5.4/examples/data/abnorm.dat',$
data_dims=[64,64,16],data_type=1)
2. Load an appropriate color table:
loadct, 3
3. Display the first slice of our 3-D array:
tv,heart[*, *, 0]
The asterisks (*) in the first two element positions tell IDL to use all of the elements in those positions. Hence, the TV procedure displays a 64 by 64 byte image. The image is rather small.
4. Now resize each image in the array with bi-linear interpolation by entering:
h=rebin(heart,320,320,16)
5. Then display:
tv,h[*, *, 0]
Each image in H is 5 times its previous size.  Now a simple FOR statement can be used to animate the images. (A more robust and convenient animation routine, XINTERANIMATE, is described next.)
6. To animate, enter:
for i=0,15 do tvscl,h[*,*,i]

IDL displays the 16 images in the array H sequentially. To repeat the animation, press the up arrow key to recall the command and press enter.

7. Dismiss the window:
wdelete

Displaying Animation as a Wire Mesh

The same series of images can be displayed as different types of animations. For example, each frame of the animation could be displayed as a SURFACE plot.
1. Create a new array to hold the heartbeat data:
s=rebin(heart,32,32,16)
s now holds 32 byte by 32 byte versions of the heartbeat images. SURFACE plots are often more legible when made from a resized version of the dataset with fewer data points in it.
2. Display the first image in s, as a wire-mesh surface by entering:
surface,s[*,*,0]

Now create a whole series of SURFACE plots, one for each image in the original dataset.

3. To do this, first create a three-dimensional array to hold all of the images by entering:
frames=bytarr(300,300,16)
The variable frames will hold sixteen, 300 by 300 byte images.
4. Now create a 300 by 300 pixel window in which to display the images:
window,1,title='IDL Animation',xsize=300,ysize=300
The next command will draw each frame of the animation. A SURFACE plot is drawn in the window and then the TVRD function is used to read the image from the plotting window into the frames array. The FOR loop is used to increment the array indices. The lines which follow are actually a single IDL command. The dollar sign ($) works as a continuation character in IDL and the ampersand (&) allows multiple commands in the same line.
5. Enter:
for i=0,15 do begin surface,s[*,*,i],zrange=[0,250]$
& frames[0,0,i]=tvrd()&end
You should see a series of SURFACE plots being drawn in the animation window, as shown in below. The ZRANGE keyword is used to keep theheight axis the same for each plot.
6. Now display the new images in series by entering:
for i=0,15 do tv,frames[*,*,i]

Aniamation with XINTERANIMATE

IDL includes a powerful, widget-based animation tool called XINTERANIMATE.  Sometimes it is useful to view a single wire-mesh surface or shaded surface from a number of different angles. Lets make a SURFACE plot from one of the S dataset frames and view it rotating through 360 degrees. by entering:
1. Save the first frame of the S dataset in the variable A to simplify the next set of commands:
a=s[*,*,0]
2. Create a window in which to display your surface:
window,0,xsize=300,ysize=300
3. Display a as a wire-mesh surface:
surface,a,xstyle=4,ystyle=4,zstyle=4
Setting the XSTYLE, YSTYLE, and ZSTYLE keywords equal to 4 turns axis drawing off. Usually, IDL automatically scales the axes of plots to best display all of the data points sent to the plotting routine. However, for this sequence of images, it is best if each SURFACE plot is drawn with the same size axes. The SCALE3 procedure can be used to control various aspects of the three-dimensional transformation used to display plots.
4. Force the X and Y axis ranges to run from 0 to 32 and the Z axis range to run from 0 to 250:
scale3,xrange=[0,31],yrange=[0,31],zrange=[0,250]
5. Set up the XINTERANIMATE routine to hold 40, 300 by 300 byte images:
xinteranimate,set=[300,300,40],/showload
6. Generate each frame of the animation and store it for the XINTERANIMATE routine. Once a 3-D transformation has been established, most IDL plotting routines can be made to use it by including the T3D keyword. The [XYZ]STYLE keywords are shortened to [XYZ]ST:
for i=0,39 do begin scale3,az= -i * 9 & surface,a, $
/t3d,xstyle=4,ystyle=4,zstyle=4 & xinteranimate,$
frame=i,win=0 & end
7. Play images back as an animation after all the images have been saved in the XINTERANIMATE routine:
xinteranimate

The XINTERANIMATE window should appear, as shown above. Tape recorderstyle controls can be used to play the animation forward, play it backward, or stop.  Individual frames can also be selected by moving the Animation Frame slider. TheOptions menu controls the style and direction of image playback. Click on End Animation when you are ready to return to the IDL Command Line.

Cleaning Up Animation Windows

Before continuing with the rest of the tutorials, delete the two windows you used to create the animations. The WDELETE procedure is used to delete IDL windows.
1. Delete both window 0 and window 1 by entering:
wdelete, 0
wdelete, 1


 
This information is available in alternative formats upon request by individuals with disabilities. Please send email to alt-format@msi.umn.edu or call 612-624-0528.

HOME | QUESTIONS | FEEDBACK
Employment | Events | Links | People | Programs | Publications | Support | Welcome
 


URL: http://www.msi.umn.edu/software/fast/tutorial/fast-starting.html
This page last modified on Friday, 03 November, 2000,  09:10:02 CDT  
Please direct questions or problems to help@msi.umn.edu  
Website related questions or problems should be dirrected to webmaster@msi.umn.edu