diffct-mlx 1.0.1__py3-none-any.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.
- diffct_mlx/__about__.py +3 -0
- diffct_mlx/__init__.py +223 -0
- diffct_mlx/constants.py +38 -0
- diffct_mlx/geometry.py +802 -0
- diffct_mlx/kernels/__init__.py +39 -0
- diffct_mlx/kernels/cone_beam.py +708 -0
- diffct_mlx/kernels/fan_beam.py +502 -0
- diffct_mlx/kernels/parallel_beam.py +431 -0
- diffct_mlx/phantoms/__init__.py +5 -0
- diffct_mlx/phantoms/shepp_logan.py +118 -0
- diffct_mlx/projectors.py +1084 -0
- diffct_mlx/real_measured_data_helper.py +601 -0
- diffct_mlx/reconstruction_algorithms/__init__.py +85 -0
- diffct_mlx/reconstruction_algorithms/_analytic.py +101 -0
- diffct_mlx/reconstruction_algorithms/_core.py +872 -0
- diffct_mlx/reconstruction_algorithms/asd_pocs.py +114 -0
- diffct_mlx/reconstruction_algorithms/awtv_pocs.py +106 -0
- diffct_mlx/reconstruction_algorithms/cases.py +988 -0
- diffct_mlx/reconstruction_algorithms/dart.py +424 -0
- diffct_mlx/reconstruction_algorithms/fbp.py +69 -0
- diffct_mlx/reconstruction_algorithms/fdk.py +67 -0
- diffct_mlx/reconstruction_algorithms/sart.py +66 -0
- diffct_mlx/reconstruction_algorithms/sirt.py +64 -0
- diffct_mlx/reconstruction_algorithms/tv_pocs.py +85 -0
- diffct_mlx/regularizers.py +122 -0
- diffct_mlx/tv_gradients.py +74 -0
- diffct_mlx/utils.py +64 -0
- diffct_mlx-1.0.1.dist-info/METADATA +315 -0
- diffct_mlx-1.0.1.dist-info/RECORD +31 -0
- diffct_mlx-1.0.1.dist-info/WHEEL +4 -0
- diffct_mlx-1.0.1.dist-info/licenses/LICENSE +201 -0
diffct_mlx/__about__.py
ADDED
diffct_mlx/__init__.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"""DiffCT-MLX — Differentiable CT Reconstruction for Apple Silicon.
|
|
2
|
+
|
|
3
|
+
A GPU-accelerated, differentiable computed tomography (CT) forward and backward
|
|
4
|
+
projection library built with MLX and custom Metal kernels, optimized for
|
|
5
|
+
Apple Silicon (M-series) chips.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .projectors import (
|
|
9
|
+
parallel_forward,
|
|
10
|
+
parallel_backward,
|
|
11
|
+
parallel_forward_footprint,
|
|
12
|
+
parallel_backward_footprint,
|
|
13
|
+
fan_forward,
|
|
14
|
+
fan_backward,
|
|
15
|
+
fan_forward_footprint,
|
|
16
|
+
fan_backward_footprint,
|
|
17
|
+
cone_forward,
|
|
18
|
+
cone_backward,
|
|
19
|
+
cone_forward_footprint,
|
|
20
|
+
cone_backward_footprint,
|
|
21
|
+
)
|
|
22
|
+
from .regularizers import (
|
|
23
|
+
l2_regularizer,
|
|
24
|
+
normalize_reconstruction_volume,
|
|
25
|
+
tv_regularizer,
|
|
26
|
+
tv_regularizer_3d,
|
|
27
|
+
awtv_regularizer,
|
|
28
|
+
tv_pocs,
|
|
29
|
+
asd_pocs,
|
|
30
|
+
awtv_pocs,
|
|
31
|
+
)
|
|
32
|
+
from .tv_gradients import (
|
|
33
|
+
tv_gradient,
|
|
34
|
+
weight_d_volume,
|
|
35
|
+
awtv_gradient,
|
|
36
|
+
)
|
|
37
|
+
from .phantoms import (
|
|
38
|
+
shepp_logan_2d,
|
|
39
|
+
shepp_logan_3d,
|
|
40
|
+
)
|
|
41
|
+
from .reconstruction_algorithms import (
|
|
42
|
+
MeasuredConeDataConfig,
|
|
43
|
+
NpyProjectionsConfig,
|
|
44
|
+
ReconstructionCase,
|
|
45
|
+
ReconstructionParameters,
|
|
46
|
+
RegularizationParameters,
|
|
47
|
+
Reconstruction_Parameter,
|
|
48
|
+
Regularisation_Parameter,
|
|
49
|
+
build_parallel_2d_case,
|
|
50
|
+
build_fan_2d_case,
|
|
51
|
+
build_cone_3d_case,
|
|
52
|
+
build_measured_cone_3d_case,
|
|
53
|
+
build_npy_cone_3d_case,
|
|
54
|
+
make_parallel_2d_operators,
|
|
55
|
+
make_fan_2d_operators,
|
|
56
|
+
make_cone_3d_operators,
|
|
57
|
+
SARTParameters,
|
|
58
|
+
SIRTParameters,
|
|
59
|
+
run_sart,
|
|
60
|
+
run_sirt,
|
|
61
|
+
reconstruct_sart,
|
|
62
|
+
reconstruct_sirt,
|
|
63
|
+
TVPOCSParameters,
|
|
64
|
+
TV_POCS_Parameter,
|
|
65
|
+
run_tv_pocs,
|
|
66
|
+
reconstruct_tv_pocs,
|
|
67
|
+
ASDPOCSParameters,
|
|
68
|
+
ASD_POCS_Parameter,
|
|
69
|
+
run_asd_pocs,
|
|
70
|
+
reconstruct_asd_pocs,
|
|
71
|
+
AwTVPOCSParameters,
|
|
72
|
+
AwTV_POCS_Parameter,
|
|
73
|
+
run_awtv_pocs,
|
|
74
|
+
reconstruct_awtv_pocs,
|
|
75
|
+
DARTParameters,
|
|
76
|
+
run_dart,
|
|
77
|
+
reconstruct_dart,
|
|
78
|
+
FBPParameters,
|
|
79
|
+
run_fbp,
|
|
80
|
+
reconstruct_fbp,
|
|
81
|
+
FDKParameters,
|
|
82
|
+
run_fdk,
|
|
83
|
+
reconstruct_fdk,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
from .real_measured_data_helper import (
|
|
87
|
+
apply_detector_array_convention,
|
|
88
|
+
apply_detector_geometry_convention,
|
|
89
|
+
apply_upper_left_detector_transform,
|
|
90
|
+
auto_voxel_spacing_from_detector,
|
|
91
|
+
build_upper_left_detector_transform,
|
|
92
|
+
diagnose_cone_geometry,
|
|
93
|
+
estimate_cone_isocenter,
|
|
94
|
+
mu_to_hu,
|
|
95
|
+
mu_to_uint16,
|
|
96
|
+
normalize_volume,
|
|
97
|
+
resize_volume_to_shape,
|
|
98
|
+
shift_detector_center,
|
|
99
|
+
transform_detector_offsets,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
from .geometry import (
|
|
103
|
+
circular_trajectory_3d,
|
|
104
|
+
random_trajectory_3d,
|
|
105
|
+
spiral_trajectory_3d,
|
|
106
|
+
sinusoidal_trajectory_3d,
|
|
107
|
+
saddle_trajectory_3d,
|
|
108
|
+
custom_trajectory_3d,
|
|
109
|
+
load_arbitrary_cone_geometry_from_json,
|
|
110
|
+
circular_trajectory_2d_fan,
|
|
111
|
+
sinusoidal_trajectory_2d_fan,
|
|
112
|
+
custom_trajectory_2d_fan,
|
|
113
|
+
circular_trajectory_2d_parallel,
|
|
114
|
+
sinusoidal_trajectory_2d_parallel,
|
|
115
|
+
custom_trajectory_2d_parallel,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
from .__about__ import __version__
|
|
119
|
+
|
|
120
|
+
__all__ = [
|
|
121
|
+
# Projector functions
|
|
122
|
+
'parallel_forward',
|
|
123
|
+
'parallel_backward',
|
|
124
|
+
'parallel_forward_footprint',
|
|
125
|
+
'parallel_backward_footprint',
|
|
126
|
+
'fan_forward',
|
|
127
|
+
'fan_backward',
|
|
128
|
+
'fan_forward_footprint',
|
|
129
|
+
'fan_backward_footprint',
|
|
130
|
+
'cone_forward',
|
|
131
|
+
'cone_backward',
|
|
132
|
+
'cone_forward_footprint',
|
|
133
|
+
'cone_backward_footprint',
|
|
134
|
+
'l2_regularizer',
|
|
135
|
+
'normalize_reconstruction_volume',
|
|
136
|
+
'tv_regularizer',
|
|
137
|
+
'tv_regularizer_3d',
|
|
138
|
+
'awtv_regularizer',
|
|
139
|
+
'tv_pocs',
|
|
140
|
+
'asd_pocs',
|
|
141
|
+
'awtv_pocs',
|
|
142
|
+
'tv_gradient',
|
|
143
|
+
'weight_d_volume',
|
|
144
|
+
'awtv_gradient',
|
|
145
|
+
'shepp_logan_2d',
|
|
146
|
+
'shepp_logan_3d',
|
|
147
|
+
'MeasuredConeDataConfig',
|
|
148
|
+
'NpyProjectionsConfig',
|
|
149
|
+
'ReconstructionCase',
|
|
150
|
+
'ReconstructionParameters',
|
|
151
|
+
'RegularizationParameters',
|
|
152
|
+
'Reconstruction_Parameter',
|
|
153
|
+
'Regularisation_Parameter',
|
|
154
|
+
'build_parallel_2d_case',
|
|
155
|
+
'build_fan_2d_case',
|
|
156
|
+
'build_cone_3d_case',
|
|
157
|
+
'build_measured_cone_3d_case',
|
|
158
|
+
'build_npy_cone_3d_case',
|
|
159
|
+
'make_parallel_2d_operators',
|
|
160
|
+
'make_fan_2d_operators',
|
|
161
|
+
'make_cone_3d_operators',
|
|
162
|
+
'SARTParameters',
|
|
163
|
+
'SIRTParameters',
|
|
164
|
+
'SARTDiagnosticsResult',
|
|
165
|
+
'SARTProjectionSnapshot',
|
|
166
|
+
'default_projection_indices',
|
|
167
|
+
'diagnose_sart',
|
|
168
|
+
'plot_sart_projection_diagnostics',
|
|
169
|
+
'run_sart',
|
|
170
|
+
'run_sirt',
|
|
171
|
+
'reconstruct_sart',
|
|
172
|
+
'reconstruct_sirt',
|
|
173
|
+
'TVPOCSParameters',
|
|
174
|
+
'TV_POCS_Parameter',
|
|
175
|
+
'run_tv_pocs',
|
|
176
|
+
'reconstruct_tv_pocs',
|
|
177
|
+
'ASDPOCSParameters',
|
|
178
|
+
'ASD_POCS_Parameter',
|
|
179
|
+
'run_asd_pocs',
|
|
180
|
+
'reconstruct_asd_pocs',
|
|
181
|
+
'AwTVPOCSParameters',
|
|
182
|
+
'AwTV_POCS_Parameter',
|
|
183
|
+
'run_awtv_pocs',
|
|
184
|
+
'reconstruct_awtv_pocs',
|
|
185
|
+
'DARTParameters',
|
|
186
|
+
'run_dart',
|
|
187
|
+
'reconstruct_dart',
|
|
188
|
+
'FBPParameters',
|
|
189
|
+
'run_fbp',
|
|
190
|
+
'reconstruct_fbp',
|
|
191
|
+
'FDKParameters',
|
|
192
|
+
'run_fdk',
|
|
193
|
+
'reconstruct_fdk',
|
|
194
|
+
# 3D trajectory generators
|
|
195
|
+
'circular_trajectory_3d',
|
|
196
|
+
'random_trajectory_3d',
|
|
197
|
+
'spiral_trajectory_3d',
|
|
198
|
+
'sinusoidal_trajectory_3d',
|
|
199
|
+
'saddle_trajectory_3d',
|
|
200
|
+
'custom_trajectory_3d',
|
|
201
|
+
'apply_detector_array_convention',
|
|
202
|
+
'apply_detector_geometry_convention',
|
|
203
|
+
'apply_upper_left_detector_transform',
|
|
204
|
+
'auto_voxel_spacing_from_detector',
|
|
205
|
+
'build_upper_left_detector_transform',
|
|
206
|
+
'diagnose_cone_geometry',
|
|
207
|
+
'estimate_cone_isocenter',
|
|
208
|
+
'mu_to_hu',
|
|
209
|
+
'mu_to_uint16',
|
|
210
|
+
'normalize_volume',
|
|
211
|
+
'resize_volume_to_shape',
|
|
212
|
+
'shift_detector_center',
|
|
213
|
+
'transform_detector_offsets',
|
|
214
|
+
'load_arbitrary_cone_geometry_from_json',
|
|
215
|
+
# 2D fan beam trajectory generators
|
|
216
|
+
'circular_trajectory_2d_fan',
|
|
217
|
+
'sinusoidal_trajectory_2d_fan',
|
|
218
|
+
'custom_trajectory_2d_fan',
|
|
219
|
+
# 2D parallel beam trajectory generators
|
|
220
|
+
'circular_trajectory_2d_parallel',
|
|
221
|
+
'sinusoidal_trajectory_2d_parallel',
|
|
222
|
+
'custom_trajectory_2d_parallel',
|
|
223
|
+
]
|
diffct_mlx/constants.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Global constants and configuration for DiffCT-MLX package.
|
|
2
|
+
|
|
3
|
+
This module defines core constants used throughout the DiffCT-MLX package,
|
|
4
|
+
including data types, Metal thread group configurations, and numerical
|
|
5
|
+
precision parameters.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
import mlx.core as mx
|
|
10
|
+
|
|
11
|
+
# ---------------------------------------------------------------------------
|
|
12
|
+
# Data Types and Numerical Constants
|
|
13
|
+
# ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
_DTYPE = np.float32
|
|
16
|
+
"""Default data type for numerical computations (numpy.float32)."""
|
|
17
|
+
|
|
18
|
+
_MX_DTYPE = mx.float32
|
|
19
|
+
"""Default MLX data type for GPU computations."""
|
|
20
|
+
|
|
21
|
+
_INF = np.float32(np.inf)
|
|
22
|
+
"""Floating-point infinity in default data type."""
|
|
23
|
+
|
|
24
|
+
_EPSILON = np.float32(1e-6)
|
|
25
|
+
"""Small epsilon value for numerical comparisons to avoid division by zero."""
|
|
26
|
+
|
|
27
|
+
# ---------------------------------------------------------------------------
|
|
28
|
+
# Metal Thread Group Configurations
|
|
29
|
+
# ---------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
# Metal threadgroup sizes optimized for Apple Silicon GPU
|
|
32
|
+
# 2D threadgroups: 16x16 = 256 threads, optimal for 2D ray-tracing kernels
|
|
33
|
+
_TG_2D = (16, 16)
|
|
34
|
+
"""Metal threads-per-threadgroup for 2D kernels (parallel/fan beam): (16, 16) = 256 threads."""
|
|
35
|
+
|
|
36
|
+
# 3D threadgroups: 8x8x8 = 512 threads, optimal for 3D cone beam kernels
|
|
37
|
+
_TG_3D = (8, 8, 8)
|
|
38
|
+
"""Metal threads-per-threadgroup for 3D kernels (cone beam): (8, 8, 8) = 512 threads."""
|