Data visualization
The qim3d
library aims to provide easy ways to explore and get insights from volumetric data.
qim3d.viz
qim3d.viz.histogram
histogram(volume, bins='auto', slice_idx=None, axis=0, kde=True, log_scale=False, despine=True, show_title=True, color='qim3d', edgecolor=None, figsize=(8, 4.5), element='step', return_fig=False, show=True, **sns_kwargs)
Plots a histogram of voxel intensities from a 3D volume, with options to show a specific slice or the entire volume.
Utilizes seaborn.histplot for visualization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
volume |
ndarray
|
A 3D NumPy array representing the volume to be visualized. |
required |
bins |
int or str
|
Number of histogram bins or a binning strategy (e.g., "auto"). Default is "auto". |
'auto'
|
axis |
int
|
Axis along which to take a slice. Default is 0. |
0
|
slice_idx |
int or str or None
|
Specifies the slice to visualize. If an integer, it represents the slice index along the selected axis. If "middle", the function uses the middle slice. If None, the entire volume is visualized. Default is None. |
None
|
kde |
bool
|
Whether to overlay a kernel density estimate. Default is True. |
True
|
log_scale |
bool
|
Whether to use a logarithmic scale on the y-axis. Default is False. |
False
|
despine |
bool
|
If True, removes the top and right spines from the plot for cleaner appearance. Default is True. |
True
|
show_title |
bool
|
If True, displays a title with slice information. Default is True. |
True
|
color |
str
|
Color for the histogram bars. If "qim3d", defaults to the qim3d color. Default is "qim3d". |
'qim3d'
|
edgecolor |
str
|
Color for the edges of the histogram bars. Default is None. |
None
|
figsize |
tuple of floats
|
Size of the figure (width, height). Default is (8, 4.5). |
(8, 4.5)
|
element |
str
|
Type of histogram to draw ('bars', 'step', or 'poly'). Default is "step". |
'step'
|
return_fig |
bool
|
If True, returns the figure object instead of showing it directly. Default is False. |
False
|
show |
bool
|
If True, displays the plot. If False, suppresses display. Default is True. |
True
|
**sns_kwargs |
Any
|
Additional keyword arguments for |
{}
|
Returns:
Name | Type | Description |
---|---|---|
fig |
Optional[Figure]
|
If |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValueError
|
If |
Example
Source code in qim3d/viz/_data_exploration.py
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 |
|
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=False, **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
|
color_bar |
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/_data_exploration.py
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 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 |
|
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', **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_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'
|
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
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 |
|
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)
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
|
Returns:
Name | Type | Description |
---|---|---|
slicer_orthogonal_obj |
HBox
|
The interactive widget for visualizing orthogonal slices of a 3D volume. |
Example
Source code in qim3d/viz/_data_exploration.py
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.chunks
Function to visualize chunks of a Zarr dataset using the specified visualization method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
zarr_path |
str or PathLike
|
Path to the Zarr dataset. |
required |
**kwargs |
Any
|
Additional keyword arguments to pass to the visualization method. |
{}
|
Example
Source code in qim3d/viz/_data_exploration.py
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 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 |
|
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.volumetric
volumetric(img, aspectmode='data', show=True, save=False, grid_visible=False, color_map='magma', constant_opacity=False, 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
|
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
|
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 512^3. |
512 ** 3
|
data_type |
str
|
Default to 'scaled_float16'. |
'scaled_float16'
|
**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
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 |
|
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 |
Any
|
Additional keyword arguments to be passed to the |
{}
|
Returns:
Name | Type | Description |
---|---|---|
plot |
plot
|
If |
Example
Source code in qim3d/viz/_k3d.py
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 |
|
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
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 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
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, display_figure=True, color_map='viridis', value_min=None, value_max=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 or 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 |
ndarray or None
|
Overlay image. Defaults to None. |
None
|
crop |
bool
|
Whether to crop the image to the cc. Defaults to False. |
False
|
display_figure |
bool
|
Whether to show the figure. Defaults to True. |
True
|
color_map |
str
|
Specifies the color map for the image. Defaults to "viridis". |
'viridis'
|
value_min |
float or None
|
Together with vmax define the data range the colormap covers. By default colormap covers the full range. Defaults to None. |
None
|
value_max |
float or None
|
Together with vmin define the data range the colormap covers. By default colormap covers the full range. Defaults to None |
None
|
**kwargs |
Any
|
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.segmentation.get_3d_cc(vol_bin)
qim3d.viz.plot_cc(cc, crop=True, display_figure=True, overlay=None, num_slices=5, component_indexs=[4,6,7])
qim3d.viz.plot_cc(cc, crop=True, display_figure=True, overlay=vol, num_slices=5, component_indexs=[4,6,7])
Source code in qim3d/viz/_cc.py
qim3d.viz.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 |
---|---|---|---|
volume |
ndarray
|
The volume to apply edge fading to. |
required |
axis |
int
|
The axis along which to apply the fading. Defaults to 0. |
0
|
color_map |
str
|
Specifies the color map for the image. Defaults to "viridis". |
'magma'
|
value_min |
float or None
|
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 or None
|
Together with value_min define the data range the colormap covers. By default colormap covers the full range. Defaults to None |
None
|
Returns:
Name | Type | Description |
---|---|---|
slicer_obj |
HBox
|
The interactive widget for visualizing fade mask on slices of a 3D volume. |
Source code in qim3d/viz/_data_exploration.py
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 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 |
|
qim3d.viz.colormaps
qim3d.viz.colormaps.qim
module-attribute
qim3d.viz.colormaps.segmentation
segmentation(num_labels, 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 |
---|---|---|---|
num_labels |
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 |
---|---|---|
color_map |
LinearSegmentedColormap
|
Colormap for matplotlib |
Example
import qim3d
cmap_bright = qim3d.viz.colormaps.segmentation(num_labels=100, style = 'bright', first_color_background=True, background_color="black", min_dist=0.7)
cmap_soft = qim3d.viz.colormaps.segmentation(num_labels=100, style = 'soft', first_color_background=True, background_color="black", min_dist=0.2)
cmap_earth = qim3d.viz.colormaps.segmentation(num_labels=100, style = 'earth', first_color_background=True, background_color="black", min_dist=0.8)
cmap_ocean = qim3d.viz.colormaps.segmentation(num_labels=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.filters.gaussian(vol, sigma = 2) < 60
labeled_volume, num_labels = qim3d.segmentation.watershed(binary)
color_map = qim3d.viz.colormaps.segmentation(num_labels, style = 'bright')
qim3d.viz.slicer(labeled_volume, slice_axis = 1, color_map=color_map)
Tip
It can be easily used when calling visualization functions as
which automatically detects number of unique classes and creates the colormap object with defualt arguments.Tip
The min_dist
parameter can be used to control the distance between neighboring colors.
Source code in qim3d/viz/colormaps/_segmentation.py
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 |
|