ritk-python 0.12.79__cp39-abi3-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,169 @@
1
+ """Type stubs for the ``_ritk.statistics`` submodule (compiled by PyO3/maturin).
2
+
3
+ Descriptive statistics, image comparison metrics, noise estimation,
4
+ and intensity normalization functions. All delegate to
5
+ ``ritk_core::statistics`` implementations (SSOT).
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Any
11
+
12
+ from ritk._ritk.image import Image
13
+
14
+ def compute_statistics(image: Image) -> dict[str, float]:
15
+ """Compute descriptive statistics over all voxels.
16
+
17
+ Returns dict with keys: min, max, mean, std, p25, p50, p75.
18
+ """
19
+ ...
20
+
21
+ def masked_statistics(image: Image, mask: Image) -> dict[str, float]:
22
+ """Compute descriptive statistics over foreground voxels (mask > 0.5).
23
+
24
+ Returns dict with keys: min, max, mean, std, p25, p50, p75.
25
+ """
26
+ ...
27
+
28
+ def dice_coefficient(image1: Image, image2: Image) -> float:
29
+ """Sørensen–Dice coefficient between two binary masks. Returns value in [0, 1]."""
30
+ ...
31
+
32
+ def similarity_index(image1: Image, image2: Image) -> float:
33
+ """ITK SimilarityIndex: 2|A∩B|/(|A|+|B|), binarizing (nonzero=foreground). ITK Parity: SimilarityIndexImageFilter."""
34
+ ...
35
+
36
+ def hausdorff_distance(image1: Image, image2: Image) -> float:
37
+ """Symmetric Hausdorff distance (mm) between two binary masks.
38
+
39
+ Spacing is derived from ``image1``'s voxel spacing.
40
+ """
41
+ ...
42
+
43
+ def mean_surface_distance(image1: Image, image2: Image) -> float:
44
+ """Symmetric mean surface distance (mm) between two binary masks.
45
+
46
+ Spacing is derived from ``image1``'s voxel spacing.
47
+ """
48
+ ...
49
+
50
+ def psnr(image1: Image, image2: Image, max_val: float = 1.0) -> float:
51
+ """Peak signal-to-noise ratio (dB).
52
+
53
+ Args:
54
+ image1: Test image.
55
+ image2: Reference image (same shape).
56
+ max_val: Dynamic range (default 1.0 for normalized images).
57
+ """
58
+ ...
59
+
60
+ def ssim(image1: Image, image2: Image, max_val: float = 1.0) -> float:
61
+ """Structural similarity index (Wang et al. 2004).
62
+
63
+ Args:
64
+ image1: Test image.
65
+ image2: Reference image (same shape).
66
+ max_val: Dynamic range (default 1.0 for normalized images).
67
+
68
+ Returns value in [-1, 1].
69
+ """
70
+ ...
71
+
72
+ def estimate_noise(image: Image, mask: Image | None = None) -> float:
73
+ """MAD-based Gaussian noise σ̂ estimate.
74
+
75
+ If *mask* is provided, only foreground voxels (mask > 0.5) contribute.
76
+ """
77
+ ...
78
+
79
+ def minmax_normalize(image: Image) -> Image:
80
+ """Min-max rescale to [0, 1]."""
81
+ ...
82
+
83
+ def minmax_normalize_range(image: Image, target_min: float, target_max: float) -> Image:
84
+ """Min-max rescale to [target_min, target_max]."""
85
+ ...
86
+
87
+ def zscore_normalize(image: Image, mask: Image | None = None) -> Image:
88
+ """Z-score standardization (zero mean, unit variance).
89
+
90
+ If *mask* is provided, statistics are computed from foreground voxels
91
+ (mask > 0.5) and applied to all voxels.
92
+ """
93
+ ...
94
+
95
+ def histogram_match(source: Image, reference: Image) -> Image:
96
+ """CDF-based histogram matching of *source* to *reference*."""
97
+ ...
98
+
99
+ def white_stripe_normalize(
100
+ image: Image,
101
+ mask: Image | None = None,
102
+ contrast: str | None = None,
103
+ width: float | None = None,
104
+ ) -> tuple[Image, float, float, float, int]:
105
+ """Shinohara et al. (2014) white stripe MRI normalization.
106
+
107
+ Args:
108
+ image: Input brain MRI.
109
+ mask: Optional brain mask (foreground > 0.5).
110
+ contrast: ``"t1"`` or ``"t2"`` (default ``"t1"``).
111
+ width: Stripe half-width in quantile units (default 0.05).
112
+
113
+ Returns:
114
+ (normalized_image, mu, sigma, wm_peak, stripe_size).
115
+ """
116
+ ...
117
+
118
+ def nyul_udupa_normalize(
119
+ image: Image,
120
+ training_images: list[Image],
121
+ ) -> Image:
122
+ """Nyul-Udupa piecewise-linear histogram standardization.
123
+
124
+ Args:
125
+ image: Image to normalize.
126
+ training_images: Non-empty list of images used to learn standard landmarks.
127
+
128
+ Returns:
129
+ Normalized image with the same shape and spatial metadata as *image*.
130
+
131
+ Raises:
132
+ RuntimeError: if training_images is empty or normalization fails.
133
+ """
134
+ ...
135
+
136
+ def compute_label_intensity_statistics(
137
+ label_image: Image,
138
+ intensity_image: Image,
139
+ ) -> list[dict[str, object]]:
140
+ """Per-label intensity statistics over a co-registered intensity image.
141
+
142
+ Background (label 0) is excluded. Results are sorted by label ascending.
143
+
144
+ Args:
145
+ label_image: Label image (integer labels as f32; 0 = background).
146
+ intensity_image: Intensity image with identical shape to label_image.
147
+
148
+ Returns:
149
+ list of dicts, one per label, each with keys:
150
+ ``label`` (int), ``count`` (int), ``min`` (float), ``max`` (float),
151
+ ``mean`` (float), ``std`` (float).
152
+
153
+ Raises:
154
+ RuntimeError: if images have different element counts.
155
+ """
156
+ ...
157
+
158
+ # -- Deformation-field Jacobian and label-overlap analysis --------------------
159
+
160
+ def jacobian_determinant(
161
+ disp_z: Image, disp_y: Image, disp_x: Image
162
+ ) -> Image: ...
163
+ def analyze_jacobian(jac: Image) -> dict[str, Any]: ...
164
+ def extended_label_shape_statistics_py(
165
+ label_image: Image,
166
+ ) -> list[dict[str, Any]]: ...
167
+ def label_overlap_measures(
168
+ prediction: Image, ground_truth: Image
169
+ ) -> dict[str, Any]: ...
ritk/_ritk.pyd ADDED
@@ -0,0 +1,4 @@
1
+ [diffend] Oversized file quarantined before diffing.
2
+ name: ritk/_ritk.pyd
3
+ size: 34272256 bytes
4
+ sha256: 66b26c2070c48626019de454bbf063950f74c2316a33a4caaaba1c68d942795f
ritk/py.typed ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.4
2
+ Name: ritk-python
3
+ Version: 0.12.79
4
+ Classifier: Development Status :: 3 - Alpha
5
+ Classifier: Intended Audience :: Science/Research
6
+ Classifier: License :: OSI Approved :: MIT License
7
+ Classifier: License :: OSI Approved :: Apache Software License
8
+ Classifier: Operating System :: POSIX :: Linux
9
+ Classifier: Operating System :: Microsoft :: Windows
10
+ Classifier: Operating System :: MacOS
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Rust
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Programming Language :: Python :: Implementation :: CPython
20
+ Classifier: Typing :: Typed
21
+ Requires-Dist: numpy>=2.0.2,<2.6 ; python_full_version < '3.15'
22
+ Requires-Dist: numpy>=2.5,<2.6 ; python_full_version >= '3.15'
23
+ Summary: Python bindings for the RITK medical imaging toolkit
24
+ Keywords: medical-imaging,dicom,registration,image-processing,rust
25
+ Author-email: Ryan Clanton <ryanclanton@outlook.com>
26
+ License: MIT OR Apache-2.0
27
+ Requires-Python: >=3.9
28
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
29
+ Project-URL: Documentation, https://ryancinsight.github.io/ritk/
30
+ Project-URL: Homepage, https://github.com/ryancinsight/ritk
31
+ Project-URL: Issues, https://github.com/ryancinsight/ritk/issues
32
+ Project-URL: Repository, https://github.com/ryancinsight/ritk
33
+
34
+ # ritk-python
35
+
36
+ PyO3/maturin Python extension module wrapping the RITK Rust crate.
37
+
38
+ ## Requirements
39
+
40
+ - Rust toolchain 1.97.0 (the repository pin)
41
+ - Python ≥ 3.9
42
+ - maturin ≥ 1.9.4, < 2.0
43
+ - NumPy ≥ 2.0.2, < 2.6 on Python < 3.15; NumPy ≥ 2.5, < 2.6 on Python ≥ 3.15
44
+
45
+ Install the parity-test dependencies from their canonical manifest:
46
+
47
+ ```sh
48
+ py -m pip install -r crates/ritk-python/requirements-test.txt
49
+ ```
50
+
51
+ ## Build
52
+
53
+ Build the stable-ABI wheel from the repository root:
54
+
55
+ ```sh
56
+ python -m pip install "maturin>=1.9.4,<2.0"
57
+ python -m maturin build --release --locked \
58
+ --manifest-path crates/ritk-python/Cargo.toml --out dist
59
+ ```
60
+
61
+ The Cargo feature set leaves PyO3's `extension-module` feature disabled so
62
+ Rust tests and binaries retain their normal Python link contract; maturin
63
+ 1.9.4 or newer supplies the extension-module build environment when producing
64
+ a wheel.
65
+
66
+ Install the wheel selected for the current interpreter:
67
+
68
+ ```sh
69
+ python -m pip install --force-reinstall --no-index --find-links dist ritk-python
70
+ ```
71
+
72
+ The release workflow builds the `abi3-py39` wheel matrix and the `abi3t` stable
73
+ free-threaded wheel, then publishes through GitHub Actions OIDC Trusted
74
+ Publishing. It stores no PyPI token or private key.
75
+
76
+ ## Free-threaded CPython
77
+
78
+ The `abi3t` feature targets CPython 3.15t and declares `gil_used = false` at
79
+ the module boundary. Build it with:
80
+
81
+ ```sh
82
+ python -m maturin build --release --locked --no-default-features --features abi3t \
83
+ --manifest-path crates/ritk-python/Cargo.toml --out dist
84
+ ```
85
+
86
+ `test_free_threaded.py` runs the value-semantic image contract on a
87
+ free-threaded interpreter. The test is skipped on GIL-enabled CPython because
88
+ it cannot establish the free-threaded contract there.
89
+
90
+ The hosted contract job installs the minimal dependencies listed in
91
+ `requirements-free-threaded.txt`. The regular parity matrix keeps the broader
92
+ `requirements-test.txt` set; native parity packages are not required to prove
93
+ the binding's free-threaded contract and may not publish prerelease
94
+ free-threaded wheels. NumPy 2.5 or newer is required for the free-threaded
95
+ contract because the abi3t array bridge uses the NumPy 2.5 C API surface.
96
+
97
+ ## Running Tests
98
+
99
+ ```sh
100
+ # VTK parity tests
101
+ py -m pytest crates/ritk-python/tests/test_vtk_parity.py -v
102
+
103
+ # SimpleITK parity tests (requires installed ritk wheel + SimpleITK)
104
+ py -m pytest crates/ritk-python/tests/test_simpleitk_parity.py -v
105
+
106
+ # CT/MRI DICOM parity tests (requires MRI-DIR test data in test_data/)
107
+ py -m pytest crates/ritk-python/tests/test_ct_mri_registration_parity.py -v
108
+
109
+ # All Python parity tests
110
+ py -m pytest crates/ritk-python/tests/ -v
111
+ ```
112
+
113
+ ## Module API
114
+
115
+ | Submodule | Key functions |
116
+ |---|---|
117
+ | `ritk.filter` | `discrete_gaussian`, `median_filter`, `bilateral_filter`, `gradient_magnitude`, `laplacian`, `sobel_gradient`, `n4_bias_correct`, `anisotropic_diffuse`, `frangi_vesselness` |
118
+ | `ritk.registration` | `demons_register`, `diffeomorphic_demons_register`, `syn_register`, `bspline_ffd_register`, `multires_syn_register`, `bspline_syn_register`, `lddmm_register`, `build_atlas`, `joint_label_fusion_py` |
119
+ | `ritk.segmentation` | `otsu_threshold`, `li_threshold`, `multi_otsu_threshold`, `binary_threshold`, `connected_components`, `binary_fill_holes`, `binary_erode`, `binary_dilate`, `kmeans_segment` |
120
+ | `ritk.statistics` | `compute_statistics`, `masked_statistics`, `histogram_match`, `minmax_normalize`, `zscore_normalize`, `psnr`, `ssim`, `dice_coefficient`, `hausdorff_distance` |
121
+ | `ritk.io` | `read_image`, `write_image`, `read_transform`, `write_transform` |
122
+
123
+ ## Architecture
124
+
125
+ The extension module (`_ritk.cdylib`) is compiled from `src/lib.rs` and registered as
126
+ submodules `filter`, `registration`, `segmentation`, `statistics`, and `io`. All computation
127
+ delegates to Rust crates (zero business logic in the binding layer). The image I/O boundary
128
+ uses `ritk-io`'s native readers/writers and converts only at the `PyImage` boundary. The
129
+ `PyImage` wrapper holds an `Arc<ritk_image::Image<f32, MoiraiBackend, 3>>` over Coeus/Leto
130
+ storage and provides `.to_numpy()` for zero-copy-where-possible extraction.
131
+
132
+ ### DICOM I/O
133
+
134
+ `ritk.io.read_image(path)` dispatches to `ritk_io::read_image_native`, which routes DICOM
135
+ directories through the native DICOM series reader before extension inference. A directory with
136
+ one image series can be passed directly. A mixed directory must name the acquisition explicitly:
137
+
138
+ ```python
139
+ image = ritk.io.read_image(
140
+ "test_data/3_head_ct_mridir/DICOM",
141
+ series_instance_uid="1.3.6.1.4.1.14519.5.2.1.1706.4996.115936088547498980797393821518",
142
+ )
143
+ ```
144
+
145
+ The UID is matched by RITK's scanner before pixels are decoded. Omitting it for a mixed directory,
146
+ passing an unknown or empty UID, or passing a non-directory with a UID fails with `IOError`; no
147
+ first-series fallback is used. Obtain the UID from RITK's series discovery or the DICOM metadata.
148
+
149
+ ### Native image I/O coverage
150
+
151
+ Python image reads use the Atlas-native path for NIfTI, MetaImage, NRRD, PNG, DICOM
152
+ directories, MGH/MGZ, TIFF, JPEG, and Analyze. Python image writes use the Atlas-native path
153
+ for NIfTI, MetaImage, NRRD, MGH/MGZ, TIFF, JPEG, and Analyze. PNG, DICOM, and VTK image writes
154
+ are rejected until native writers exist; VTK image reads are rejected until the VTK image reader
155
+ migrates to the native substrate.
156
+
157
+ ### Extension Points
158
+
159
+ | Abstraction | Mechanism | Adding a target |
160
+ |---|---|---|
161
+ | Compute backend | `ComputeBackend` trait | `impl ComputeBackend` for new device; no algorithm changes |
162
+ | GUI backend | `GuiBackend` trait | `impl GuiBackend` for new shell; no domain logic changes |
163
+ | Execution policy | GAT-based `ExecutionPolicy` | `impl ExecutionPolicy` for new regime |
164
+ | Scalar type | `Scalar` trait | `impl Scalar` for new numeric type |
165
+
166
+ All variation dimensions are encoded through traits, generics, associated types, and const
167
+ generics. No algorithm is cloned per backend, precision, layout, or execution regime.
168
+
@@ -0,0 +1,17 @@
1
+ ritk/__init__.py,sha256=dTc6GHPH0jfuW_Ehw8cfAKT1z_hml2KUSU6UxJ_1mhE,3648
2
+ ritk/__init__.pyi,sha256=jyqmd2jO7AYip6tXyhXNIIv5s8gHawOOsseY69-p73I,643
3
+ ritk/_ritk/__init__.pyi,sha256=UlAbFfJo-_fbpF5ewbDySXIFw6A4ftTufbq68kTFZN4,447
4
+ ritk/_ritk/connectome.pyi,sha256=D5ihepJ6szJMEvEPc9jvgMYCEHurvWuEivQpaDeECeo,2796
5
+ ritk/_ritk/diffusion.pyi,sha256=IbTh42oCjupf6o6WbAWZEOnCD2VqoGlrceGO2SoMdEU,2364
6
+ ritk/_ritk/filter.pyi,sha256=U1VBFg7HBGVmFBd1WjE3DZAJr-aaFlwlR74kkAMDhAs,43272
7
+ ritk/_ritk/image.pyi,sha256=Mdjb8wt2b8MieSxN0rc7r5PvixFWLSh5ZETebBKlBsA,1122
8
+ ritk/_ritk/io.pyi,sha256=PJ3Hb4vpZ4pEDnFq9TWJ8A5adN--aY6OQJ5KSa0pIcc,1000
9
+ ritk/_ritk/registration.pyi,sha256=Y-7KzsOKM7s5AzYXhhvYfkkNzGvOlSct4JTAKxMqqGA,4848
10
+ ritk/_ritk/segmentation.pyi,sha256=5NQmLS_LKTkph4BeAgkw4Iu2Uiv7KUGQciAAF-qfv88,12011
11
+ ritk/_ritk/statistics.pyi,sha256=D5l3dtMWtszOXi1cJbC2Uy_0DwqP8msNowpJMJuPdG8,5223
12
+ ritk/_ritk.pyd,sha256=ZrJsIHDEhiYBneRUu_BjlQ90wjFqM6TKqrocaNlCeV8,34272256
13
+ ritk/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
14
+ ritk_python-0.12.79.dist-info/METADATA,sha256=t98bRberLM2LLWx_1uI9FKNIcpt1nvjHt1JSAtLXOmU,7520
15
+ ritk_python-0.12.79.dist-info/WHEEL,sha256=_rgZdQc9sLFEqt2IemX7qyxsGt5fFRnBDATxGzerdmg,95
16
+ ritk_python-0.12.79.dist-info/sboms/ritk-python.cyclonedx.json,sha256=nrQq67OxtwGdqRU5JKkbiI7n6LiVQvNOE0cS-VZnxwc,476042
17
+ ritk_python-0.12.79.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.14.1)
3
+ Root-Is-Purelib: false
4
+ Tag: cp39-abi3-win_amd64