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,
color_map='magma',
value_min=None,
value_max=None,
image_height=3,
image_width=3,
display_positions=False,
interpolation=None,
image_size=None,
color_bar=None,
mask=None,
mask_alpha=0.4,
mask_color_map='gray',
default_position=0.5,
**matplotlib_imshow_kwargs,
)
Interactive widget for visualizing slices of a 3D volume.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
volume
|
ndarray
|
The 3D volume to be sliced. |
required |
slice_axis
|
int
|
Specifies the axis, or dimension, along which to slice. Defaults to 0. |
0
|
color_map
|
str or LinearSegmentedColormap
|
Specifies the color map for the image. Defaults to 'magma'. |
'magma'
|
value_min
|
float
|
Together with value_max define the data range the colormap covers. By default colormap covers the full range. Defaults to None. |
None
|
value_max
|
float
|
Together with value_min define the data range the colormap covers. By default colormap covers the full range. Defaults to None |
None
|
image_height
|
int
|
Height of the figure. Defaults to 3. |
3
|
image_width
|
int
|
Width of the figure. Defaults to 3. |
3
|
display_positions
|
bool
|
If True, displays the position of the slices. Defaults to False. |
False
|
interpolation
|
str
|
Specifies the interpolation method for the image. Defaults to None. |
None
|
image_size
|
int
|
Size of the figure. If set, image_height and image_width are ignored. Defaults to None. |
None
|
color_bar
|
str
|
Controls the options for color bar. If None, no color bar is included. If 'volume', the color map range is constant for each slice. If 'slices', the color map range changes dynamically according to the slice. Defaults to None. |
None
|
mask
|
ndarray
|
Overlays the image with this segmentation mask. Defaults to None. |
None
|
mask_alpha
|
float
|
Sets the alpha of the overlaying mask. Defaults to 0.4. |
0.4
|
mask_color_map
|
str
|
Sets the color map of the overlaying mask. Defaults to 'gray'. |
'gray'
|
default_position
|
float | int
|
Set the x slicer to this slice after reload. If float, it should be between 0 and 1 to set position relative to shape. If int, it sets the exact slice. Defaults to 0.5. |
0.5
|
**matplotlib_imshow_kwargs
|
Any
|
Additional keyword arguments to pass to the |
{}
|
Returns:
Name | Type | Description |
---|---|---|
slicer_obj |
interactive
|
The interactive widget for visualizing slices of a 3D volume. |
Source code in qim3d/viz/_data_exploration.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 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 |
|
qim3d.viz.slices_grid
slices_grid(
volume,
slice_axis=0,
slice_positions=None,
num_slices=15,
max_columns=5,
color_map='magma',
value_min=None,
value_max=None,
image_size=None,
image_height=2,
image_width=2,
display_figure=False,
display_positions=True,
interpolation=None,
color_bar=False,
color_bar_style='small',
mask=None,
mask_alpha=0.4,
mask_color_map='gray',
**matplotlib_imshow_kwargs,
)
Displays one or several slices from a 3d volume.
By default if slice_positions
is None, slices_grid plots num_slices
linearly spaced slices.
If slice_positions
is given as a string or integer, slices_grid will plot an overview with num_slices
figures around that position.
If slice_positions
is given as a list, num_slices
will be ignored and the slices from slice_positions
will be plotted.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
volume
|
ndarray
|
The 3D volume to be sliced. |
required |
slice_axis
|
int
|
Specifies the axis, or dimension, along which to slice. Defaults to 0. |
0
|
slice_positions
|
int or list[int] or str or None
|
One or several slicing levels. If None, linearly spaced slices will be displayed. Defaults to None. |
None
|
num_slices
|
int
|
Defines how many slices the user wants to be displayed. Defaults to 15. |
15
|
max_columns
|
int
|
The maximum number of columns to be plotted. Defaults to 5. |
5
|
color_map
|
str or LinearSegmentedColormap
|
Specifies the color map for the image. Defaults to "magma". |
'magma'
|
value_min
|
float
|
Together with value_max define the data range the colormap covers. By default colormap covers the full range. Defaults to None. |
None
|
value_max
|
float
|
Together with value_min define the data range the colormap covers. By default colormap covers the full range. Defaults to None |
None
|
image_size
|
int
|
Size of the figure. If set, image_height and image_width are ignored. |
None
|
image_height
|
int
|
Height of the figure. |
2
|
image_width
|
int
|
Width of the figure. |
2
|
display_figure
|
bool
|
If True, displays the plot (i.e. calls plt.show()). Defaults to False. |
False
|
display_positions
|
bool
|
If True, displays the position of the slices. Defaults to True. |
True
|
interpolation
|
str
|
Specifies the interpolation method for the image. Defaults to None. |
None
|
color_bar
|
bool
|
Adds a colorbar positioned in the top-right for the corresponding colormap and data range. Defaults to False. |
False
|
color_bar_style
|
str
|
Determines the style of the colorbar. Option 'small' is height of one image row. Option 'large' spans full height of image grid. Defaults to 'small'. |
'small'
|
**matplotlib_imshow_kwargs
|
Any
|
Additional keyword arguments to pass to the |
{}
|
Returns:
Name | Type | Description |
---|---|---|
fig |
Figure
|
The figure with the slices from the 3d array. |
Raises:
Type | Description |
---|---|
ValueError
|
If the input is not a numpy.ndarray or da.core.Array. |
ValueError
|
If the slice_axis to slice along is not a valid choice, i.e. not an integer between 0 and the number of dimensions of the volume minus 1. |
ValueError
|
If the file or array is not a volume with at least 3 dimensions. |
ValueError
|
If the |
ValueError
|
If the color_bar_style keyword argument is not one of the following strings: 'small' or 'large'. |
Example

