Previous Getting Started with IDL: Animation Next

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 the following commands at the IDL Command Line:
  2. HEARTTEMPLATE=BINARY_TEMPLATE(FILEPATH('abnorm.dat',$
       SUBDIR=['examples', 'data']))  
    

     

  3. When the binary template dialog box appears, name the template "Animation" and then click New Field.
  4.  

  5. Enter "H" for the Field Name, be sure to specify that you have three dimensions and that the sizes are 64, 64 and 16.
  6.  

  7. Also select Byte in the Type field. Now click OK for both open dialogs.
  8.  

  9. Next, read the images into variable HEART_BINARY:
  10. HEART_BINARY=READ_BINARY(FILEPATH('abnorm.dat',SUBDIR= $
       ['examples', 'data']), TEMPLATE=HEARTTEMPLATE)  
    

     

  11. Load an appropriate color table:
  12. LOADCT, 3  
    

     

  13. Display the first "slice" of our 3-D array:
  14. TV,HEART_BINARY.H[*, *, 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.

     

  15. Now resize each image in the array with bilinear interpolation by entering:
  16. H=REBIN(HEART_BINARY.H,320,320,16)  
    

     

  17. Then display:
  18. 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.)

     

  19. To animate, enter:
  20. FOR I=0,15 DO TVSCL,H[*,*,i]  
    

     

    Figure 11-1: Representation of an abnormal heartbeat

    Figure 11-1: Representation of an abnormal heartbeat

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.


Note
If the IDLDE screen covers and existing IDL window, you may want to delete the current IDL window before recalling the FOR statement in order to clearly see the animation.

  1. Dismiss the window:
  2. WDELETE  
    

  IDL Online Help (March 06, 2007)