Plot and render
Visualization of volumetric data.
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 |
|
qim3d.viz.circles
Plots the blobs found on a slice of the volume.
This function takes in a 3D volume and a list of blobs (detected features) and plots the blobs on a specified slice of the volume. If no slice is specified, it defaults to the middle slice of the volume.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
blobs
|
ndarray
|
An array-like object of blobs, where each blob is represented
as a 4-tuple (p, r, c, radius). Usually the result of |
required |
vol
|
ndarray
|
The 3D volume on which to plot the blobs. |
required |
alpha
|
float
|
The transparency of the blobs. Defaults to 0.5. |
0.5
|
color
|
str
|
The color of the blobs. Defaults to "#ff9900". |
'#ff9900'
|
**kwargs
|
Any
|
Arbitrary keyword arguments for the |
{}
|
Returns:
Name | Type | Description |
---|---|---|
slicer_obj |
interactive
|
An interactive widget for visualizing the blobs. |
Example
import qim3d
import qim3d.detection
# Get data
vol = qim3d.examples.cement_128x128x128
# Detect blobs, and get binary mask
blobs, _ = qim3d.detection.blobs(
vol,
min_sigma=1,
max_sigma=8,
threshold=0.001,
overlap=0.1,
background="bright"
)
# Visualize detected blobs with circles method
qim3d.viz.circles(blobs, vol, alpha=0.8, color='blue')

Source code in qim3d/viz/_detection.py
qim3d.viz.local_thickness
local_thickness(
image,
image_lt,
max_projection=False,
axis=0,
slice_idx=None,
show=False,
figsize=(15, 5),
)
Visualizes the local thickness of a 2D or 3D image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
ndarray
|
2D or 3D NumPy array representing the image/volume. |
required |
image_lt
|
ndarray
|
2D or 3D NumPy array representing the local thickness of the input image/volume. |
required |
max_projection
|
bool
|
If True, displays the maximum projection of the local thickness. Only used for 3D images. Defaults to False. |
False
|
axis
|
int
|
The axis along which to visualize the local thickness. Unused for 2D images. Defaults to 0. |
0
|
slice_idx
|
int or float
|
The initial slice to be visualized. The slice index can afterwards be changed. If value is an integer, it will be the index of the slice to be visualized. If value is a float between 0 and 1, it will be multiplied by the number of slices and rounded to the nearest integer. If None, the middle slice will be used for 3D images. Unused for 2D images. Defaults to None. |
None
|
show
|
bool
|
If True, displays the plot (i.e. calls plt.show()). Defaults to False. |
False
|
figsize
|
tuple
|
The size of the figure. Defaults to (15, 5). |
(15, 5)
|
Raises:
Type | Description |
---|---|
ValueError
|
If the slice index is not an integer or a float between 0 and 1. |
Returns:
Name | Type | Description |
---|---|---|
local_thickness |
interactive or Figure
|
If the input is 3D, returns an interactive widget. Otherwise, returns a matplotlib figure. |
Example
import qim3d
fly = qim3d.examples.fly_150x256x256
lt_fly = qim3d.processing.local_thickness(fly)
qim3d.viz.local_thickness(fly, lt_fly, axis=0)

Source code in qim3d/viz/_local_thickness.py
10 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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
qim3d.viz.vectors
vectors(
volume,
vec,
axis=0,
volume_cmap='grey',
vmin=None,
vmax=None,
slice_idx=None,
grid_size=10,
interactive=True,
figsize=(10, 5),
show=False,
)
Visualizes the orientation of the structures in a 3D volume using the eigenvectors of the structure tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
volume
|
ndarray
|
The 3D volume to be sliced. |
required |
vec
|
ndarray
|
The eigenvectors of the structure tensor. |
required |
axis
|
int
|
The axis along which to visualize the orientation. Defaults to 0. |
0
|
volume_cmap
|
str
|
Defines colormap for display of the volume |
'grey'
|
vmin
|
float
|
Together with vmax define the data range the colormap covers. By default colormap covers the full range. Defaults to None. |
None
|
vmax
|
float
|
Together with vmin define the data range the colormap covers. By default colormap covers the full range. Defaults to None |
None
|
slice_idx
|
int or float or None
|
The initial slice to be visualized. The slice index can afterwards be changed. If value is an integer, it will be the index of the slice to be visualized. If value is a float between 0 and 1, it will be multiplied by the number of slices and rounded to the nearest integer. If None, the middle slice will be used. Defaults to None. |
None
|
grid_size
|
int
|
The size of the grid. Defaults to 10. |
10
|
interactive
|
bool
|
If True, returns an interactive widget. Defaults to True. |
True
|
figsize
|
tuple
|
The size of the figure. Defaults to (15, 5). |
(10, 5)
|
show
|
bool
|
If True, displays the plot (i.e. calls plt.show()). Defaults to False. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
If the axis to slice along is not 0, 1, or 2. |
ValueError
|
If the slice index is not an integer or a float between 0 and 1. |
Returns:
Name | Type | Description |
---|---|---|
fig |
interactive or Figure
|
If |
Note
The orientation of the vectors is visualized using an HSV color map, where the saturation corresponds to the vector component
of the slicing direction (i.e. z-component when choosing visualization along axis = 0
). Hence, if an orientation in the volume
is orthogonal to the slicing direction, the corresponding color of the visualization will be gray.
Example
import qim3d
vol = qim3d.examples.NT_128x128x128
val, vec = qim3d.processing.structure_tensor(vol)
# Visualize the structure tensor
qim3d.viz.vectors(vol, vec, axis = 2, interactive = True)

Source code in qim3d/viz/_structure_tensor.py
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 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 |
|