ritk-python 0.12.79__cp315-abi3.abi3t-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.
- ritk/__init__.py +100 -0
- ritk/__init__.pyi +18 -0
- ritk/_ritk/__init__.pyi +10 -0
- ritk/_ritk/connectome.pyi +90 -0
- ritk/_ritk/diffusion.pyi +72 -0
- ritk/_ritk/filter.pyi +1207 -0
- ritk/_ritk/image.pyi +36 -0
- ritk/_ritk/io.pyi +34 -0
- ritk/_ritk/registration.pyi +172 -0
- ritk/_ritk/segmentation.pyi +321 -0
- ritk/_ritk/statistics.pyi +169 -0
- ritk/_ritk.pyd +4 -0
- ritk/py.typed +1 -0
- ritk_python-0.12.79.dist-info/METADATA +168 -0
- ritk_python-0.12.79.dist-info/RECORD +17 -0
- ritk_python-0.12.79.dist-info/WHEEL +5 -0
- ritk_python-0.12.79.dist-info/sboms/ritk-python.cyclonedx.json +14012 -0
ritk/__init__.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ritk — Medical Image Processing Toolkit
|
|
3
|
+
========================================
|
|
4
|
+
|
|
5
|
+
Python bindings for the RITK Rust library, exposing:
|
|
6
|
+
|
|
7
|
+
- ``ritk.Image`` — Medical image with physical-space metadata (Z×Y×X, f32).
|
|
8
|
+
- ``ritk.io`` — Read / write NIfTI, PNG, DICOM, MetaImage, NRRD.
|
|
9
|
+
- ``ritk.filter`` — Gaussian, median, bilateral, anisotropic diffusion, edge detection, morphology.
|
|
10
|
+
- ``ritk.metrics`` — Image similarity metrics (MSE, NCC, mutual information).
|
|
11
|
+
- ``ritk.registration`` — Deformable registration (Demons, SyN, BSpline FFD, LDDMM, atlas building).
|
|
12
|
+
- ``ritk.segmentation`` — Thresholding, connected components, clustering, level sets, morphology.
|
|
13
|
+
- ``ritk.statistics`` — Descriptive statistics, comparison metrics, normalization.
|
|
14
|
+
- ``ritk.connectome`` — Anatomical parcellations, region connectomes, graph measures.
|
|
15
|
+
|
|
16
|
+
Quick start
|
|
17
|
+
-----------
|
|
18
|
+
>>> import ritk
|
|
19
|
+
>>> img = ritk.io.read_image("brain.nii.gz")
|
|
20
|
+
>>> smoothed = ritk.filter.gaussian_filter(img, sigma=1.0)
|
|
21
|
+
>>> threshold, mask = ritk.segmentation.otsu_threshold(smoothed)
|
|
22
|
+
>>> ritk.io.write_image(smoothed, "brain_smooth.nii.gz")
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from pathlib import Path as _Path
|
|
26
|
+
import os as _os
|
|
27
|
+
|
|
28
|
+
_DLL_DIRECTORY_HANDLES: list[object] = []
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _add_windows_dll_directories() -> None:
|
|
32
|
+
if _os.name != "nt" or not hasattr(_os, "add_dll_directory"):
|
|
33
|
+
return
|
|
34
|
+
|
|
35
|
+
package_dir = _Path(__file__).resolve().parent
|
|
36
|
+
candidate_dirs: list[_Path] = [package_dir]
|
|
37
|
+
|
|
38
|
+
for parent in package_dir.parents:
|
|
39
|
+
if (parent / "api-ms-win-core-winrt-error-l1-1-0.dll").exists():
|
|
40
|
+
candidate_dirs.append(parent)
|
|
41
|
+
break
|
|
42
|
+
|
|
43
|
+
msys_root = _Path(_os.environ.get("MSYS2_ROOT", r"D:\msys64"))
|
|
44
|
+
candidate_dirs.extend((msys_root / "mingw64" / "bin", msys_root / "ucrt64" / "bin"))
|
|
45
|
+
|
|
46
|
+
for directory in candidate_dirs:
|
|
47
|
+
if directory.is_dir():
|
|
48
|
+
_DLL_DIRECTORY_HANDLES.append(_os.add_dll_directory(str(directory)))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
_add_windows_dll_directories()
|
|
52
|
+
|
|
53
|
+
from ritk._ritk import (
|
|
54
|
+
__version__,
|
|
55
|
+
connectome, # noqa: F401
|
|
56
|
+
diffusion, # noqa: F401
|
|
57
|
+
filter, # noqa: F401
|
|
58
|
+
io, # noqa: F401
|
|
59
|
+
metrics, # noqa: F401
|
|
60
|
+
registration, # noqa: F401
|
|
61
|
+
segmentation, # noqa: F401
|
|
62
|
+
statistics, # noqa: F401
|
|
63
|
+
)
|
|
64
|
+
from ritk._ritk import image as _image_mod # noqa: F401 (submodule reference)
|
|
65
|
+
|
|
66
|
+
# Surface the Image class at the top-level namespace so users can write
|
|
67
|
+
# ``ritk.Image(array, spacing=...)`` instead of ``ritk.image.Image(...)``.
|
|
68
|
+
image = _image_mod # expose ritk.image as top-level attribute
|
|
69
|
+
Image = _image_mod.Image # extract from already-imported submodule attribute
|
|
70
|
+
ColorImage = _image_mod.ColorImage # RGB/vector multi-component image
|
|
71
|
+
|
|
72
|
+
import sys as _sys
|
|
73
|
+
|
|
74
|
+
# Register PyO3 submodule objects in sys.modules so that
|
|
75
|
+
# "import ritk.filter", "import ritk.io", etc. work as expected.
|
|
76
|
+
# PyO3 add_submodule() exposes submodules as attributes but does not
|
|
77
|
+
# automatically register them as importable paths; we do it here.
|
|
78
|
+
_sys.modules.setdefault("ritk.connectome", connectome)
|
|
79
|
+
_sys.modules.setdefault("ritk.diffusion", diffusion)
|
|
80
|
+
_sys.modules.setdefault("ritk.filter", filter)
|
|
81
|
+
_sys.modules.setdefault("ritk.io", io)
|
|
82
|
+
_sys.modules.setdefault("ritk.metrics", metrics)
|
|
83
|
+
_sys.modules.setdefault("ritk.registration", registration)
|
|
84
|
+
_sys.modules.setdefault("ritk.segmentation", segmentation)
|
|
85
|
+
_sys.modules.setdefault("ritk.statistics", statistics)
|
|
86
|
+
_sys.modules.setdefault("ritk.image", _image_mod)
|
|
87
|
+
|
|
88
|
+
__all__ = [
|
|
89
|
+
"Image",
|
|
90
|
+
"ColorImage",
|
|
91
|
+
"image",
|
|
92
|
+
"io",
|
|
93
|
+
"connectome",
|
|
94
|
+
"diffusion",
|
|
95
|
+
"filter",
|
|
96
|
+
"metrics",
|
|
97
|
+
"registration",
|
|
98
|
+
"segmentation",
|
|
99
|
+
"statistics",
|
|
100
|
+
]
|
ritk/__init__.pyi
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Type stubs for the ``ritk`` Python package (top-level re-exports)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from ritk._ritk import connectome as connectome
|
|
6
|
+
from ritk._ritk import filter as filter
|
|
7
|
+
from ritk._ritk import image as image
|
|
8
|
+
from ritk._ritk import io as io
|
|
9
|
+
from ritk._ritk import metrics as metrics
|
|
10
|
+
from ritk._ritk import registration as registration
|
|
11
|
+
from ritk._ritk import segmentation as segmentation
|
|
12
|
+
from ritk._ritk import diffusion as diffusion
|
|
13
|
+
from ritk._ritk import statistics as statistics
|
|
14
|
+
from ritk._ritk.image import ColorImage as ColorImage
|
|
15
|
+
from ritk._ritk.image import Image as Image
|
|
16
|
+
|
|
17
|
+
__all__: list[str]
|
|
18
|
+
__version__: str
|
ritk/_ritk/__init__.pyi
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Type stub package for the native _ritk extension module (compiled by PyO3/maturin)."""
|
|
2
|
+
|
|
3
|
+
from ritk._ritk import connectome as connectome
|
|
4
|
+
from ritk._ritk import diffusion as diffusion
|
|
5
|
+
from ritk._ritk import filter as filter
|
|
6
|
+
from ritk._ritk import image as image
|
|
7
|
+
from ritk._ritk import io as io
|
|
8
|
+
from ritk._ritk import registration as registration
|
|
9
|
+
from ritk._ritk import segmentation as segmentation
|
|
10
|
+
from ritk._ritk import statistics as statistics
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""Type stubs for the ``_ritk.connectome`` submodule (PyO3/maturin).
|
|
2
|
+
|
|
3
|
+
All signatures derived from ``ritk-python/src/connectome/``.
|
|
4
|
+
|
|
5
|
+
Array conventions: label volumes are ``[Z, Y, X]``, and ``spacing``, ``origin``,
|
|
6
|
+
and ``direction`` are given outermost-axis first — the same order an ``Image``
|
|
7
|
+
reports. Streamlines are ``[N, 3]`` float arrays in the parcellation's physical
|
|
8
|
+
frame.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from typing import Any, Sequence
|
|
14
|
+
|
|
15
|
+
class Parcellation:
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
labels: Any,
|
|
19
|
+
spacing: Sequence[float],
|
|
20
|
+
origin: Sequence[float],
|
|
21
|
+
direction: Sequence[float] | None = None,
|
|
22
|
+
region_names: list[tuple[int, str]] | None = None,
|
|
23
|
+
) -> None: ...
|
|
24
|
+
def __len__(self) -> int: ...
|
|
25
|
+
def __repr__(self) -> str: ...
|
|
26
|
+
@property
|
|
27
|
+
def region_count(self) -> int: ...
|
|
28
|
+
@property
|
|
29
|
+
def region_labels(self) -> list[int]: ...
|
|
30
|
+
@property
|
|
31
|
+
def shape(self) -> list[int]: ...
|
|
32
|
+
def labels(self) -> Any: ...
|
|
33
|
+
def name_of(self, label: int) -> str | None: ...
|
|
34
|
+
def label_at(self, point: Sequence[float]) -> int | None: ...
|
|
35
|
+
def region_statistics(self) -> list[dict[str, Any]]: ...
|
|
36
|
+
|
|
37
|
+
class GraphMeasures:
|
|
38
|
+
def __repr__(self) -> str: ...
|
|
39
|
+
@property
|
|
40
|
+
def node_count(self) -> int: ...
|
|
41
|
+
@property
|
|
42
|
+
def edge_count(self) -> int: ...
|
|
43
|
+
@property
|
|
44
|
+
def density(self) -> float: ...
|
|
45
|
+
@property
|
|
46
|
+
def characteristic_path_length(self) -> float | None: ...
|
|
47
|
+
@property
|
|
48
|
+
def reachable_pair_fraction(self) -> float: ...
|
|
49
|
+
@property
|
|
50
|
+
def global_efficiency(self) -> float: ...
|
|
51
|
+
@property
|
|
52
|
+
def component_sizes(self) -> list[int]: ...
|
|
53
|
+
@property
|
|
54
|
+
def modularity(self) -> float: ...
|
|
55
|
+
@property
|
|
56
|
+
def community_count(self) -> int: ...
|
|
57
|
+
def degree(self) -> Any: ...
|
|
58
|
+
def strength(self) -> Any: ...
|
|
59
|
+
def clustering(self) -> Any: ...
|
|
60
|
+
def weighted_clustering(self) -> Any: ...
|
|
61
|
+
def betweenness(self) -> Any: ...
|
|
62
|
+
def local_efficiency(self) -> Any: ...
|
|
63
|
+
def communities(self) -> Any: ...
|
|
64
|
+
|
|
65
|
+
class ConnectivityMatrix:
|
|
66
|
+
def __len__(self) -> int: ...
|
|
67
|
+
def __repr__(self) -> str: ...
|
|
68
|
+
@property
|
|
69
|
+
def region_labels(self) -> list[int]: ...
|
|
70
|
+
@property
|
|
71
|
+
def accounting(self) -> dict[str, int]: ...
|
|
72
|
+
@property
|
|
73
|
+
def edge_count(self) -> int: ...
|
|
74
|
+
@property
|
|
75
|
+
def density(self) -> float: ...
|
|
76
|
+
def weights(self) -> Any: ...
|
|
77
|
+
def measures(self) -> GraphMeasures: ...
|
|
78
|
+
def rich_club(
|
|
79
|
+
self,
|
|
80
|
+
ensemble_size: int,
|
|
81
|
+
seed: int,
|
|
82
|
+
swaps_per_edge: int | None = None,
|
|
83
|
+
) -> tuple[list[dict[str, Any]], float]: ...
|
|
84
|
+
|
|
85
|
+
def build_connectivity_matrix(
|
|
86
|
+
parcellation: Parcellation,
|
|
87
|
+
streamlines: Sequence[Any],
|
|
88
|
+
assignment_radius: float | None = None,
|
|
89
|
+
weighting: str | None = None,
|
|
90
|
+
) -> ConnectivityMatrix: ...
|
ritk/_ritk/diffusion.pyi
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Type stubs for the ``_ritk.diffusion`` submodule (tensor fitting)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Sequence
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import numpy.typing as npt
|
|
9
|
+
|
|
10
|
+
from ritk._ritk.image import Image
|
|
11
|
+
|
|
12
|
+
class DiffusionMaps:
|
|
13
|
+
"""Fitted tensor field and the scalar maps derived from it.
|
|
14
|
+
|
|
15
|
+
Every accessor returns a fresh array shaped ``[Z, Y, X]``, matching the
|
|
16
|
+
volumes the fit was given; the eigenvector field is ``[Z, Y, X, 3]``.
|
|
17
|
+
|
|
18
|
+
Voxels that were not fitted read zero in every map, so ``mask`` is the only
|
|
19
|
+
thing that separates them from a voxel genuinely measured as isotropic.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def fitted_count(self) -> int:
|
|
24
|
+
"""Voxels that yielded a physically admissible tensor."""
|
|
25
|
+
...
|
|
26
|
+
|
|
27
|
+
def __len__(self) -> int:
|
|
28
|
+
"""Voxels in the volume."""
|
|
29
|
+
...
|
|
30
|
+
|
|
31
|
+
def mask(self) -> npt.NDArray[np.bool_]:
|
|
32
|
+
"""Which voxels were fitted, shaped ``[Z, Y, X]``."""
|
|
33
|
+
...
|
|
34
|
+
|
|
35
|
+
def fractional_anisotropy(self) -> npt.NDArray[np.float32]:
|
|
36
|
+
"""Fractional anisotropy in ``[0, 1]``, shaped ``[Z, Y, X]``."""
|
|
37
|
+
...
|
|
38
|
+
|
|
39
|
+
def mean_diffusivity(self) -> npt.NDArray[np.float32]:
|
|
40
|
+
"""Mean diffusivity in mm²/s, shaped ``[Z, Y, X]``."""
|
|
41
|
+
...
|
|
42
|
+
|
|
43
|
+
def axial_diffusivity(self) -> npt.NDArray[np.float32]:
|
|
44
|
+
"""Axial diffusivity ``λ₁`` in mm²/s, shaped ``[Z, Y, X]``."""
|
|
45
|
+
...
|
|
46
|
+
|
|
47
|
+
def radial_diffusivity(self) -> npt.NDArray[np.float32]:
|
|
48
|
+
"""Radial diffusivity ``(λ₂ + λ₃) / 2`` in mm²/s, shaped ``[Z, Y, X]``."""
|
|
49
|
+
...
|
|
50
|
+
|
|
51
|
+
def principal_eigenvector(self) -> npt.NDArray[np.float32]:
|
|
52
|
+
"""Local fibre orientation, shaped ``[Z, Y, X, 3]``.
|
|
53
|
+
|
|
54
|
+
Unit length wherever a tensor was fitted, exactly zero elsewhere. The
|
|
55
|
+
vector carries no sign: ``v`` and ``-v`` describe the same fibre.
|
|
56
|
+
"""
|
|
57
|
+
...
|
|
58
|
+
|
|
59
|
+
def fit_tensor_maps(
|
|
60
|
+
volumes: Sequence[Image],
|
|
61
|
+
bvals: Sequence[float],
|
|
62
|
+
bvecs: Sequence[Sequence[float]],
|
|
63
|
+
background_fraction: float | None = None,
|
|
64
|
+
) -> DiffusionMaps:
|
|
65
|
+
"""Fit one diffusion tensor per voxel and derive its scalar maps.
|
|
66
|
+
|
|
67
|
+
Raises:
|
|
68
|
+
ValueError: if the volume, b-value and direction counts disagree, the
|
|
69
|
+
volumes do not share a grid, the scheme has no ``b = 0`` reference,
|
|
70
|
+
or ``background_fraction`` is not a usable number.
|
|
71
|
+
"""
|
|
72
|
+
...
|