Hello!

In a world where attention is a highly sought asset, grabbing and maintaining an audience’s interest during a presentation is a topic worth considering. In previous posts, I have shared how I enjoy preparing visual animations that help make my points across while creating a visually appealing experience for the audience, making it engaging and attractive to follow. One of the tools that is exceptionally straightforward and yet extremely powerful is ParaView, an open-source software for scientific visualisation. I have been using it since my Master’s to produce progressively more ambitious animations, and so far, it has always been up to the challenge and delivering results that I find pretty remarkable. For this reason, in this post, I would like to share my step-by-step workflow (with a bit of code) on creating animations with ParaView. While I previously shared my conceptual guidelines (e.g., preparing a storyboard), I would like to be specific about the steps and tools selected for each stage.

1. Image data preparation

2. ParaView initialisation

3. Creating an animation

4. Exporting an animation

Image data preparation

The first step is to prepare our files to be compatible with ParaView. In my case, most visualisations revolve around micro-computed tomography scans of bones, which we obtain in the proprietary format from the device. I use Python to open these files and extract the image data as a typical Numpy array. At this point, my animations usually rely on binary images, although ParaView is also compatible with grayscale data. To export the data, I use PyEVTK, which conveniently exports the data into .vti format that can easily be processed in ParaView:

from pyevtk.hl import imageToVTK
imageToVTK(save_filename, cellData={
           'ImageData': binary_image_array.as type(np.uint8),
}

This will save a file save_filename with a dataset called ImageData containing the binary image array. The conversion of the data type helps to reduce the file size. If needed, several images can be saved in a single VTI file. Additionally, when using several images in the same animation, it is helpful to crop or pad images as needed to homogenise their dimensions, making it easier to keep them in a common reference frame without many translation or rotation transformations to keep them all in the scene.

ParaView initialisation

After opening ParaView, vti files can simply be dragged into the main window to open them. This will not yet load the data, but it creates a placeholder for the processing pipeline visible in the Explorer window on the left. Assuming we are still working with binary images, a typical function to use first is the “Threshold” option. This allows us to pick a dataset in our file (e.g., ImageData) and the value we would like to use for the threshold (in binary images, any value between 0 and 1 works). After pressing apply, an image will now be generated accordingly.

Since thresholded images are essentially unprocessed, they are easy to manipulate, and I use them to test run animations, camera angles, and illumination settings. At the top bar, several buttons related to view angles and camera orientation provide fine control over the scene. As I define angles of interest, I usually store these angles and export all the camera positions using the corresponding tool from the top bar. An important detail that I usually set is the View Size (available in “Tools”, “Lock View Size Custom”), such that I can set the window of the animation to a specific aspect ratio.

Creating an animation

To prepare an animation, we can open the Animation View and Time Inspector from the View sub-menu if they are not yet visible. This menu allows us to pick how many frames and for how many seconds we want our animation to last. During development, I usually set the expected duration but a much lower frame rate, allowing me to get a sense of the flow without being too computationally intensive to preprocess. By selecting the option “Camera” in the timeline, with the option “Interpolate Cameras”, we can set time points at which the camera should reach specified camera angles. After finding our angles of interest in the previous step, we want to ensure a smooth flow between them. If precise control of the camera path is needed, there is also the option to define a clear path with all the positions and orientations of the cameras, although this option requires considerably more effort to execute.

After defining the interpolated path of the camera position, we proceed to clean the image for an appealing look. I typically follow the next steps for renderings of bone images, but other applications may not require the same sequence of operations. Overall, the idea is to have a smoother surfce that looks more realistic, rather than the voxel-based image obtained after thresholding. Hence, we use the filters “Extract Surface” and “Smooth” to achieve this effect. I typically select over 700 iterations to achieve a smooth, clean surface.

If there are several images to be manipulated in the same scene, it is also possible to adjust the opacity of each one in the animation view to create smooth transitions between them. Again, we only need to select the image of interest, the option “Opacity”, and define the timepoints at which this parameter should change value. ParaView correctly interpolates the value between these setpoints.

Exporting an animation

Finally, when the whole workflow is ready, the only step left is to export the animation. For this step, I usually activate the ray tracing algorithm from ParaView, available at the bottom of the Properties menu (“Enable Ray Tracing”). This is a computationally intensive task, especially without a dedicated graphics card, but one that dramatically improves the quality of the images rendered. I usually only set the parameters “Ambient Samples”, “Samples per Pixel”, “Progressive Passes”, and “Light Scale” (typically around 1, 10, 10 and 0.8, respectively).

To produce a video, we can select “File” and “Save Animation” to set the file name and type of each frame to be exported, as well as specific compression settings and dimensions of the frames. After pressing Save, ParaView will cycle through all the frames and export numbered images accordingly. With Ray Tracing activated, this operation can take several minutes on a standard laptop. Eventually, the image sequence can be merged into a video (e.g., using Quick Time Player), and the animation is ready!

Conclusion

Visual animations can be transformative to communicate complex scientific concepts to a broad audience. I am inspired by and attracted to presentations that can implement such ideas effectively and cause a sense of amazement when following them. For this reason, I am always eager to try new ideas, and with software like ParaView, I believe it is truly accessible to experiment and produce high-quality animations relatively simply.

Please feel free to share your thoughts about your approach to producing scientific animations!

Have a great day!