Source code in qim3d/viz/_data_exploration.py
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 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 |
|
qim3d.viz.planes
Displays an interactive 3D widget for viewing orthogonal cross-sections through a volume.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
volume
|
ndarray
|
The 3D volume of interest. |
required |
color_map
|
str or Colormap
|
Specifies the matplotlib color map. |
'magma'
|
value_min
|
float
|
Together with value_max define the data range the colormap covers. By default colormap covers the full range. |
None
|
value_max
|
float
|
Together with value_min define the data range the colormap covers. By default colormap covers the full range. |
None
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in qim3d/viz/_data_exploration.py
qim3d.viz.slicer_orthogonal
slicer_orthogonal(
volume,
color_map='magma',
value_min=None,
value_max=None,
image_height=3,
image_width=3,
display_positions=False,
interpolation=None,
image_size=None,
color_bar=None,
mask=None,
mask_alpha=0.4,
mask_color_map='gray',
default_z=0.5,
default_y=0.5,
default_x=0.5,
)
Interactive widget for visualizing orthogonal slices of a 3D volume.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
volume
|
ndarray
|
The 3D volume to be sliced. |
required |
color_map
|
str or LinearSegmentedColormap
|
Specifies the color map for the image. Defaults to "magma". |
'magma'
|
value_min
|
float
|
Together with value_max define the data range the colormap covers. By default colormap covers the full range. Defaults to None. |
None
|
value_max
|
float
|
Together with value_min define the data range the colormap covers. By default colormap covers the full range. Defaults to None |
None
|
image_height
|
int
|
Height of the figure. |
3
|
image_width
|
int
|
Width of the figure. |
3
|
display_positions
|
bool
|
If True, displays the position of the slices. Defaults to False. |
False
|
interpolation
|
str
|
Specifies the interpolation method for the image. Defaults to None. |
None
|
image_size
|
int
|
Size of the figure. If set, image_height and image_width are ignored. Defaults to None. |
None
|
color_bar
|
str
|
Controls the options for color bar. If None, no color bar is included. If 'volume', the color map range is constant for each slice. If 'slices', the color map range changes dynamically according to the slice. Defaults to None. |
None
|
mask
|
ndarray
|
Overlays the image with this segmentation mask. Defaults to None. |
None
|
mask_alpha
|
float
|
Sets the alpha of the overlaying mask. Defaults to 0.4. |
0.4
|
mask_color_map
|
str
|
Sets the color map of the overlaying mask. Defaults to 'gray'. |
'gray'
|
default_x
|
float | int
|
Set the x slicer to this slice after reload. If float, it should be between 0 and 1 to set position relative to shape. If int, it sets the exact slice. Defaults to 0.5. |
0.5
|
default_y
|
float | int
|
Set the x slicer to this slice after reload. If float, it should be between 0 and 1 to set position relative to shape. If int, it sets the exact slice. Defaults to 0.5. |
0.5
|
default_z
|
float | int
|
Set the x slicer to this slice after reload. If float, it should be between 0 and 1 to set position relative to shape. If int, it sets the exact slice. Defaults to 0.5. |
0.5
|
Returns:
Name | Type | Description |
---|---|---|
slicer_orthogonal_obj |
HBox
|
The interactive widget for visualizing orthogonal slices of a 3D volume. |
Example
import qim3d
vol = qim3d.examples.fly_150x256x256
qim3d.viz.slicer_orthogonal(vol, color_map="magma")

