Volumetric Dataset Rendering in Python
Volume Rendering in napari
- Interactive visualization and annotation: Offers tools for exploring data and annotating images in real-time.
- Layer-based rendering: Supports multiple layers like images, labels, points, and shapes for versatile data representation.
- Plugin extensibility: Easily extendable through plugins to add custom functionality.
- Integration with Python ecosystem: Seamlessly works with NumPy, Dask, and other scientific Python libraries.
Volume Rendering in napari
Solution to run napari code through Album
To simplify and unify solutions used in our tutorials, we use Album, a tool for capturing and sharing specific software use cases in dedicated virtual environments.
Click the solution box next to this text and follow the displayed usage instructions to run the solution either from command line or graphical interface.
Launch napari v0.5.3
visualization:launch-napari:0.2.0
This solution launches napari with the option to directly open a dataset.
Tags: template, napari
Launch napari v0.5.3
visualization:launch-napari:0.2.0
This solution launches napari with the option to directly open a dataset.
Tags: template, napari
- License: MIT
- Solution creator(s): Deborah Schmidt
album install visualization:launch-napari:0.2.0
album run visualization:launch-napari:0.2.0
--input # (file): The image that should be displayed in napari. [Default: ] [Required: No]
--rgb # (boolean): If an image is provided, should the image be displayed as an RGB image? [Default: 0] [Required: No]
Cite the following resources if you use this solution:
Volume Rendering in napari
Dependencies
58 dependencies={'environment_file': """channels:
59 - conda-forge
60dependencies:
61 - python=3.11
62 - scikit-image=0.24.0
63 - pyqt=5.15.9
64 - pip
65 - pip:
66 - napari==0.5.3
67"""}
Volume Rendering in napari
Running napari programmatically
8 import napari
9 from skimage.io import imread
10 from album.runner.api import get_args
11
12 # Get input parameters
13 input = get_args().input
14 is_rgb = get_args().rgb
15
16 if input:
17 # Show provided image
18 img = imread(input)
19 napari.view_image(img, rgb=is_rgb, name="Input image")
20 else:
21 # Launch empty viewer
22 napari.Viewer()
23
24 napari.run()
Volume Rendering with Pygfx
Key Features:
- Real-time GPU Rendering: Leverages modern GPU acceleration for high-performance 2D and 3D graphics.
- Diverse application support: from scientific visualization to video game rendering.
- Flexible Scene Graph: Employs a scene graph architecture to efficiently manage complex scenes.
- Custom Shader Support: Allows for custom shaders to create advanced visual effects.
Volume Rendering with Pygfx
Solution to run pygfx code through Album
To simplify and unify solutions used in our tutorials, we use Album, a tool for capturing and sharing specific software use cases in dedicated virtual environments.
Click the solution box next to this text and follow the displayed usage instructions to run the solution either from command line or graphical interface.
Render a volume using Pygfx
visualization:render-volume-pygfx:0.1.0
In this solution, volumes can either be rendered as isosurface or using raycasting.
Render a volume using Pygfx
visualization:render-volume-pygfx:0.1.0
In this solution, volumes can either be rendered as isosurface or using raycasting.
- License: MIT
- Solution creator(s): Deborah Schmidt
album install visualization:render-volume-pygfx:0.1.0
album run visualization:render-volume-pygfx:0.1.0
--input # (file): The image that should be displayed in pygfx. [Default: ] [Required: No]
--isosurface # (boolean): Whether to render the volume using isosurface material instead of using raycasting. [Default: 0] [Required: No]
Cite the following resources if you use this solution:
Volume Rendering with Pygfx
Dependencies
88 dependencies={'environment_file': """channels:
89 - conda-forge
90dependencies:
91 - python=3.11
92 - pygfx=0.5
93 - pyside6=6.7
94 - imageio=2.35
95"""}
Volume Rendering with Pygfx
Setting the scene
18 # Set up the canvas and scene
19 canvas = WgpuCanvas()
20 renderer = gfx.renderers.WgpuRenderer(canvas)
21 scene = gfx.Scene()
Volume Rendering with Pygfx
Adding the volume to the scene
23 # Read the input dataset
24 voldata = iio.imread(image_path).astype(np.float32)
25
26 # Set the volume rendering type
27 if isosurface:
28 # Render volume as isosurface
29 geometry = gfx.Geometry(grid=voldata)
30 material = gfx.VolumeIsoMaterial(clim=(0, 2000), threshold=1000)
31 vol = gfx.Volume(geometry, material)
32 else:
33 # Render volume using raycasting
34 tex = gfx.Texture(voldata, dim=3)
35 vol = gfx.Volume(
36 gfx.Geometry(grid=tex),
37 gfx.VolumeRayMaterial(clim=(0, 2000), map=gfx.cm.cividis, pick_write=True),
38 )
39
40 # Add the volume to the scene
41 scene.add(vol)
Volume Rendering with Pygfx
Setting up the camera and running the application
40 # Add the volume to the scene
41 scene.add(vol)
42
43 # Set up the camera to show the scene
44 camera = gfx.PerspectiveCamera(70, 16 / 9)
45 camera.show_object(scene, view_dir=(-1, -1, -1), up=(0, 0, 1))
46
47 # Enable interactive rendering
48 controller = gfx.OrbitController(camera, register_events=renderer)
49
50 def animate():
51 renderer.render(scene, camera)
52 canvas.request_draw()
53
54 canvas.request_draw(animate)
55 run()
Volume Rendering in VTK
- Transfer Functions: Map voxel intensities to color and opacity for flexible and accurate rendering.
- Advanced customization: Full control over lighting, shading, and rendering parameters.
- ParaView & 3D Slicer: GUI-based tools built on VTK for easier interaction with volumetric data.