Data visualization
The qim3d
library aims to provide easy ways to explore and get insights from volumetric data.
qim3d.viz
qim3d.viz.slices
slices(vol, axis=0, position=None, n_slices=5, max_cols=5, cmap='viridis', vmin=None, vmax=None, img_height=2, img_width=2, show=False, show_position=True, interpolation='none', img_size=None, cbar=False, **imshow_kwargs)
Displays one or several slices from a 3d volume.
By default if position
is None, slices plots n_slices
linearly spaced slices.
If position
is given as a string or integer, slices will plot an overview with n_slices
figures around that position.
If position
is given as a list, n_slices
will be ignored and the slices from position
will be plotted.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vol |
ndarray
|
The 3D volume to be sliced. |
required |
axis |
int
|
Specifies the axis, or dimension, along which to slice. Defaults to 0. |
0
|
position |
(str, int, list)
|
One or several slicing levels. If None, linearly spaced slices will be displayed. Defaults to None. |
None
|
n_slices |
int
|
Defines how many slices the user wants to be displayed. Defaults to 5. |
5
|
max_cols |
int
|
The maximum number of columns to be plotted. Defaults to 5. |
5
|
cmap |
str
|
Specifies the color map for the image. Defaults to "viridis". |
'viridis'
|
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
|
img_height |
int
|
Height of the figure. |
2
|
img_width |
int
|
Width of the figure. |
2
|
show |
bool
|
If True, displays the plot (i.e. calls plt.show()). Defaults to False. |
False
|
show_position |
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'
|
cbar |
bool
|
Adds a colorbar positioned in the top-right for the corresponding colormap and data range. Defaults to False. |
False
|
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 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 |
Source code in qim3d/viz/explore.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 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 |
|
qim3d.viz.slicer
slicer(vol, axis=0, cmap='viridis', vmin=None, vmax=None, img_height=3, img_width=3, show_position=False, interpolation='none', img_size=None, cbar=False, **imshow_kwargs)
Interactive widget for visualizing slices of a 3D volume.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vol |
ndarray
|
The 3D volume to be sliced. |
required |
axis |
int
|
Specifies the axis, or dimension, along which to slice. Defaults to 0. |
0
|
cmap |
str
|
Specifies the color map for the image. Defaults to "viridis". |
'viridis'
|
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
|
img_height |
int
|
Height of the figure. Defaults to 3. |
3
|
img_width |
int
|
Width of the figure. Defaults to 3. |
3
|
show_position |
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'
|
cbar |
bool
|
Adds a colorbar for the corresponding colormap and data range. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
slicer_obj |
interactive
|
The interactive widget for visualizing slices of a 3D volume. |
Source code in qim3d/viz/explore.py
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 |
|
qim3d.viz.orthogonal
orthogonal(vol, cmap='viridis', vmin=None, vmax=None, img_height=3, img_width=3, show_position=False, interpolation=None, img_size=None)
Interactive widget for visualizing orthogonal slices of a 3D volume.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vol |
ndarray
|
The 3D volume to be sliced. |
required |
cmap |
str
|
Specifies the color map for the image. Defaults to "viridis". |
'viridis'
|
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
|
img_height |
int
|
Height of the figure. |
3
|
img_width |
int
|
Width of the figure. |
3
|
show_position |
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
|
Returns:
Name | Type | Description |
---|---|---|
orthogonal_obj |
HBox
|
The interactive widget for visualizing orthogonal slices of a 3D volume. |
Source code in qim3d/viz/explore.py
qim3d.viz.vol
vol(img, aspectmode='data', show=True, save=False, grid_visible=False, cmap=None, vmin=None, vmax=None, samples='auto', max_voxels=512 ** 3, data_type='scaled_float16', **kwargs)
Visualizes a 3D volume using volumetric rendering.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img |
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
|
cmap |
list
|
The color map to be used for the volume rendering. Defaults to None. |
None
|
vmin |
float
|
Together with vmax defines the data range the colormap covers. By default colormap covers the full range. Defaults to None. |
None
|
vmax |
float
|
Together with vmin defines the data range the colormap covers. By default colormap covers the full range. Defaults to None |
None
|
samples |
int
|
The number of samples to be used for the volume rendering in k3d. Defaults to 512. Lower values will render faster but with lower quality. |
'auto'
|
max_voxels |
int
|
Defaults to 512^3. |
512 ** 3
|
data_type |
str
|
Default to 'scaled_float16'. |
'scaled_float16'
|
**kwargs |
Additional keyword arguments to be passed to the |
{}
|
Returns:
Name | Type | Description |
---|---|---|
plot |
plot
|
If |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Example
Display a volume inline:
Save a plot to an HTML file:
Source code in qim3d/viz/k3d.py
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 137 138 139 140 141 142 143 144 145 146 147 |
|
qim3d.viz.chunks
Function to visualize chunks of a Zarr dataset using the specified visualization method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
zarr_path |
str
|
Path to the Zarr dataset. |
required |
**kwargs |
Additional keyword arguments to pass to the visualization method. |
{}
|
Example
Source code in qim3d/viz/explore.py
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 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 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 |
|
qim3d.viz.itk_vtk
Opens a visualization window using the itk-vtk-viewer. Works both for common file types (Tiff, Nifti, etc.) and for OME-Zarr stores.
This function starts the itk-vtk-viewer, either using a global installation or a local installation within the QIM package. It also starts an HTTP server to serve the file to the viewer. Optionally, it can automatically open a browser window to display the viewer. If the viewer is not installed, it raises a NotInstalledError.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Path to the file or OME-Zarr store to be visualized. Trailing slashes in the path are normalized. Defaults to None. |
None
|
open_browser |
bool
|
If True, opens the visualization in a new browser tab. Defaults to True. |
True
|
file_server_port |
int
|
The port number for the local file server that hosts the store. Defaults to 8042. |
8042
|
viewer_port |
int
|
The port number for the itk-vtk-viewer server. Defaults to 3000. |
3000
|
Raises:
Type | Description |
---|---|
NotInstalledError
|
Raised if the itk-vtk-viewer is not installed in the expected location. |
Example
import qim3d
# Download data
downloader = qim3d.io.Downloader()
data = downloader.Okinawa_Forams.Okinawa_Foram_1(load_file=True, virtual_stack=True)
# Export to OME-Zarr
qim3d.io.export_ome_zarr("Okinawa_Foram_1.zarr", data)
# Start visualization
qim3d.viz.itk_vtk("Okinawa_Foram_1.zarr")
Downloading Okinawa_Foram_1.tif https://archive.compute.dtu.dk/download/public/projects/viscomp_data_repository/Okinawa_Forams/Okinawa_Foram_1.tif 1.85GB [00:17, 111MB/s] Loading Okinawa_Foram_1.tif Loading: 100%  1.85GB/1.85GB  [00:02<00:00, 762MB/s] Loaded shape: (995, 1014, 984) Using virtual stack Exporting data to OME-Zarr format at Okinawa_Foram_1.zarr Number of scales: 5 Creating a multi-scale pyramid - Scale 0: (995, 1014, 984) - Scale 1: (498, 507, 492) - Scale 2: (249, 254, 246) - Scale 3: (124, 127, 123) - Scale 4: (62, 63, 62) Writing data to disk All done! itk-vtk-viewer => Serving /home/fima/Notebooks/Qim3d on port 3000 enp0s31f6 => http://10.52.0.158:3000/ wlp0s20f3 => http://10.197.104.229:3000/ Serving directory '/home/fima/Notebooks/Qim3d' http://localhost:8042/ Visualization url: http://localhost:3000/?rotate=false&fileToLoad=http://localhost:8042/Okinawa_Foram_1.zarr
Source code in qim3d/viz/itk_vtk_viewer/run.py
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 |
|
qim3d.viz.mesh
mesh(verts, faces, wireframe=True, flat_shading=True, grid_visible=False, show=True, save=False, **kwargs)
Visualizes a 3D mesh using K3D.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
verts |
ndarray
|
A 2D array (Nx3) containing the vertices of the mesh. |
required |
faces |
ndarray
|
A 2D array (Mx3) containing the indices of the mesh faces. |
required |
wireframe |
bool
|
If True, the mesh is rendered as a wireframe. Defaults to True. |
True
|
flat_shading |
bool
|
If True, flat shading is applied to the mesh. Defaults to True. |
True
|
grid_visible |
bool
|
If True, the grid is visible in the plot. Defaults to False. |
False
|
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
|
**kwargs |
Additional keyword arguments to be passed to the |
{}
|
Returns:
Name | Type | Description |
---|---|---|
plot |
plot
|
If |
Example
Source code in qim3d/viz/k3d.py
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 |
|
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[int, int]
|
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:
Type | Description |
---|---|
Union[Figure, interactive]
|
If the input is 3D, returns an interactive widget. Otherwise, returns a matplotlib figure. |
Example
Source code in qim3d/viz/local_thickness_.py
7 8 9 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 |
|
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
|
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[int, int]
|
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 |
Union[Figure, interactive]
|
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
Source code in qim3d/viz/structure_tensor.py
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 315 316 |
|
qim3d.viz.plot_cc
plot_cc(connected_components, component_indexs=None, max_cc_to_plot=32, overlay=None, crop=False, show=True, cmap='viridis', vmin=None, vmax=None, **kwargs)
Plots the connected components from a qim3d.processing.cc.CC
object. If an overlay image is provided, the connected component will be masked to the overlay image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
connected_components |
CC
|
The connected components object. |
required |
component_indexs |
list | tuple
|
The components to plot. If None the first max_cc_to_plot=32 components will be plotted. Defaults to None. |
None
|
max_cc_to_plot |
int
|
The maximum number of connected components to plot. Defaults to 32. |
32
|
overlay |
optional
|
Overlay image. Defaults to None. |
None
|
crop |
bool
|
Whether to crop the image to the cc. Defaults to False. |
False
|
show |
bool
|
Whether to show the figure. Defaults to True. |
True
|
cmap |
str
|
Specifies the color map for the image. Defaults to "viridis". |
'viridis'
|
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
|
**kwargs |
Additional keyword arguments to pass to |
{}
|
Returns:
Name | Type | Description |
---|---|---|
figs |
list[Figure]
|
List of figures, if |
Example
import qim3d
vol = qim3d.examples.cement_128x128x128[50:150]
vol_bin = vol<80
cc = qim3d.processing.get_3d_cc(vol_bin)
qim3d.viz.plot_cc(cc, crop=True, show=True, overlay=None, n_slices=5, component_indexs=[4,6,7])
qim3d.viz.plot_cc(cc, crop=True, show=True, overlay=vol, n_slices=5, component_indexs=[4,6,7])
Source code in qim3d/viz/cc.py
qim3d.viz.interactive_fade_mask
Interactive widget for visualizing the effect of edge fading on a 3D volume.
This can be used to select the best parameters before applying the mask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vol |
ndarray
|
The volume to apply edge fading to. |
required |
axis |
int
|
The axis along which to apply the fading. Defaults to 0. |
0
|
cmap |
str
|
Specifies the color map for the image. Defaults to "viridis". |
'viridis'
|
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
|
Source code in qim3d/viz/explore.py
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 |
|
qim3d.viz.colormaps
This module provides a collection of colormaps useful for 3D visualization.
qim3d.viz.colormaps.qim
module-attribute
qim3d.viz.colormaps.objects
objects(nlabels, style='bright', first_color_background=True, last_color_background=False, background_color=(0.0, 0.0, 0.0), min_dist=0.5, seed=19)
Creates a random colormap to be used together with matplotlib. Useful for segmentation tasks
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nlabels |
int
|
Number of labels (size of colormap). |
required |
style |
str
|
'bright' for strong colors, 'soft' for pastel colors, 'earth' for yellow/green/blue colors, 'ocean' for blue/purple/pink colors. Defaults to 'bright'. |
'bright'
|
first_color_background |
bool
|
If True, the first color is used as background. Defaults to True. |
True
|
last_color_background |
bool
|
If True, the last color is used as background. Defaults to False. |
False
|
background_color |
tuple or str
|
RGB tuple or string for background color. Can be "black" or "white". Defaults to (0.0, 0.0, 0.0). |
(0.0, 0.0, 0.0)
|
min_dist |
int
|
Minimum distance between neighboring colors. Defaults to 0.5. |
0.5
|
seed |
int
|
Seed for random number generator. Defaults to 19. |
19
|
Returns:
Name | Type | Description |
---|---|---|
cmap |
LinearSegmentedColormap
|
Colormap for matplotlib |
Example
import qim3d
cmap_bright = qim3d.viz.colormaps.objects(nlabels=100, style = 'bright', first_color_background=True, background_color="black", min_dist=0.7)
cmap_soft = qim3d.viz.colormaps.objects(nlabels=100, style = 'soft', first_color_background=True, background_color="black", min_dist=0.2)
cmap_earth = qim3d.viz.colormaps.objects(nlabels=100, style = 'earth', first_color_background=True, background_color="black", min_dist=0.8)
cmap_ocean = qim3d.viz.colormaps.objects(nlabels=100, style = 'ocean', first_color_background=True, background_color="black", min_dist=0.9)
display(cmap_bright)
display(cmap_soft)
display(cmap_earth)
display(cmap_ocean)
import qim3d
vol = qim3d.examples.cement_128x128x128
binary = qim3d.processing.filters.gaussian(vol, sigma = 2) < 60
labeled_volume, num_labels = qim3d.processing.operations.watershed(binary)
cmap = qim3d.viz.colormaps.objects(num_labels, style = 'bright')
qim3d.viz.slicer(labeled_volume, axis = 1, cmap=cmap)
Tip
The min_dist
parameter can be used to control the distance between neighboring colors.
Source code in qim3d/viz/colormaps.py
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 |
|