Source code in qim3d/viz/_data_exploration.py
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 532 533 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 |
|
qim3d.viz.volumetric
volumetric(
volume,
aspectmode='data',
show=True,
save=False,
grid_visible=False,
color_map='magma',
constant_opacity=False,
opacity_function=None,
vmin=None,
vmax=None,
samples='auto',
max_voxels=256**3,
data_type='scaled_float16',
camera_mode='orbit',
**kwargs,
)
Visualizes a 3D volume using volumetric rendering.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
volume
|
ndarray
|
The input 3D image data. It should be a 3D numpy array. |
required |
aspectmode
|
str
|
Determines the proportions of the scene's axes. Defaults to "data".
If |
'data'
|
show
|
bool
|
If True, displays the visualization inline. Defaults to True. |
True
|
save
|
bool or str
|
If True, saves the visualization as an HTML file. If a string is provided, it's interpreted as the file path where the HTML file will be saved. Defaults to False. |
False
|
grid_visible
|
bool
|
If True, the grid is visible in the plot. Defaults to False. |
False
|
color_map
|
str or Colormap or list
|
The color map to be used for the volume rendering. If a string is passed, it should be a matplotlib colormap name. Defaults to 'magma'. |
'magma'
|
constant_opacity
|
bool
|
Set to True if doing an object label visualization with a corresponding color_map; otherwise, the plot may appear poorly. Defaults to False. |
False
|
opacity_function
|
str or list
|
Applies an opacity function to the plot, enabling custom values for opaqueness. Set to True if doing an object label visualization with a corresponding color_map; otherwise, the plot may appear poorly. Defaults to []. |
None
|
vmin
|
float or None
|
Together with vmax defines the data range the colormap covers. By default colormap covers the full range. Defaults to None. |
None
|
vmax
|
float or None
|
Together with vmin defines the data range the colormap covers. By default colormap covers the full range. Defaults to None |
None
|
samples
|
int or auto
|
The number of samples to be used for the volume rendering in k3d. Input 'auto' for auto selection. Defaults to 'auto'. Lower values will render faster but with lower quality. |
'auto'
|
max_voxels
|
int
|
Defaults to 256^3. |
256 ** 3
|
data_type
|
str
|
Default to 'scaled_float16'. |
'scaled_float16'
|
camera_mode
|
str
|
Camera interaction mode, being 'orbit', 'trackball' or 'fly'. Defaults to 'orbit'. |
'orbit'
|
**kwargs
|
Any
|
Additional keyword arguments to be passed to the |
{}
|
Returns:
Name | Type | Description |
---|---|---|
plot |
plot
|
If |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Tip
The function can be used for object label visualization using a color_map
created with qim3d.viz.colormaps.objects
along with setting objects=True
. The latter ensures appropriate rendering.
Example
Display a volume inline:
Save a plot to an HTML file:
Source code in qim3d/viz/_k3d.py
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 |
|
qim3d.viz.itk_vtk
Command to run in cli/init.py. Tries to run the vizualization, if that fails, asks the user to install it. This function is needed here so we don't have to import NotInstalledError and Installer, which exposes these to user.
Source code in qim3d/viz/itk_vtk_viewer/run.py
qim3d.viz.mesh
mesh(
mesh,
backend='pygel3d',
wireframe=True,
flat_shading=True,
grid_visible=False,
show=True,
save=False,
**kwargs,
)
Visualize a 3D mesh using pygel3d
or k3d
. The visualization with the pygel3d backend provides higher-quality rendering, but it may take more time compared to using the k3d backend.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mesh
|
Manifold
|
The input mesh object. |
required |
backend
|
str
|
The visualization backend to use.
Choose between |
'pygel3d'
|
wireframe
|
bool
|
If True, displays the mesh as a wireframe.
Works both with backend |
True
|
flat_shading
|
bool
|
If True, applies flat shading to the mesh.
Works only with backend |
True
|
grid_visible
|
bool
|
If True, shows a grid in the visualization.
Works only with backend |
False
|
show
|
bool
|
If True, displays the visualization inline, useful for multiple plots.
Works only with backend |
True
|
save
|
bool or str
|
If True, saves the visualization as an HTML file.
If a string is provided, it's interpreted as the file path where the HTML
file will be saved. Works only with the backend |
False
|
**kwargs
|
Any
|
Additional keyword arguments specific to the chosen backend:
|
{}
|
Returns:
Type | Description |
---|---|
Plot | FigureWidget | None
|
k3d.Plot or None:
|
Raises:
Type | Description |
---|---|
ValueError
|
If |
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)


