Explore data
Visualization of volumetric data.
qim3d.viz.threshold
Launches an interactive widget to perform 3D image segmentation via thresholding (binarization).
This tool allows you to explore the volume slice-by-slice to determine the optimal cut-off value for creating a binary mask. It is essential for separating objects of interest from the background based on intensity. The interface provides real-time feedback by displaying the intensity histogram and overlaying the resulting mask on the original data.
Key Features:
- Visualization: Simultaneously views the original slice, intensity histogram, binary mask, and a color overlay.
- Manual Control: Adjust the threshold value precisely using a slider.
- Automatic Algorithms: Applies standard
skimageauto-thresholding methods including Otsu, Isodata, Li, Mean, Minimum, Triangle, and Yen. - Slice Navigation: Scroll through the 3D stack to ensure the chosen threshold works across different depths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The 3D input data (image stack) to threshold. |
required |
colormap
|
str
|
The Matplotlib colormap for the original image display. |
'magma'
|
min_value
|
float
|
Custom minimum value for display contrast (vmin). If |
None
|
max_value
|
float
|
Custom maximum value for display contrast (vmax). If |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
slicer_obj |
VBox
|
The interactive Jupyter widget containing the visualization plots and control sliders. |
Example
import qim3d
# Load a sample volume
vol = qim3d.examples.bone_128x128x128
# Visualize interactive thresholding
qim3d.viz.threshold(vol)
Source code in qim3d/viz/_data_exploration.py
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 | |
qim3d.viz.line_profile
line_profile(
volume,
slice_axis=0,
slice_index='middle',
vertical_position='middle',
horizontal_position='middle',
angle=0,
fraction_range=(0.0, 1.0),
y_limits='auto',
)
Creates an interactive tool to visualize intensity profiles along a line segment within a 3D volume.
This function allows you to draw a line on a specific slice of your data and plot the pixel or voxel intensity values along that path. It is ideal for quantitative analysis, such as checking material homogeneity, measuring the sharpness of edges (step functions), or inspecting noise levels across a region of interest (ROI). The tool supports arbitrary angles, dynamic pivot points, and adjustable plot limits.
Key Features:
- Profile Plotting: Real-time graph of intensity values (gray levels) versus distance.
- Flexible Positioning: Define the line by a pivot point (vertical/horizontal) and an angle of rotation.
- Navigation: Select specific slices using indices or keywords like 'middle'.
- Zooming: Focus on specific segments of the line using the
fraction_rangeparameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The 3D input volume (image stack). |
required |
slice_axis
|
int
|
The axis along which to extract the 2D slice (0, 1, or 2). Defaults to 0. |
0
|
slice_index
|
int or str
|
The index of the slice to display. Can be an integer or a position string ('start', 'middle', 'end'). Defaults to 'middle'. |
'middle'
|
vertical_position
|
int or str
|
The vertical coordinate of the line's pivot point. Can be an integer or 'start', 'middle', 'end'. Defaults to 'middle'. |
'middle'
|
horizontal_position
|
int or str
|
The horizontal coordinate of the line's pivot point. Can be an integer or 'start', 'middle', 'end'. Defaults to 'middle'. |
'middle'
|
angle
|
int or float
|
The angle of the line in degrees relative to the horizontal axis. Floats are rounded to the nearest integer. Defaults to 0. |
0
|
fraction_range
|
tuple[float, float]
|
The start and end points of the line segment as a fraction of the image width/height (0.0 to 1.0). Defaults to (0.00, 1.00). |
(0.0, 1.0)
|
y_limits
|
str or tuple[float, float]
|
Controls the Y-axis range of the intensity plot. Defaults to 'auto'.
|
'auto'
|
Returns:
| Name | Type | Description |
|---|---|---|
widget |
interactive
|
The interactive widget object containing the slice viewer and the intensity plot. |
Source code in qim3d/viz/_data_exploration.py
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 | |
qim3d.viz.histogram
histogram(
volume,
coarseness=1,
ignore_zero=True,
bins='auto',
slice_index=None,
slice_axis=0,
vertical_line=None,
vertical_line_colormap='qim',
kde=False,
log_scale=False,
despine=True,
show_title=True,
color='qim3d',
edgecolor=None,
figsize=(8, 4.5),
bin_style='step',
return_fig=False,
show=True,
ax=None,
**sns_kwargs,
)
Computes and displays the intensity distribution (histogram) of a 3D volume or a specific 2D slice.
This function visualizes the frequency of voxel intensities (gray values), which is essential for analyzing data contrast, identifying material phases, and determining threshold values for segmentation. It utilizes seaborn.histplot and includes optimizations for 3D data, such as subsampling (coarseness) to handle large datasets efficiently. You can also overlay Kernel Density Estimates (KDE) or specific threshold markers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The 3D input volume. |
required |
coarseness
|
int or list[int]
|
Subsampling factor to speed up computation. A value of |
1
|
ignore_zero
|
bool
|
If |
True
|
bins
|
int or str
|
The number of bins or a binning strategy (e.g., 'auto', 'sturges'). |
'auto'
|
slice_index
|
int, str, or None
|
The specific slice to analyze. If |
None
|
slice_axis
|
int
|
The axis along which to extract the slice (0, 1, or 2). Used only if |
0
|
vertical_line
|
int or Iterable
|
One or more intensity values to mark with vertical dashed lines (e.g., to visualize a threshold cut-off). |
None
|
vertical_line_colormap
|
str or Iterable
|
The colormap or list of colors for the vertical lines. |
'qim'
|
kde
|
bool
|
If |
False
|
log_scale
|
bool
|
If |
False
|
despine
|
bool
|
If |
True
|
show_title
|
bool
|
If |
True
|
color
|
str
|
The main color of the histogram bars. |
'qim3d'
|
edgecolor
|
str
|
The color of the bar edges. |
None
|
figsize
|
tuple[float, float]
|
The width and height of the figure in inches. |
(8, 4.5)
|
bin_style
|
str
|
The visual style of the histogram ('bars', 'step', or 'poly'). |
'step'
|
return_fig
|
bool
|
If |
False
|
show
|
bool
|
If |
True
|
ax
|
Axes
|
An existing Axes object to plot onto. If provided, the function returns this Axes object (unless |
None
|
**sns_kwargs
|
str | float | bool
|
Additional keyword arguments passed to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
object |
matplotlib.figure.Figure, matplotlib.axes.Axes, or None
|
The plot object, depending on parameters:
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Histogram from a single slice
import qim3d
vol = qim3d.examples.bone_128x128x128
qim3d.viz.histogram(vol, slice_index=100, slice_axis=1, bin_style='bars', edgecolor='white')
Using coarseness for faster computation
import qim3d
vol = qim3d.examples.bone_128x128x128
qim3d.viz.histogram(vol, coarseness=2, kde=True, log_scale=True)
Source code in qim3d/viz/_data_exploration.py
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 | |
qim3d.viz.overlay
overlay(
volume1,
volume2,
volume1_values=(None, None),
volume2_values=(None, None),
colormaps='gray',
display_size=512,
)
Creates an interactive widget to compare two 3D volumes by overlaying them with adjustable transparency.
This tool is essential for tasks like image registration (checking alignment between two scans), segmentation validation (comparing a binary mask against the original raw data), or general change detection. It provides a slider to smoothly fade (blend) between the two volumes, allowing for precise visual inspection of differences and spatial correspondence slice-by-slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume1
|
ndarray
|
The first 3D volume (e.g., the reference image). |
required |
volume2
|
ndarray
|
The second 3D volume (e.g., the moving image or segmentation mask). Must have the same shape as |
required |
volume1_values
|
tuple[float, float]
|
Intensity limits |
(None, None)
|
volume2_values
|
tuple[float, float]
|
Intensity limits |
(None, None)
|
colormaps
|
str or Colormap or tuple
|
The colormap(s) to apply. Can be a single value (applied to both) or a tuple |
'gray'
|
display_size
|
int
|
The maximum width/height of the displayed image in pixels. Defaults to 512. |
512
|
Returns:
| Name | Type | Description |
|---|---|---|
widget |
VBox
|
The interactive widget containing the slicer controls and the fading overlay display. |
Example
import qim3d
vol = qim3d.examples.cement_128x128x128
binary = qim3d.filters.gaussian(vol, sigma=2) < 60
labeled_volume, num_labels = qim3d.segmentation.watershed(binary)
segm_cmap = qim3d.viz.colormaps.segmentation(num_labels, style = 'bright')
qim3d.viz.overlay(vol, labeled_volume, colormaps=('grey', segm_cmap), volume2_values=(0, num_labels))
Source code in qim3d/viz/_data_exploration.py
qim3d.viz.compare_volumes
compare_volumes(
volume1,
volume2,
slice_axis=0,
slice_index=None,
volumetric_visualization=False,
)
Launches an interactive dashboard to visually compare two 3D volumes side-by-side.
This tool is essential for registration validation (checking alignment), change detection, or analyzing reconstruction errors (residuals). It displays synchronized slices of both volumes alongside a computed difference map. You can switch between 'difference', 'absolute difference', and 'quadratic difference' modes to highlight discrepancies effectively.
If enabled, the tool also provides 3D volumetric rendering (via k3d), allowing you to inspect the spatial distribution of the errors or changes in 3D space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume1
|
ndarray
|
The first 3D volume (e.g., Ground Truth or Reference). |
required |
volume2
|
ndarray
|
The second 3D volume (e.g., Prediction or Moving Image). Must have the same shape as |
required |
slice_axis
|
int
|
The initial axis along which to slice (0, 1, or 2). Defaults to 0. |
0
|
slice_index
|
int
|
The initial slice index to display. If |
None
|
volumetric_visualization
|
bool
|
If |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
widget |
VBox
|
The interactive widget containing the comparison controls, slice plots, and optional 3D views. |
Example
import qim3d
vol1 = qim3d.generate.volume(noise_scale=0.020, dtype='float32')
vol2 = qim3d.generate.volume(noise_scale=0.021, dtype='float32')
qim3d.viz.compare_volumes(vol1, vol2, volumetric_visualization=True)
Source code in qim3d/viz/_data_exploration.py
2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 | |
qim3d.viz.chunks
Launches an interactive explorer for large-scale OME-Zarr and Zarr datasets.
This tool enables you to inspect massive 3D or 5D datasets (e.g., bio-imaging pyramids, large block-wise volumes) one chunk at a time without loading the entire file into RAM. It relies on lazy loading, making it ideal for checking data integrity, visualizing specific regions of interest (ROI) in big data, or navigating multi-resolution hierarchies.
Key Features:
- Lazy Exploration: Loads only the specific chunk selected via dropdown menus.
- Multiscale Support: Automatically detects and navigates resolution levels (pyramids) in OME-Zarr groups.
- 5D Navigation: Supports dimensions for Time (T) and Channel (C) in addition to spatial axes (Z, Y, X).
- Versatile Visualization: Switch instantly between a
slicer, aslices_grid, or a 3Dvolumetricrendering for the selected chunk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zarr_path
|
str
|
The filesystem path to the OME-Zarr or Zarr dataset. |
required |
**kwargs
|
Any
|
Additional keyword arguments passed selectively to the underlying visualization function.
For example, you can pass |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
chunk_explorer |
VBox
|
The interactive interface containing controls for scale selection, chunk coordinates, and the visualization display. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset dimensionality is not 3D or 5D. |
Example
Source code in qim3d/viz/_data_exploration.py
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 851 852 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 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 | |
qim3d.viz.fade_mask
Launches an interactive tool to tune parameters for edge fading (vignetting) on a 3D volume.
This function helps you find the optimal settings for suppressing boundary artifacts or focusing on the center of the volume. It visualizes the process by displaying three panels: the original slice, the generated weight mask (attenuation map), and the final result. You can adjust the decay rate, ratio (radius), and geometry (spherical or cylindrical) in real-time before applying them permanently using qim3d.operations.fade_mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The 3D input volume. |
required |
axis
|
int
|
The axis alignment for the mask geometry (relevant for cylindrical fading). Defaults to 0. |
0
|
colormap
|
str
|
The Matplotlib colormap used for displaying the volume and mask. Defaults to 'magma'. |
'magma'
|
min_value
|
float
|
Custom minimum intensity for display contrast. If |
None
|
max_value
|
float
|
Custom maximum intensity for display contrast. If |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
slicer_obj |
interactive
|
The interactive widget containing the parameter sliders and the side-by-side visualization. |
Source code in qim3d/viz/_data_exploration.py
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 | |