Display volumes
The qim3d library aims to provide easy ways to explore and get insights from volumetric data.
Visualization of volumetric data.
qim3d.viz.slicer
slicer(
volume,
slice_axis=0,
colormap='magma',
min_value=None,
max_value=None,
image_height=3,
image_width=3,
display_positions=False,
interpolation=None,
image_size=None,
colorbar=None,
mask=None,
mask_alpha=0.4,
mask_colormap='gray',
default_position=0.5,
**matplotlib_imshow_kwargs,
)
Interactive tool to visualize, inspect, and scroll through 2D slices of a 3D volume.
Generates a GUI with a slider to navigate through the dataset along a specified axis. This function is essential for quality control, verifying segmentation masks, or exploring orthogonal views (axial, coronal, sagittal) of a stack.
Key Features:
- Scrollable Interface: Automatically generates a slider for the chosen axis.
- Overlay Support: Visualize segmentation results on top of raw data using the
maskparameter. - Dynamic Contrast: Use
colorbar='slices'to adapt intensity ranges per slice, or'volume'for a global fixed range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The 3D input data to be sliced. |
required |
slice_axis
|
int
|
The axis to slice along (e.g., 0 for Z, 1 for Y, 2 for X). |
0
|
colormap
|
str or LinearSegmentedColormap
|
Matplotlib colormap name for the volume. |
'magma'
|
min_value
|
float
|
Minimum value for color scaling. If |
None
|
max_value
|
float
|
Maximum value for color scaling. If |
None
|
image_height
|
int
|
Height of the displayed figure. |
3
|
image_width
|
int
|
Width of the displayed figure. |
3
|
display_positions
|
bool
|
If |
False
|
interpolation
|
str
|
Matplotlib interpolation method (e.g., 'nearest', 'bilinear'). |
None
|
image_size
|
int
|
Overrides both |
None
|
colorbar
|
str
|
Strategy for the color bar range.
|
None
|
mask
|
ndarray
|
A 3D segmentation mask to overlay on the volume. |
None
|
mask_alpha
|
float
|
Opacity of the mask overlay (0.0 to 1.0). |
0.4
|
mask_colormap
|
str
|
Matplotlib colormap name for the mask. |
'gray'
|
default_position
|
float or int
|
Initial slice position of the slider.
|
0.5
|
**matplotlib_imshow_kwargs
|
Additional keyword arguments passed to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
slicer_obj |
interactive
|
The interactive widget object containing the figure and slider. |
Example
import qim3d
# Load sample data
vol = qim3d.examples.bone_128x128x128
# Visualize with a slider
qim3d.viz.slicer(vol, colormap='bone')
Source code in qim3d/viz/_data_exploration.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | |
qim3d.viz.slices_grid
slices_grid(
volume,
slice_axis=0,
slice_positions=None,
n_slices=15,
max_columns=5,
colormap='magma',
min_value=None,
max_value=None,
image_size=None,
image_height=2,
image_width=2,
display_figure=False,
display_positions=True,
interpolation=None,
colorbar=False,
colorbar_style='small',
mask=None,
mask_alpha=0.4,
mask_colormap='gray',
**matplotlib_imshow_kwargs,
)
Creates a static grid visualization (montage) of multiple 2D slices from a 3D volume.
Generates a mosaic or gallery view of the dataset, ideal for reports, publications, or quick overviews.
Unlike interactive tools, this function produces a static matplotlib figure that can be saved easily.
It supports batch visualization of specific indices, relative positions (e.g., 'mid'), or automatically spaced intervals.
Key Features:
- Flexible Selection: Choose slices by specific index, relative strings ('start', 'mid', 'end'), or automatic linear spacing.
- Publication Ready: Control layout (
max_columns), sizing, and colorbars for export-ready figures. - Mask Overlays: Superimpose segmentation masks directly onto the slice grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The 3D input volume to be sliced. |
required |
slice_axis
|
int
|
The axis to slice along (e.g., 0 for Z, 1 for Y, 2 for X). |
0
|
slice_positions
|
int, list[int], str, or None
|
Determines which slices to display.
|
None
|
n_slices
|
int
|
The number of slices to display. Ignored if |
15
|
max_columns
|
int
|
The maximum number of columns in the grid layout. |
5
|
colormap
|
str or LinearSegmentedColormap
|
Matplotlib colormap name. |
'magma'
|
min_value
|
float
|
Minimum value for color scaling. If |
None
|
max_value
|
float
|
Maximum value for color scaling. If |
None
|
image_size
|
int
|
Overrides both |
None
|
image_height
|
int
|
Height of each subplot in inches. |
2
|
image_width
|
int
|
Width of each subplot in inches. |
2
|
display_figure
|
bool
|
If |
False
|
display_positions
|
bool
|
If |
True
|
interpolation
|
str
|
Matplotlib interpolation method (e.g., 'nearest', 'bilinear'). |
None
|
colorbar
|
bool
|
If |
False
|
colorbar_style
|
str
|
Visual style of the colorbar.
|
'small'
|
mask
|
ndarray
|
A 3D segmentation mask to overlay on the slices. |
None
|
mask_alpha
|
float
|
Opacity of the mask overlay (0.0 to 1.0). |
0.4
|
mask_colormap
|
str
|
Matplotlib colormap name for the mask. |
'gray'
|
**matplotlib_imshow_kwargs
|
Additional keyword arguments passed to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
The generated matplotlib figure object containing the grid of slices. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
ValueError
|
If |
Example
import qim3d
# Load sample data
vol = qim3d.examples.shell_225x128x128
# Create a grid of 15 linearly spaced slices
qim3d.viz.slices_grid(vol, n_slices=15)
Source code in qim3d/viz/_data_exploration.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
qim3d.viz.planes
Displays an interactive 3D scene with movable orthogonal cross-sections (X, Y, Z planes).
Creates a composite 3D viewer where three orthogonal slices intersect within the volume. Users can interactively drag sliders to explore the internal structure of the stack from different angles simultaneously. This visualization is often referred to as Multi-Planar Reconstruction (MPR) or an Orthogonal Slicer.
Key Features:
- 3D Context: Visualizes how the three planes (Axial, Coronal, Sagittal) intersect in 3D space.
- Interactive Controls: Includes sliders for position, opacity, and dynamic color range adjustment.
- High Performance: Uses
Plotlyandipywidgetsfor responsive slicing of local data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The 3D input volume. |
required |
colormap
|
str or Colormap
|
Matplotlib colormap name (e.g., 'magma', 'viridis'). |
'magma'
|
min_value
|
float
|
Minimum value for color scaling (lower bound of contrast). |
None
|
max_value
|
float
|
Maximum value for color scaling (upper bound of contrast). |
None
|
Example
import qim3d
# Load sample data
vol = qim3d.examples.shell_225x128x128
# Launch the interactive 3D plane viewer
qim3d.viz.planes(vol, colormap='plasma')
Source code in qim3d/viz/_data_exploration.py
qim3d.viz.slicer_orthogonal
slicer_orthogonal(
volume,
colormap='magma',
min_value=None,
max_value=None,
image_height=3,
image_width=3,
display_positions=False,
interpolation=None,
image_size=None,
colorbar=None,
mask=None,
mask_alpha=0.4,
mask_colormap='gray',
default_z=0.5,
default_y=0.5,
default_x=0.5,
)
Interactive tool to visualize three orthogonal views (Z, Y, X) side-by-side.
Creates a composite widget displaying Axial, Coronal, and Sagittal slices simultaneously. This is often called a Multi-Planar Reconstruction (MPR) view. It allows users to verify isotropy, check feature continuity across dimensions, or inspect segmentation masks in all three orientations at once.
Key Features:
- Simultaneous Views: Generates three independent sliders for Z, Y, and X axes.
- Linked Settings: Applies colormaps, contrast settings, and masks uniformly across all three views.
- Holistic Inspection: Essential for understanding the 3D structure without rendering a full 3D scene.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The 3D input volume. |
required |
colormap
|
str or LinearSegmentedColormap
|
Matplotlib colormap name. |
'magma'
|
min_value
|
float
|
Minimum value for color scaling. If |
None
|
max_value
|
float
|
Maximum value for color scaling. If |
None
|
image_height
|
int
|
Height of each individual figure in inches. |
3
|
image_width
|
int
|
Width of each individual figure in inches. |
3
|
display_positions
|
bool
|
If |
False
|
interpolation
|
str
|
Matplotlib interpolation method (e.g., 'nearest', 'bilinear'). |
None
|
image_size
|
int
|
Overrides |
None
|
colorbar
|
str
|
Strategy for the color bar range.
|
None
|
mask
|
ndarray
|
A 3D segmentation mask to overlay on all views. |
None
|
mask_alpha
|
float
|
Opacity of the mask overlay (0.0 to 1.0). |
0.4
|
mask_colormap
|
str
|
Matplotlib colormap name for the mask. |
'gray'
|
default_z
|
float or int
|
Initial position for the Z-axis slider (0.0-1.0 relative or exact index). |
0.5
|
default_y
|
float or int
|
Initial position for the Y-axis slider (0.0-1.0 relative or exact index). |
0.5
|
default_x
|
float or int
|
Initial position for the X-axis slider (0.0-1.0 relative or exact index). |
0.5
|
Returns:
| Name | Type | Description |
|---|---|---|
slicer_orthogonal_obj |
HBox
|
A container widget holding the three interactive slicers arranged horizontally. |
Example
import qim3d
# Load sample data
vol = qim3d.examples.fly_150x256x256
# View all three axes side-by-side
qim3d.viz.slicer_orthogonal(vol, colormap="magma")
Source code in qim3d/viz/_data_exploration.py
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | |
qim3d.viz.volumetric
volumetric(
volume,
aspectmode='data',
show=True,
save=False,
grid_visible=False,
colormap='magma',
constant_opacity=False,
opacity_function=None,
min_value=None,
max_value=None,
samples='auto',
max_voxels=256**3,
data_type='scaled_float16',
camera_mode='orbit',
**kwargs,
)
Renders a 3D volume using high-performance hardware-accelerated ray-casting.
Creates an interactive 3D visualization in the browser using K3D. This function is ideal for inspecting complex voxel data, understanding 3D spatial relationships, or creating exportable HTML representations of a stack. It handles large datasets by automatically downsampling if the size exceeds a set threshold.
Key Features:
- Browser-Based: Renders directly in Jupyter notebooks or exports to standalone HTML.
- Performance: Automatically manages sampling rates and data types (
float16) for smooth interaction. - Customization: Supports custom colormaps, opacity transfer functions, and camera modes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The 3D input data to be rendered. |
required |
aspectmode
|
str
|
Controls the proportions of the scene axes.
|
'data'
|
show
|
bool
|
If |
True
|
save
|
bool or str
|
Controls saving the output.
|
False
|
grid_visible
|
bool
|
If |
False
|
colormap
|
str, matplotlib.colors.Colormap, or list
|
Colormap for the rendering. Can be a Matplotlib name (e.g., 'magma') or object. |
'magma'
|
constant_opacity
|
bool
|
Deprecated. Use |
False
|
opacity_function
|
str or list
|
Defines the transparency transfer function.
|
None
|
min_value
|
float
|
Minimum value for color scaling. If |
None
|
max_value
|
float
|
Maximum value for color scaling. If |
None
|
samples
|
int or str
|
Number of ray-marching samples.
|
'auto'
|
max_voxels
|
int
|
Maximum number of voxels allowed before downsampling occurs (defaults to approx. 16 million). |
256 ** 3
|
data_type
|
str
|
Internal data type for rendering. |
'scaled_float16'
|
camera_mode
|
str
|
Interaction mode for the camera ( |
'orbit'
|
**kwargs
|
Additional keyword arguments passed to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
plot |
Plot
|
The K3D plot object. Returned if |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
Tip
The function can be used for object label visualization using a colormap created with qim3d.viz.colormaps.objects along with setting objects=True. The latter ensures appropriate rendering.
Example
Display a volume inline:
Save the rendering to an HTML file without displaying it:
Source code in qim3d/viz/_k3d.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
qim3d.viz.itk_vtk
Launches the ITK-VTK Viewer in a web browser to visualize 3D data.
Starts a local file server and opens a dedicated visualization window in your default web browser. This function is particularly effective for viewing OME-Zarr stores and other large datasets that benefit from on-demand loading. If the viewer is not found, it prompts to handle the installation automatically.
Key Features:
- Web-Based: Runs the visualization in a browser tab.
- Large Data Support: Efficiently streams data, making it ideal for large segmentation masks or multi-scale pyramids.
- Auto-Configuration: Manages local ports and installation dependencies automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or PathLike
|
Path to the file or OME-Zarr store to be visualized. |
None
|
open_browser
|
bool
|
If |
True
|
file_server_port
|
int
|
The port number for the local file server hosting the data. |
8042
|
viewer_port
|
int
|
The port number for the ITK-VTK viewer application. |
3000
|
Source code in qim3d/viz/itk_vtk_viewer/run.py
qim3d.viz.mesh
mesh(
mesh,
wireframe=False,
show_edges=True,
show=True,
save_screenshot='',
export_html='',
explode=0,
smooth_shading=False,
face_color='#cccccc',
edge_color='#993333',
**kwargs,
)
Visualize a 3D mesh using pygel3d or pyvista. If you need more advanced tools, use pyvista directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Manifold
|
The input mesh object. |
required |
wireframe
|
bool
|
If True, displays the mesh as a wireframe. Defaults to False. |
False
|
show_edges
|
bool
|
If True, shows edges of the mesh. Fefaults to True. |
True
|
show
|
bool
|
If True, displays the visualization inline, useful for multiple plots.
Works only with backend |
True
|
save_screenshot
|
str
|
If True, saves the visualization as an |
''
|
export_html
|
str
|
If True, saves the visualization as an |
''
|
explode
|
int
|
Only works when mesh is qim3d.mesh.VolumeMesh. Defines how spread are the tetrahedrons. If 0, the volume us intact. Defaults to 1. |
0
|
smooth_shading
|
bool
|
Smooths out edges. Only works with `pyvista'. Defaults to False. |
False
|
face_color
|
str
|
Face color of the mesh. Onyl works with |
'#cccccc'
|
edge_color
|
str
|
Edge color of the mesh. Only works with |
'#993333'
|
**kwargs
|
Any
|
Additional keyword arguments specific to the chosen backend:
- |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
The function displays the mesh but does not return a plot object. |
Example
import qim3d
# Generate a 3D blob
synthetic_blob = qim3d.generate.volume()
# Convert the 3D numpy array to a Pygel3D mesh object
mesh = qim3d.mesh.from_volume(synthetic_blob, mesh_precision=0.5)
# Visualize the generated mesh
qim3d.viz.mesh(mesh)
k3d_visualization
Source code in qim3d/viz/_mesh.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
qim3d.viz.iso_surface
Creates an interactive tool to visualize 3D iso-surfaces (surfaces of constant value).
Generates a GUI to extract and render 3D contours from the volume in real-time. This is useful for finding specific intensity boundaries, visualizing segmentation masks, or exploring the shape of objects defined by a specific threshold. It uses Plotly for interaction and includes controls for resolution and transparency.
Key Features:
- Interactive Thresholding: Adjust the iso-value dynamically to see how the surface changes.
- Performance Control: Adjustable resolution slider to balance between mesh quality and rendering speed.
- Visual Styles: Supports wireframe mode, transparency, and various colormaps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The 3D input volume to be visualized. |
required |
colormap
|
str
|
The initial color map name (e.g., 'Magma', 'Viridis'). Can be changed in the GUI. |
'Magma'
|
Source code in qim3d/viz/_data_exploration.py
qim3d.viz.export_rotation
export_rotation(
path,
volume,
degrees=360,
n_frames=180,
fps=30,
image_size=(256, 256),
colormap='magma',
camera_height=2.0,
camera_distance='auto',
camera_focus='center',
show=False,
)
Exports a 360-degree turntable animation of the volume to a video or GIF.
Generates a spinning orbit visualization of the 3D data, perfect for presentations, reports, or sharing results on the web. It renders the volume from a rotating camera perspective and saves the output as a movie file (.mp4, .webm, .avi) or an animated .gif.
Key Features:
- Presentation Ready: Creates smooth, professional animations of your data.
- Flexible Output: Supports common video formats and high-quality GIFs.
- Customizable Camera: Control the height, distance, and focus point of the rotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The destination file path. Must end with .gif, .avi, .mp4, or .webm. If no extension is provided, defaults to .gif. |
required |
volume
|
ndarray
|
The 3D input volume to be animated. |
required |
degrees
|
int
|
Total rotation angle in degrees (e.g., 360 for a full spin). |
360
|
n_frames
|
int
|
Total number of frames to generate. Higher values create smoother/slower animations at fixed FPS. |
180
|
fps
|
int
|
Frames per second. Controls the playback speed. |
30
|
image_size
|
tuple[int, int] or None
|
Resolution (width, height) of the output frames. |
(256, 256)
|
colormap
|
str
|
Matplotlib colormap name for the volume rendering. |
'magma'
|
camera_height
|
float
|
Vertical position of the camera relative to the volume's Z-axis height. |
2.0
|
camera_distance
|
float or str
|
Distance from the camera to the focus point.
|
'auto'
|
camera_focus
|
list or str
|
The point the camera rotates around.
|
'center'
|
show
|
bool
|
If |
False
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Example
Creation of .gif file with default parameters of a generated volume.
Example
Creation of a .webm file with specified parameters of a generated volume in the shape of a tube.
import qim3d
vol = qim3d.generate.volume(shape='tube')
qim3d.viz.export_rotation('test.webm', vol,
degrees = 360,
n_frames = 120,
fps = 30,
image_size = (512,512),
camera_height = 3.0,
camera_distance = 'auto',
camera_focus = 'center',
show = True)
Source code in qim3d/viz/_data_exploration.py
2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 | |