Source code in qim3d/viz/_k3d.py
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 |
|
qim3d.viz.iso_surface
Creates an interactive iso-surface visualizer for a single surface level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vol
|
ndarray
|
Volume to visualize an iso-surface of. |
required |
colormap
|
str
|
(str, optional): Initial colormap for the iso-surface. This can be changed in the interface |
'Magma'
|
Source code in qim3d/viz/_data_exploration.py
qim3d.viz.export_rotation
export_rotation(
path,
vol,
degrees=360,
num_frames=180,
fps=30,
image_size=(256, 256),
color_map='magma',
camera_height=2.0,
camera_distance='auto',
camera_focus='center',
show=False,
)
Export a rotation animation of volume.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
The path to save the output. The path should end with .gif, .avi, .mp4 or .webm. If no file extension is specified, .gif is automatically added. |
required |
vol
|
ndarray
|
Volume to create .gif of. |
required |
degrees
|
int
|
The amount of degrees for the volume to rotate. Defaults to 360. |
360
|
num_frames
|
int
|
The amount of frames to generate. Defaults to 180. |
180
|
fps
|
int
|
The amount of frames per second in the resulting animation. This determines the speed of the rotation of the volume. Defaults to 30. |
30
|
image_size
|
tuple of ints or None
|
Pixel size (width, height) of each frame. If None, the plotter's default size is used. Defaults to (256, 256). |
(256, 256)
|
color_map
|
str
|
Determines color map of volume. Defaults to 'magma'. |
'magma'
|
camera_height
|
float
|
Determines the height of the camera rotating around the volume. The float value represents a multiple of the height of the z-axis. Defaults to 2.0. |
2.0
|
camera_distance
|
int or string
|
Determines the distance of the camera from the center point. If 'auto' is used, it will be auto calculated. Otherwise a float value representing voxel distance is expected. Defaults to 'auto'. |
'auto'
|
camera_focus
|
list or str
|
Determines the voxel that the camera rotates around. Using 'center' will default to the center of the volume. Otherwise a list of three integers is expected. Defaults to 'center'. |
'center'
|
show
|
bool
|
If True, the resulting animation will be shown in the Jupyter notebook. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
TypeError
|
If the camera focus argument is incorrectly used. |
TypeError
|
If the camera_distance argument is incorrectly used. |
ValueError
|
If the path contains an unrecognized file extension. |
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,
num_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
2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 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 |
|