Explore data
Visualization of volumetric data.
qim3d.viz.threshold
An interactive interface to explore thresholding on a
3D volume slice-by-slice. Users can either manually set the threshold value
using a slider or select an automatic thresholding method from skimage.
The visualization includes the original image slice, a binary mask showing regions above the threshold and an overlay combining the binary mask and the original image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
3D volume to threshold. |
required |
colormap
|
str
|
Colormap for the original image. Defaults to 'viridis'. |
'magma'
|
min_value
|
float
|
Minimum value for the colormap. Defaults to None. |
None
|
max_value
|
float
|
Maximum value for the colormap. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
slicer_obj |
VBox
|
The interactive widget for thresholding a 3D volume. |
Interactivity
- Manual Thresholding: Select 'Manual' from the dropdown menu to manually adjust the threshold using the slider.
-
Automatic Thresholding: Choose a method from the dropdown menu to apply an automatic thresholding algorithm. Available methods include:
- Otsu
- Isodata
- Li
- Mean
- Minimum
- Triangle
- Yen
The threshold slider will display the computed value and will be disabled in this mode.
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
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 1612 1613 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 | |
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',
)
Returns an interactive widget for visualizing the intensity profiles of lines on slices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume
|
ndarray
|
The 3D volume of interest. |
required |
slice_axis
|
int
|
Specifies the initial axis along which to slice. |
0
|
slice_index
|
int or str
|
Specifies the initial slice index along slice_axis. |
'middle'
|
vertical_position
|
int or str
|
Specifies the initial vertical position of the line's pivot point. |
'middle'
|
horizontal_position
|
int or str
|
Specifies the initial horizontal position of the line's pivot point. |
'middle'
|
angle
|
int or float
|
Specifies the initial angle (°) of the line around the pivot point. A float will be converted to an int. A value outside the range will be wrapped modulo. |
0
|
fraction_range
|
tuple or list
|
Specifies the fraction of the line segment to use from border to border. Both the start and the end should be in the range [0.0, 1.0]. |
(0.0, 1.0)
|
y_limits
|
str or tuple or list
|
Specifies the behaviour of the limits on the y-axis of the intensity value plot. Option 'full' fixes to the volume's data range. Option 'auto' automatically adapts to the intensities on the current line. A manual range can be specified by passing a tuple or list of length 2. Defaults to 'auto'. |
'auto'
|
Returns:
| Name | Type | Description |
|---|---|---|
widget |
VBox
|
The interactive widget. |
Source code in qim3d/viz/_data_exploration.py
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 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 | |
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,
)
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 |
coarseness
|
int or list[int]
|
A positive integer representing the coarseness of the subsampling. A value of 1 (default) uses the original volume, a value of 2 uses every second element along each axis and so on. Used to reduce the needed computation. |
1
|
ignore_zero
|
bool
|
Specifies if zero-values in the volume should be ignored. |
True
|
bins
|
Union[int, str]
|
Number of histogram bins or a binning strategy (e.g., "auto"). Default is "auto". |
'auto'
|
slice_axis
|
int
|
Axis along which to take a slice. Default is 0. |
0
|
slice_index
|
Union[int, str]
|
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
|
vertical_line
|
Union[int, Iterable]
|
Intensity value for a vertical line(s) to be drawn on the histogram. Default is None. |
None
|
vertical_line_colormap
|
Union[str, Iterable]
|
Colors for vertical lines. If string, it should be a valid colormap. If iterable, it should be list of valid colors. Default is 'qim'. |
'qim'
|
kde
|
bool
|
Whether to overlay a kernel density estimate. |
False
|
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
|
Size of the figure (width, height). Default is (8, 4.5). |
(8, 4.5)
|
bin_style
|
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
|
ax
|
Axes
|
Axes object where the histogram will be plotted. Default is None. |
None
|
**sns_kwargs
|
str | float | bool
|
Additional keyword arguments for |
{}
|
Returns:
| Type | Description |
|---|---|
Figure | Axes | None
|
Optional[matplotlib.figure.Figure or matplotlib.axes.Axes]:
If |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
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 coarsness 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
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 1012 1013 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 | |
qim3d.viz.overlay
overlay(
volume1,
volume2,
volume1_values=(None, None),
volume2_values=(None, None),
colormaps='gray',
display_size=512,
)
Returns an interactive widget for comparing two volumes along slices in a fading overlay image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume1
|
ndarray
|
The first volume. |
required |
volume2
|
ndarray
|
The second volume. |
required |
volume1_values
|
tuple[float, float]
|
Set the color limits of volume1. |
(None, None)
|
volume2_values
|
tuple[float, float]
|
Set the color limits of volume2. |
(None, None)
|
colormaps
|
ColormapLike or tuple[ColormapLike, ColormapLike]
|
Specifies the colormaps used for each volume. A single value will be applied to both volumes. |
'gray'
|
display_size
|
int
|
Size in pixels of the image. If image is non-square, then the largest dimension will have display_size pixels. |
512
|
Returns:
| Name | Type | Description |
|---|---|---|
widget |
VBox
|
The interactive widget. |
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,
)
Returns an interactive widget for comparing two volumes along slices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
volume1
|
ndarray
|
The first volume. |
required |
volume2
|
ndarray
|
The second volume. |
required |
slice_axis
|
int
|
Specifies the initial axis along which to slice. |
0
|
slice_index
|
int
|
Specifies the initial index along slice_axis. |
None
|
volumetric_visualization
|
bool
|
Defines if k3d plots should also be shown. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
widget |
VBox
|
The interactive widget. |
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
2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 | |
qim3d.viz.chunks
Launch an interactive chunk explorer for a 3D or 5D OME-Zarr/Zarr dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zarr_path
|
str
|
Path to the OME-Zarr/Zarr dataset. |
required |
**kwargs
|
Any
|
Additional keyword arguments that are selectively forwarded only to the visualization method that supports them. Any key not accepted by the chosen method is ignored. The visualization methods available in this tool are:
Users select the desired method via the dropdown menu in the widget. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset's dimensionality is not 3 or 5. |
Returns:
| Name | Type | Description |
|---|---|---|
chunk_explorer |
VBox
|
A widget containing dropdowns for selecting the OME-Zarr scale, chunk coordinates along each axis, and visualization method. |
Example
Source code in qim3d/viz/_data_exploration.py
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 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 | |
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
|
colormap
|
str
|
Specifies the color map for the image. Defaults to "viridis". |
'magma'
|
min_value
|
float or None
|
Together with max_value define the data range the colormap covers. By default colormap covers the full range. Defaults to None. |
None
|
max_value
|
float or None
|
Together with min_value 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
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 | |