Image Processing¶
The voids.image sub-package provides utilities for segmented image processing,
connectivity analysis, and pore network extraction used in vug sensitivity studies.
Maximal-Ball Extraction¶
voids.image.maximal_ball
¶
MaximalBallSettings
dataclass
¶
User-facing controls for the native maximal-ball extraction stages.
These settings mirror the main Imperial pnextract controls closely enough
for staged verification work, while keeping Python names explicit and
readable. The current implementation covers the maximal-ball candidate stage
and the initial overlap suppression stage. Hierarchy construction and voxel
growth are planned follow-on steps.
Source code in src/voids/image/maximal_ball.py
ResolvedMaximalBallSettings
dataclass
¶
Concrete maximal-ball settings after Imperial-style default resolution.
Source code in src/voids/image/maximal_ball.py
MaximalBallCandidates
dataclass
¶
Candidate and retained maximal-ball data on voxel centers.
Source code in src/voids/image/maximal_ball.py
MaximalBallHierarchy
dataclass
¶
Parent-child hierarchy over retained maximal-ball candidates.
The hierarchy is stored on the retained-ball order of
:class:MaximalBallCandidates, which is already sorted by descending
radius. Each ball points either to itself, if it is a root/master ball, or
to the index of its parent ball in the same retained ordering.
Source code in src/voids/image/maximal_ball.py
MaximalBallVoxelRegions
dataclass
¶
Voxel ownership assignment grown from maximal-ball hierarchy roots.
Source code in src/voids/image/maximal_ball.py
assigned_void_mask
property
¶
Return a mask of voxels assigned to some pore/root region.
MaximalBallRegionAdjacency
dataclass
¶
Region-wise geometric summaries derived from voxel ownership labels.
Notes
The fields here are deliberately close to the intermediate quantities that the Imperial extractor builds before CNM export:
- per-region occupied voxel counts
- per-region exposed face counts
- region-to-region interface face counts
- interface centroids in voxel-index coordinates
- boundary-face contact counts on each sample side
This is still an intermediate voxel-geometry product, not yet a final
voids.Network.
Source code in src/voids/image/maximal_ball.py
MaximalBallExtractionResult
dataclass
¶
Staged native maximal-ball extraction outputs before CNM assembly.
Source code in src/voids/image/maximal_ball.py
MaximalBallNetworkDictResult
dataclass
¶
PoreSpy-style network mapping assembled from native maximal-ball regions.
Source code in src/voids/image/maximal_ball.py
MaximalBallExtractionDiagnostics
dataclass
¶
Compact diagnostics for step-by-step maximal-ball extraction comparison.
Source code in src/voids/image/maximal_ball.py
compute_void_distance_map
¶
Compute the void-space Euclidean distance map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
void_phase_mask
|
ndarray
|
Boolean array where |
required |
backend
|
str
|
Distance-transform backend. |
'auto'
|
edt_parallel_threads
|
int | None
|
Number of worker threads to use when the optional |
None
|
Source code in src/voids/image/maximal_ball.py
compute_maximal_ball_radius_field
¶
compute_maximal_ball_radius_field(
void_phase_mask,
*,
backend="auto",
edt_parallel_threads=None,
mode="half_voxel",
)
Compute the radius field used by the maximal-ball extractor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
void_phase_mask
|
ndarray
|
Boolean array where |
required |
backend
|
str
|
Distance-transform backend passed through to
:func: |
'auto'
|
edt_parallel_threads
|
int | None
|
Number of worker threads to use when the optional |
None
|
mode
|
str
|
Radius-field convention. |
'half_voxel'
|
Source code in src/voids/image/maximal_ball.py
smooth_radius_field_local_relaxation
¶
Smooth a radius field with a compact local relaxation stencil.
Source code in src/voids/image/maximal_ball.py
resolve_maximal_ball_settings
¶
Resolve Imperial-style default settings from a distance map.
The Imperial code derives several defaults from the average void-space radius. We mirror that default logic here so staged comparisons use the same parameter semantics even before the full extractor is implemented.
Source code in src/voids/image/maximal_ball.py
clip_distance_map_to_domain_boundaries
¶
Apply the Imperial-style boundary clipping heuristic to a distance map.
Source code in src/voids/image/maximal_ball.py
find_maximal_ball_candidates
¶
find_maximal_ball_candidates(
distance_map,
*,
minimal_radius_voxels,
footprint=None,
selection_mode="local_maxima",
)
Find maximal-ball candidates from a radius field.
Source code in src/voids/image/maximal_ball.py
suppress_overlapping_maximal_balls
¶
Retain descending-radius maximal-ball candidates after overlap suppression.
Source code in src/voids/image/maximal_ball.py
refine_retained_ball_coordinates
¶
Apply Imperial-style uphill refinements to retained maximal balls.
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray, ndarray]
|
Refined integer voxel indices, refined floating-point center coordinates, and refined radii. |
Source code in src/voids/image/maximal_ball.py
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 | |
refine_ball_from_seed_index
¶
Refine one voxel-centered ball seed with the Imperial uphill sequence.
Source code in src/voids/image/maximal_ball.py
build_maximal_ball_hierarchy
¶
Build an Imperial-inspired hierarchy over retained maximal balls.
Notes
This stage mirrors the main geometric ideas in the Imperial parent competition logic:
- only retained maximal balls participate
- nearby balls interact only when their midpoint is supported by the void distance map
- smaller balls preferentially attach to larger nearby balls
- nearby master balls can also merge into a higher-level hierarchy
This is still a staged native implementation. The downstream voxel-growth and throat-construction stages are not yet included here.
Source code in src/voids/image/maximal_ball.py
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 | |
initialize_root_region_labels
¶
Seed voxel-region labels from hierarchy root balls.
Notes
This stage mirrors the first pore-element seeding in the Imperial code: each root/master maximal ball defines an initial pore region, and each retained non-root ball maps to the region of its hierarchy root.
Source code in src/voids/image/maximal_ball.py
seed_root_region_ball_interiors
¶
Assign small interior neighborhoods around retained balls to their root regions.
Source code in src/voids/image/maximal_ball.py
grow_root_regions_by_radius
¶
grow_root_regions_by_radius(
void_phase_mask,
distance_map,
voxel_regions,
*,
minimum_supporting_neighbors,
radius_support_mode=None,
require_strictly_larger_radius=None,
iterations=1,
void_indices=None,
)
Grow root regions across unassigned void voxels using local radius rules.
Source code in src/voids/image/maximal_ball.py
2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 | |
reassign_region_boundary_voxels_by_majority
¶
reassign_region_boundary_voxels_by_majority(
void_phase_mask,
distance_map,
voxel_regions,
*,
radius_support_mode="any",
iterations=1,
void_indices=None,
)
Reassign weakly supported labeled voxels using a neighbor majority rule.
This mirrors the Imperial medianElem stage conceptually: if a labeled
voxel is more exposed to different neighboring pore labels than to its own
label, it may be reassigned to the strongest competing neighbor label.
Source code in src/voids/image/maximal_ball.py
2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 | |
retreat_mixed_region_boundary_voxels
¶
Retreat mixed boundary voxels back to the unassigned state.
This mirrors the Imperial retreatPoresMedian stage: labeled voxels that
touch both same-label and different-label neighbors are temporarily removed
so later growth passes can rebuild cleaner interfaces.
Source code in src/voids/image/maximal_ball.py
stamp_retained_ball_centers_to_root_labels
¶
Restore retained-ball centers to their hierarchy-root region labels.
Source code in src/voids/image/maximal_ball.py
grow_root_regions_by_neighbor_priority
¶
grow_root_regions_by_neighbor_priority(
void_phase_mask,
voxel_regions,
*,
iterations=1,
void_indices=None,
)
Grow unassigned voxels by direct neighbor propagation in sweep order.
This mirrors the late Imperial growPores / growPores_X2 stages more
closely than the earlier radius-aware majority passes.
Source code in src/voids/image/maximal_ball.py
assign_voxel_regions_from_hierarchy
¶
Assign voxel ownership using an Imperial-inspired staged growth schedule.
Source code in src/voids/image/maximal_ball.py
2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 | |
measure_region_adjacency
¶
Measure pore-region volumes, interfaces, and boundary contacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
void_phase_mask
|
ndarray
|
Boolean void-domain mask used for extraction. |
required |
voxel_regions
|
MaximalBallVoxelRegions
|
Labeled pore/root ownership image. |
required |
Returns:
| Type | Description |
|---|---|
MaximalBallRegionAdjacency
|
Region-wise voxel volumes and region-pair interface measurements. |
Notes
This stage converts the voxel partition into the basic discrete geometry we
need for a native pnextract-like network assembly:
- region voxel counts become pore-region volumes
- region-pair contact faces become throat candidates
- boundary-face contacts expose inlet/outlet touching regions
The centroid coordinates are reported in voxel-index units, using face
midpoint locations such as i + 0.5 along the axis normal to the
interface.
Source code in src/voids/image/maximal_ball.py
2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 | |
extract_maximal_ball_regions
¶
extract_maximal_ball_regions(
void_phase_mask,
*,
distance_map_backend="auto",
edt_parallel_threads=None,
settings=None,
apply_boundary_clipping=True,
)
Run the staged native maximal-ball pipeline up to region adjacency.
This is the current highest-level native extraction entry point that stays
independent of PoreSpy network generation. It stops at voxel-region and
interface geometry because the final pore/throat-to-Network assembly is
still under active implementation.
Source code in src/voids/image/maximal_ball.py
summarize_maximal_ball_extraction_diagnostics
¶
Summarize intermediate maximal-ball extraction behavior for comparison work.
Source code in src/voids/image/maximal_ball.py
3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 | |
build_network_dict_from_maximal_ball_regions
¶
build_network_dict_from_maximal_ball_regions(
extraction_result,
*,
voxel_size,
axis_names=("x", "y", "z"),
flow_boundary_mode="direct",
boundary_axis=None,
boundary_length_epsilon=1e-300,
boundary_radius_scale=1.1,
throat_area_mode="face_count",
throat_shape_factor_radius_mode="inscribed",
throat_anchor_mode="second_side",
)
Assemble a PoreSpy-style network mapping from maximal-ball regions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extraction_result
|
MaximalBallExtractionResult
|
Native maximal-ball extraction outputs through the region-adjacency stage. |
required |
voxel_size
|
float
|
Physical edge length of one voxel. |
required |
axis_names
|
tuple[str, ...]
|
Axis labels associated with the image dimensions. Only the first
|
('x', 'y', 'z')
|
Notes
This builder intentionally uses explicit, readable geometric rules rather than hidden heuristics:
- pore coordinates are the root maximal-ball centers
- pore volumes are the labeled region voxel counts
- throat areas are the counted interface faces
- throat centroids are the mean interface-face midpoints
- conduit lengths are derived from pore-center to interface-centroid distances with a minimum half-voxel regularization
The current implementation now follows the Imperial export logic more closely in three places:
- throat radii are taken from interface-supporting maximal balls
- throat and pore shape factors follow the Imperial export repair and throat-area-weighted pore averaging logic
- region volumes are redistributed between pores and throats using the same area-partition rule used by the Imperial CNM writer
This is still not full pnextract parity, because the upstream voxel
ownership and throat-surface ball construction remain a native
approximation.
Source code in src/voids/image/maximal_ball.py
3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 | |
extract_maximal_ball_network_dict
¶
extract_maximal_ball_network_dict(
void_phase_mask,
*,
voxel_size,
distance_map_backend="auto",
edt_parallel_threads=None,
settings=None,
apply_boundary_clipping=True,
axis_names=("x", "y", "z"),
flow_boundary_mode="direct",
boundary_axis=None,
boundary_length_epsilon=1e-300,
boundary_radius_scale=1.1,
throat_area_mode="face_count",
throat_shape_factor_radius_mode="inscribed",
throat_anchor_mode="second_side",
)
Run the staged native maximal-ball path and assemble a network mapping.
Source code in src/voids/image/maximal_ball.py
extract_maximal_ball_candidates
¶
extract_maximal_ball_candidates(
void_phase_mask,
*,
distance_map_backend="auto",
edt_parallel_threads=None,
settings=None,
apply_boundary_clipping=True,
)
Compute and suppress maximal-ball candidates for a void-phase image.
Source code in src/voids/image/maximal_ball.py
PREGO Extraction¶
voids.image.prego
¶
PregoSettings
dataclass
¶
Controls for seed-based Pore Region Growing segmentation.
The defaults use r_max=4 and Gaussian smoothing sigma=0.4. PREGO is
currently implemented for a single active pore phase, with nonzero input
voxels treated as void.
Source code in src/voids/image/prego.py
PregoSegmentationResult
dataclass
¶
Intermediate PREGO segmentation data before network construction.
Source code in src/voids/image/prego.py
PregoNetworkDictResult
dataclass
¶
PoreSpy-style network mapping assembled from PREGO regions.
Source code in src/voids/image/prego.py
snow_seed_points
¶
snow_seed_points(
void_phase_mask,
*,
distance_map=None,
r_max=4,
sigma=0.4,
peak_footprint="sphere",
peaks=None,
distance_map_backend="auto",
edt_parallel_threads=None,
porespy_module=ps,
)
Find PREGO seed points using the peak-filtering stages of SNOW.
Returns:
| Type | Description |
|---|---|
tuple
|
|
Source code in src/voids/image/prego.py
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 | |
prego_partitioning
¶
Partition a binary pore image with PREGO-style region growing.
Notes
The default growth_mode="level_queue" follows the paper's delayed seed
activation and level-by-level FIFO queue before the final expansion of
unassigned foreground voxels. growth_mode="fast" remains available as
a faster approximation that stamps non-overlapping seed spheres in
descending radius order before the same final FIFO fill.
Source code in src/voids/image/prego.py
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 | |
extract_prego_network_dict
¶
extract_prego_network_dict(
im,
*,
settings=None,
distance_map=None,
peaks=None,
porespy_module=ps,
regions_to_network_kwargs=None,
)
Run PREGO segmentation and convert regions to a PoreSpy network dict.
Source code in src/voids/image/prego.py
Porosity Maps¶
For conceptual background, block_shape interpretation, and synthetic
verification context, see Porosity Maps.
voids.image.porosity
¶
PorosityMap
dataclass
¶
Cell-wise porosity field for continuum or external-solver workflows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
Two- or three-dimensional porosity field with entries in |
required |
cell_size
|
float | Sequence[float]
|
Scalar or per-axis cell side length in physical units. |
1.0
|
origin
|
Sequence[float] | None
|
Physical coordinate of the lower corner of the first cell. |
None
|
units
|
dict[str, str]
|
Unit metadata for reporting and serialization. |
(lambda: {'length': 'm'})()
|
metadata
|
dict[str, Any]
|
Additional JSON-serializable provenance and calibration metadata. |
dict()
|
Source code in src/voids/image/porosity.py
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 | |
void_volume
property
¶
Return the pore volume implied by the cell-average porosity field.
to_metadata
¶
Serialize map metadata without the porosity array.
Source code in src/voids/image/porosity.py
from_metadata
classmethod
¶
Reconstruct a porosity map from values and serialized metadata.
Source code in src/voids/image/porosity.py
PermeabilityMap
dataclass
¶
Cell-wise permeability field paired with a continuum porosity map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
Two- or three-dimensional permeability field. Values are interpreted in
the square of the length unit recorded in |
required |
cell_size
|
float | Sequence[float]
|
Scalar or per-axis cell side length in physical units. |
1.0
|
origin
|
Sequence[float] | None
|
Physical coordinate of the lower corner of the first cell. |
None
|
units
|
dict[str, str]
|
Unit metadata for reporting and serialization. |
(lambda: {'length': 'm', 'permeability': 'm^2'})()
|
metadata
|
dict[str, Any]
|
Additional JSON-serializable provenance and closure metadata. |
dict()
|
Source code in src/voids/image/porosity.py
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 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 | |
finite_mean_permeability
property
¶
Return the arithmetic mean over finite permeability values.
inverse_values
property
¶
Return the inverse permeability field with reciprocal endpoint limits.
to_metadata
¶
Serialize map metadata without the permeability array.
Source code in src/voids/image/porosity.py
from_metadata
classmethod
¶
Reconstruct a permeability map from values and serialized metadata.
Source code in src/voids/image/porosity.py
calibrated_porosity_from_grayscale
¶
calibrated_porosity_from_grayscale(
grayscale,
*,
solid_gray,
pore_gray,
background_porosity=0.0,
clip=True,
)
Map grayscale intensity to porosity with a two-point linear calibration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grayscale
|
ndarray
|
Two- or three-dimensional grayscale image. |
required |
solid_gray
|
float
|
Grayscale value assigned to the background or unresolved-microporosity porosity. |
required |
pore_gray
|
float
|
Grayscale value assigned to porosity equal to one. |
required |
background_porosity
|
float
|
Porosity assigned at |
0.0
|
clip
|
bool
|
Whether to clip extrapolated values to
|
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Voxel-wise porosity field. |
Source code in src/voids/image/porosity.py
kozeny_carman_permeability
¶
kozeny_carman_permeability(
porosity,
*,
characteristic_length,
kozeny_constant=180.0,
solid_permeability=0.0,
free_flow_permeability=np.inf,
max_permeability=None,
)
Estimate permeability from porosity with a Kozeny-Carman closure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
porosity
|
ndarray
|
Two- or three-dimensional porosity field with entries in |
required |
characteristic_length
|
float
|
Characteristic length |
required |
kozeny_constant
|
float
|
Denominator constant. The default |
180.0
|
solid_permeability
|
float
|
Permeability assigned at |
0.0
|
free_flow_permeability
|
float
|
Permeability assigned at |
inf
|
max_permeability
|
float | None
|
Optional finite cap applied after evaluating the closure. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Permeability field computed as
|
Source code in src/voids/image/porosity.py
kozeny_carman_inverse_permeability
¶
kozeny_carman_inverse_permeability(
porosity,
*,
characteristic_length,
kozeny_constant=180.0,
solid_inverse_permeability=np.inf,
free_flow_inverse_permeability=0.0,
max_inverse_permeability=None,
)
Estimate inverse permeability from porosity with a Kozeny-Carman closure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
porosity
|
ndarray
|
Two- or three-dimensional porosity field with entries in |
required |
characteristic_length
|
float
|
Characteristic length |
required |
kozeny_constant
|
float
|
Numerator constant. The default |
180.0
|
solid_inverse_permeability
|
float
|
Inverse permeability assigned at |
inf
|
free_flow_inverse_permeability
|
float
|
Inverse permeability assigned at |
0.0
|
max_inverse_permeability
|
float | None
|
Optional finite cap applied after evaluating the closure. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Inverse permeability field computed as
|
Source code in src/voids/image/porosity.py
permeability_map_from_porosity
¶
permeability_map_from_porosity(
porosity_map,
*,
characteristic_length,
kozeny_constant=180.0,
solid_permeability=0.0,
free_flow_permeability=np.inf,
max_permeability=None,
metadata=None,
)
Generate a Kozeny-Carman permeability map from a porosity map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
porosity_map
|
PorosityMap
|
Porosity map supplying the cell-wise |
required |
characteristic_length
|
float
|
|
required |
kozeny_constant
|
float
|
|
required |
solid_permeability
|
float
|
|
required |
free_flow_permeability
|
float
|
Closure parameters passed to :func: |
inf
|
max_permeability
|
float
|
Closure parameters passed to :func: |
inf
|
metadata
|
dict[str, Any] | None
|
Optional extra metadata merged into the generated map metadata. |
None
|
Returns:
| Type | Description |
|---|---|
PermeabilityMap
|
Permeability field paired with the porosity-map grid metadata. |
Source code in src/voids/image/porosity.py
porosity_map_from_binary
¶
porosity_map_from_binary(
image,
*,
block_shape=None,
voxel_size=1.0,
image_is_void=True,
strict=True,
origin=None,
units=None,
metadata=None,
)
Compute a local porosity map from a segmented binary image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
ndarray
|
Binary 2D or 3D image. By default, |
required |
block_shape
|
Sequence[int] | None
|
Number of fine image voxels in each porosity-map cell. When omitted, each image voxel becomes one porosity-map cell. |
None
|
voxel_size
|
float | Sequence[float]
|
Scalar or per-axis fine-image voxel spacing in physical units. |
1.0
|
image_is_void
|
bool
|
If |
True
|
strict
|
bool
|
If |
True
|
origin
|
Sequence[float] | None
|
Optional physical and provenance metadata. |
None
|
units
|
Sequence[float] | None
|
Optional physical and provenance metadata. |
None
|
metadata
|
Sequence[float] | None
|
Optional physical and provenance metadata. |
None
|
Returns:
| Type | Description |
|---|---|
PorosityMap
|
Cell-average local porosity map. |
Source code in src/voids/image/porosity.py
porosity_map_from_grayscale
¶
porosity_map_from_grayscale(
grayscale,
*,
solid_gray,
pore_gray,
background_porosity=0.0,
block_shape=None,
voxel_size=1.0,
clip=True,
strict=True,
origin=None,
units=None,
metadata=None,
)
Compute a local porosity map from a calibrated grayscale image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grayscale
|
ndarray
|
Two- or three-dimensional grayscale image. |
required |
solid_gray
|
float
|
Calibration parameters passed to
:func: |
required |
pore_gray
|
float
|
Calibration parameters passed to
:func: |
required |
background_porosity
|
float
|
Calibration parameters passed to
:func: |
required |
clip
|
float
|
Calibration parameters passed to
:func: |
required |
block_shape
|
Sequence[int] | None
|
Number of fine image voxels in each porosity-map cell. When omitted, each image voxel becomes one porosity-map cell. |
None
|
voxel_size
|
float | Sequence[float]
|
Scalar or per-axis fine-image voxel spacing in physical units. |
1.0
|
strict
|
bool
|
If |
True
|
origin
|
Sequence[float] | None
|
Optional physical and provenance metadata. |
None
|
units
|
Sequence[float] | None
|
Optional physical and provenance metadata. |
None
|
metadata
|
Sequence[float] | None
|
Optional physical and provenance metadata. |
None
|
Returns:
| Type | Description |
|---|---|
PorosityMap
|
Cell-average local porosity map. |
Source code in src/voids/image/porosity.py
save_porosity_map_hdf5
¶
Write a porosity map to a compact HDF5 interchange file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
porosity_map
|
PorosityMap
|
Porosity map to serialize. |
required |
path
|
str | Path
|
Destination HDF5 file. Parent directories must already exist. |
required |
Notes
The stored array is named /porosity and contains cell-average porosity
values. Root attributes store schema and calibration metadata as JSON.
Source code in src/voids/image/porosity.py
load_porosity_map_hdf5
¶
Load a porosity map written by :func:save_porosity_map_hdf5.
Source code in src/voids/image/porosity.py
save_permeability_map_hdf5
¶
Write a permeability map to a compact HDF5 interchange file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
permeability_map
|
PermeabilityMap
|
Permeability map to serialize. |
required |
path
|
str | Path
|
Destination HDF5 file. Parent directories must already exist. |
required |
Notes
The stored array is named /permeability and contains cell-wise
permeability values. Root attributes store schema and closure metadata as
JSON.
Source code in src/voids/image/porosity.py
load_permeability_map_hdf5
¶
Load a permeability map written by :func:save_permeability_map_hdf5.
Source code in src/voids/image/porosity.py
Morphometry¶
The morphometry helpers compute local-thickness diameter maps for binary 2D/3D phase images. This API operates on an explicit phase mask supplied by the caller, requires isotropic voxel spacing, returns diameter-valued maps in the requested physical units, and summarizes values over the selected phase only.
For the scientific definition, radius-to-diameter conversion, backend method choices, and verification notes, see Local Thickness Morphometry.
voids.image.morphometry
¶
LocalThicknessSummary
dataclass
¶
Summary statistics for a local-thickness diameter map.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
Human-readable phase label, for example |
voxel_count |
int
|
Number of phase voxels used for the statistics. |
mean, std, p10, p50, p90, max |
Summary statistics of the local-thickness diameter over phase voxels. |
|
units |
str
|
Physical units of the returned diameter values. Use |
method |
str
|
PoreSpy local-thickness method used to generate the map. |
voxel_size |
float
|
Isotropic voxel edge length in |
Notes
BoneJ-style trabecular thickness and separation are diameter quantities:
each phase voxel is assigned the diameter of the largest sphere that fits
inside the phase and contains that voxel. PoreSpy reports the corresponding
local radius field, so voids multiplies by two and by voxel_size.
Source code in src/voids/image/morphometry.py
LocalThicknessResult
dataclass
¶
Local-thickness diameter map and summary for one binary phase.
Source code in src/voids/image/morphometry.py
local_thickness_map
¶
local_thickness_map(
phase_mask,
*,
voxel_size=1.0,
method="dt",
sizes=64,
smooth=True,
approx=False,
distance_map=None,
)
Compute a BoneJ-style local-thickness diameter map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phase_mask
|
ndarray
|
Boolean or binary 2D/3D image where |
required |
voxel_size
|
float | Sequence[float]
|
Isotropic voxel edge length. A scalar is preferred; a sequence is accepted only when all entries are equal. |
1.0
|
method
|
str
|
PoreSpy local-thickness backend. Common choices are |
'dt'
|
sizes
|
int | Sequence[float] | None
|
Radius sampling control forwarded to PoreSpy for |
64
|
smooth
|
bool
|
Controls forwarded to PoreSpy. |
True
|
approx
|
bool
|
Controls forwarded to PoreSpy. |
True
|
distance_map
|
ndarray | None
|
Optional Euclidean distance map in voxel units for |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Local-thickness diameter map in units of |
Notes
The public BoneJ description defines local thickness as the diameter of the largest sphere contained in the object and containing the point. PoreSpy's local-thickness filters return the corresponding local radius field; this function converts that radius to a diameter in physical units.
Source code in src/voids/image/morphometry.py
summarize_local_thickness_map
¶
summarize_local_thickness_map(
thickness_map,
phase_mask,
*,
label="phase",
units="voxel",
method="unknown",
voxel_size=1.0,
)
Summarize local-thickness values over phase voxels.
Source code in src/voids/image/morphometry.py
local_thickness_analysis
¶
local_thickness_analysis(
phase_mask,
*,
voxel_size=1.0,
units="voxel",
label="phase",
method="dt",
sizes=64,
smooth=True,
approx=False,
distance_map=None,
)
Compute a local-thickness diameter map and summary for one phase.
Source code in src/voids/image/morphometry.py
Network Extraction¶
voids.image.network_extraction
¶
NetworkExtractionResult
dataclass
¶
Store outputs of an image-to-network extraction workflow.
Attributes:
| Name | Type | Description |
|---|---|---|
image |
ndarray
|
Input phase image used for extraction. |
voxel_size |
float
|
Physical voxel edge length. |
axis_lengths |
dict[str, float]
|
Sample lengths by axis. |
axis_areas |
dict[str, float]
|
Cross-sectional areas normal to each axis. |
flow_axis |
str
|
Axis used for spanning subnetwork pruning. |
network_dict |
dict[str, object]
|
Intermediate extracted network mapping before conversion to
:class: |
sample |
SampleGeometry
|
Sample geometry attached to the network. |
provenance |
Provenance
|
Extraction provenance metadata. |
net_full |
Network
|
Full imported network before spanning pruning. |
net |
Network
|
Axis-spanning subnetwork. |
pore_indices |
ndarray
|
Indices of retained pores in |
throat_mask |
ndarray
|
Mask of retained throats in |
backend |
str
|
Extraction backend identifier (currently |
backend_version |
str | None
|
Backend version string when available. |
Source code in src/voids/image/network_extraction.py
NetworkConstructionResult
dataclass
¶
Store outputs of a general network-construction workflow.
This result type covers both image-based extraction backends and imported external-network backends such as Imperial CNM text files.
Source code in src/voids/image/network_extraction.py
infer_sample_axes
¶
Infer per-axis counts, lengths, areas, and the longest flow axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple[int, ...]
|
Image shape in voxel counts. |
required |
voxel_size
|
float
|
Edge length of one voxel in the target length unit. |
required |
axis_names
|
tuple[str, ...]
|
Axis labels mapped onto the image shape. |
('x', 'y', 'z')
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Source code in src/voids/image/network_extraction.py
extract_spanning_pore_network
¶
extract_spanning_pore_network(
phases,
*,
voxel_size,
backend="porespy",
flow_axis=None,
length_unit="m",
pressure_unit="Pa",
extraction_kwargs=None,
provenance_notes=None,
strict=True,
geometry_repairs="imperial_export",
repair_seed=0,
)
Extract, import, and prune an axis-spanning pore network from an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phases
|
ndarray
|
Binary or integer-labeled phase image where nonzero values are active phases passed to the extraction backend. |
required |
voxel_size
|
float
|
Edge length of one voxel in the declared |
required |
backend
|
str
|
Image-to-network extraction backend. Currently supported values are
|
'porespy'
|
flow_axis
|
str | None
|
Requested spanning axis. When omitted, the longest image axis is used. |
None
|
length_unit
|
str
|
Units stored in resulting :class: |
'm'
|
pressure_unit
|
str
|
Units stored in resulting :class: |
'm'
|
extraction_kwargs
|
dict[str, object] | None
|
Keyword arguments forwarded to the extraction backend call. For the
Imperial-calibrated |
None
|
provenance_notes
|
dict[str, object] | None
|
Optional extra provenance metadata attached to the resulting network. |
None
|
strict
|
bool
|
Forwarded to :func: |
True
|
geometry_repairs
|
str | None
|
Optional importer preprocessing mode. The default
|
'imperial_export'
|
repair_seed
|
int | None
|
Seed for any stochastic repair branch when |
0
|
Returns:
| Type | Description |
|---|---|
NetworkExtractionResult
|
Full and pruned networks together with intermediate metadata. |
Notes
Current implementation uses PoreSpy's snow2 backend and normalizes
accepted return styles into a standard network mapping before import. The
calibrated Imperial-style aliases still use snow2, but start from a
benchmark-tuned parameter profile that is closer to the committed
pnextract reference cases than the plain default.
Source code in src/voids/image/network_extraction.py
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 955 956 957 958 959 960 961 962 963 964 965 966 967 | |
construct_spanning_network
¶
construct_spanning_network(
*,
backend,
phases=None,
voxel_size=None,
pnflow_cnm_prefix=None,
pnflow_solver_box_compat=False,
flow_axis=None,
length_unit="m",
pressure_unit="Pa",
extraction_kwargs=None,
provenance_notes=None,
strict=True,
geometry_repairs="imperial_export",
repair_seed=0,
)
Construct a pore network from an image backend or imported CNM files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str
|
Construction backend identifier. Supported values include the existing
image-extraction aliases |
required |
phases
|
ndarray | None
|
Required for image-based backends and forwarded to
:func: |
None
|
voxel_size
|
ndarray | None
|
Required for image-based backends and forwarded to
:func: |
None
|
pnflow_cnm_prefix
|
str | Path | None
|
Required for the Imperial CNM backend. This is the shared path prefix
before the |
None
|
pnflow_solver_box_compat
|
bool
|
If |
False
|
flow_axis
|
str | None
|
|
None
|
length_unit
|
str | None
|
|
None
|
pressure_unit
|
str | None
|
|
None
|
extraction_kwargs
|
str | None
|
|
None
|
provenance_notes
|
str | None
|
|
None
|
strict
|
bool
|
Forwarded to the selected backend where applicable. |
True
|
geometry_repairs
|
bool
|
Forwarded to the selected backend where applicable. |
True
|
repair_seed
|
bool
|
Forwarded to the selected backend where applicable. |
True
|
Returns:
| Type | Description |
|---|---|
NetworkConstructionResult
|
Unified network-construction result. |
Source code in src/voids/image/network_extraction.py
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 | |
Segmentation¶
voids.image.segmentation
¶
VolumeCropResult
dataclass
¶
Store cylindrical-support cropping outputs from a grayscale volume.
Attributes:
| Name | Type | Description |
|---|---|---|
raw |
ndarray
|
Original grayscale volume as float array. |
specimen_mask |
ndarray
|
Slice-wise support mask after hole filling. |
common_mask |
ndarray
|
Per-pixel intersection of support masks over all slices. |
crop_bounds_yx |
tuple[int, int, int, int]
|
Maximal common rectangle bounds |
cropped |
ndarray
|
Cropped grayscale volume containing the common inscribed rectangle. |
Source code in src/voids/image/segmentation.py
GrayscaleSegmentationResult
dataclass
¶
Store grayscale preprocessing and binary segmentation outputs.
Attributes:
| Name | Type | Description |
|---|---|---|
crop |
VolumeCropResult
|
Cylindrical-support crop outputs. |
threshold |
float
|
Threshold used for binarization. |
binary |
ndarray
|
Segmented binary volume encoded as |
void_phase |
str
|
Phase polarity used for thresholding ( |
threshold_method |
str
|
Automatic method used when threshold was not explicitly supplied. |
Source code in src/voids/image/segmentation.py
largest_true_rectangle
¶
Return maximal-area axis-aligned rectangle fully contained in a mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask2d
|
ndarray
|
Two-dimensional boolean support mask. |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int, int, int]
|
Rectangle bounds |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/voids/image/segmentation.py
crop_nonzero_cylindrical_volume
¶
crop_nonzero_cylindrical_volume(
raw,
*,
background_value=0.0,
show_progress=False,
progress_desc=None,
)
Crop cylindrical specimen support to a common rectangular field of view.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
ndarray
|
Raw 3D grayscale volume. |
required |
background_value
|
float
|
Voxels strictly above this value are interpreted as specimen support before hole filling. |
0.0
|
show_progress
|
bool
|
Whether to show progress bars for slice-wise operations. |
False
|
progress_desc
|
str | None
|
Optional progress description string. |
None
|
Returns:
| Type | Description |
|---|---|
VolumeCropResult
|
Structured crop result with masks, bounds, and cropped volume. |
Source code in src/voids/image/segmentation.py
binarize_grayscale_volume
¶
Segment grayscale volume into binary void/solid phases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cropped
|
ndarray
|
Cropped 3D grayscale volume. |
required |
threshold
|
float | None
|
Explicit threshold; when omitted, an automatic threshold is computed. |
None
|
method
|
str
|
Automatic threshold method name. Supported values are |
'otsu'
|
void_phase
|
str
|
Which side of threshold corresponds to void: |
'dark'
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, float]
|
|
Source code in src/voids/image/segmentation.py
preprocess_grayscale_cylindrical_volume
¶
preprocess_grayscale_cylindrical_volume(
raw,
*,
background_value=0.0,
threshold=None,
threshold_method="otsu",
void_phase="dark",
show_progress=False,
progress_desc=None,
)
Run cylindrical crop and grayscale segmentation in one workflow call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
ndarray
|
Raw 3D grayscale specimen volume. |
required |
background_value
|
float
|
Background/support discriminator for cropping. |
0.0
|
threshold
|
float | None
|
Explicit segmentation threshold. |
None
|
threshold_method
|
str
|
Method used when |
'otsu'
|
void_phase
|
str
|
Phase polarity selector for thresholding. |
'dark'
|
show_progress
|
bool
|
Whether to request progress reporting. |
False
|
progress_desc
|
str | None
|
Optional progress message. |
None
|
Returns:
| Type | Description |
|---|---|
GrayscaleSegmentationResult
|
Crop metadata plus segmented binary volume. |
Source code in src/voids/image/segmentation.py
binarize_2d_with_voids
¶
Segment a 2D grayscale image using the same thresholding policy as 3D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gray2d
|
ndarray
|
Two-dimensional grayscale image. |
required |
threshold
|
float | None
|
Explicit threshold value. |
None
|
method
|
str
|
Automatic threshold method when |
'otsu'
|
void_phase
|
str
|
Which side of threshold corresponds to void. |
'dark'
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, float]
|
|
Source code in src/voids/image/segmentation.py
Image Connectivity¶
voids.image.connectivity
¶
has_spanning_cluster
¶
Test whether void space percolates from one boundary to the opposite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
void_mask
|
ndarray
|
Binary image where |
required |
axis_index
|
int
|
Flow/percolation axis index. For a 3D array |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
Connectivity is computed via :func:scipy.ndimage.label with its default
structuring element (face-connected in 3D, edge-connected in 2D). The
criterion is geometric percolation only; it does not assess hydraulic
conductance magnitude.
Assumptions and limitations
- Boundaries are interpreted as the first and last index along the target axis.
- Periodic boundaries are not considered.
- Very thin connections may percolate topologically even if they are not representative of realistic transport in a given experiment.
Source code in src/voids/image/connectivity.py
has_spanning_cluster_2d
¶
2D-specialized wrapper for axis-spanning connectivity checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
void_mask
|
ndarray
|
Two-dimensional binary void mask. |
required |
axis_index
|
int
|
Axis along which percolation is tested ( |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
This function exists for notebook/API compatibility and delegates to
:func:has_spanning_cluster after enforcing 2D inputs.