diffct-mlx 2.1.0__py3-none-any.whl → 2.3.0__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/kernels/cone_footprint.py +20 -3
- diffct/kernels/fan_footprint.py +10 -8
- diffct/kernels/parallel_footprint.py +4 -4
- diffct_mlx/__init__.py +6 -1
- diffct_mlx/backend/metal/kernels/cone_beam.py +17 -3
- diffct_mlx/backend/metal/kernels/fan_beam.py +8 -8
- diffct_mlx/backend/metal/kernels/parallel_beam.py +4 -4
- diffct_mlx/conventions.py +83 -0
- diffct_mlx/operators.py +80 -22
- diffct_mlx/physics/simulate.py +7 -2
- diffct_mlx/reconstruction_algorithms/cases.py +72 -12
- {diffct_mlx-2.1.0.dist-info → diffct_mlx-2.3.0.dist-info}/METADATA +18 -3
- {diffct_mlx-2.1.0.dist-info → diffct_mlx-2.3.0.dist-info}/RECORD +15 -14
- {diffct_mlx-2.1.0.dist-info → diffct_mlx-2.3.0.dist-info}/WHEEL +1 -1
- {diffct_mlx-2.1.0.dist-info → diffct_mlx-2.3.0.dist-info}/licenses/LICENSE +0 -0
diffct/kernels/cone_footprint.py
CHANGED
|
@@ -118,7 +118,12 @@ def _cone_3d_footprint_forward_kernel(
|
|
|
118
118
|
fp_u_hi = u0 + half_u
|
|
119
119
|
fp_v_lo = v0 - half_v
|
|
120
120
|
fp_v_hi = v0 + half_v
|
|
121
|
-
|
|
121
|
+
# Mass-conserving footprint amplitude: the output is a voxel-unit line integral
|
|
122
|
+
# averaged over the detector cell, on the same scale as the Siddon projector.
|
|
123
|
+
# A voxel of volume vs^3 spreads over (vs * t)^2 * ray_len / |denom| of detector area.
|
|
124
|
+
ray_len = math.sqrt(rx * rx + ry * ry + rz * rz)
|
|
125
|
+
amp = (voxel_spacing * voxel_spacing / (du * dv)) * t * t * ray_len * abs(inv_denom)
|
|
126
|
+
scaled_val = val * amp
|
|
122
127
|
|
|
123
128
|
for iu in range(iu_min, iu_max + 1):
|
|
124
129
|
pixel_u = (np.float32(iu) - center_u) * du
|
|
@@ -235,6 +240,12 @@ def _cone_3d_footprint_backward_kernel(
|
|
|
235
240
|
fp_v_lo = v0 - half_v
|
|
236
241
|
fp_v_hi = v0 + half_v
|
|
237
242
|
|
|
243
|
+
# Mass-conserving footprint amplitude: the output is a voxel-unit line integral
|
|
244
|
+
# averaged over the detector cell, on the same scale as the Siddon projector.
|
|
245
|
+
# A voxel of volume vs^3 spreads over (vs * t)^2 * ray_len / |denom| of detector area.
|
|
246
|
+
ray_len = math.sqrt(rx * rx + ry * ry + rz * rz)
|
|
247
|
+
amp = (voxel_spacing * voxel_spacing / (du * dv)) * t * t * ray_len * abs(inv_denom)
|
|
248
|
+
|
|
238
249
|
for iu in range(iu_min, iu_max + 1):
|
|
239
250
|
pixel_u = (np.float32(iu) - center_u) * du
|
|
240
251
|
overlap_u = min(pixel_u + _HALF * du, fp_u_hi) - max(pixel_u - _HALF * du, fp_u_lo)
|
|
@@ -247,7 +258,7 @@ def _cone_3d_footprint_backward_kernel(
|
|
|
247
258
|
if overlap_v <= eps:
|
|
248
259
|
continue
|
|
249
260
|
wv = overlap_v / width_v
|
|
250
|
-
accum += d_sino[iview, iu, iv] * wu * wv *
|
|
261
|
+
accum += d_sino[iview, iu, iv] * wu * wv * amp
|
|
251
262
|
|
|
252
263
|
d_vol[ix, iy, iz] = accum
|
|
253
264
|
|
|
@@ -359,6 +370,12 @@ def _cone_3d_footprint_backward_sparse_kernel(
|
|
|
359
370
|
fp_v_lo = v0 - half_v
|
|
360
371
|
fp_v_hi = v0 + half_v
|
|
361
372
|
|
|
373
|
+
# Mass-conserving footprint amplitude: the output is a voxel-unit line integral
|
|
374
|
+
# averaged over the detector cell, on the same scale as the Siddon projector.
|
|
375
|
+
# A voxel of volume vs^3 spreads over (vs * t)^2 * ray_len / |denom| of detector area.
|
|
376
|
+
ray_len = math.sqrt(rx * rx + ry * ry + rz * rz)
|
|
377
|
+
amp = (voxel_spacing * voxel_spacing / (du * dv)) * t * t * ray_len * abs(inv_denom)
|
|
378
|
+
|
|
362
379
|
for iu in range(iu_min, iu_max + 1):
|
|
363
380
|
pixel_u = (np.float32(iu) - center_u) * du
|
|
364
381
|
overlap_u = min(pixel_u + _HALF * du, fp_u_hi) - max(pixel_u - _HALF * du, fp_u_lo)
|
|
@@ -371,6 +388,6 @@ def _cone_3d_footprint_backward_sparse_kernel(
|
|
|
371
388
|
if overlap_v <= eps:
|
|
372
389
|
continue
|
|
373
390
|
wv = overlap_v / width_v
|
|
374
|
-
accum += d_sino[iview, iu, iv] * wu * wv *
|
|
391
|
+
accum += d_sino[iview, iu, iv] * wu * wv * amp
|
|
375
392
|
|
|
376
393
|
d_out[isample] = accum
|
diffct/kernels/fan_footprint.py
CHANGED
|
@@ -76,9 +76,10 @@ def _fan_2d_footprint_forward_kernel(
|
|
|
76
76
|
ray_len = math.sqrt(rx * rx + ry * ry)
|
|
77
77
|
if ray_len <= eps:
|
|
78
78
|
continue
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
# Mass-conserving footprint amplitude: the output is a voxel-unit line integral
|
|
80
|
+
# averaged over the detector cell, on the same scale as the Siddon projector.
|
|
81
|
+
# (local magnification t, oblique detector incidence ray_len / |denom|).
|
|
82
|
+
amp = t * ray_len / (abs(denom) * det_spacing_vox)
|
|
82
83
|
|
|
83
84
|
idet_min = int(math.floor(u0 / det_spacing_vox + center_u - support_u / det_spacing_vox))
|
|
84
85
|
idet_max = int(math.ceil(u0 / det_spacing_vox + center_u + support_u / det_spacing_vox))
|
|
@@ -89,7 +90,7 @@ def _fan_2d_footprint_forward_kernel(
|
|
|
89
90
|
|
|
90
91
|
fp_lo = u0 - half_u
|
|
91
92
|
fp_hi = u0 + half_u
|
|
92
|
-
scaled_val = val *
|
|
93
|
+
scaled_val = val * amp
|
|
93
94
|
|
|
94
95
|
for idet in range(idet_min, idet_max + 1):
|
|
95
96
|
pixel_u = (np.float32(idet) - center_u) * det_spacing_vox
|
|
@@ -160,9 +161,10 @@ def _fan_2d_footprint_backward_kernel(
|
|
|
160
161
|
ray_len = math.sqrt(rx * rx + ry * ry)
|
|
161
162
|
if ray_len <= eps:
|
|
162
163
|
continue
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
# Mass-conserving footprint amplitude: the output is a voxel-unit line integral
|
|
165
|
+
# averaged over the detector cell, on the same scale as the Siddon projector.
|
|
166
|
+
# (local magnification t, oblique detector incidence ray_len / |denom|).
|
|
167
|
+
amp = t * ray_len / (abs(denom) * det_spacing_vox)
|
|
166
168
|
|
|
167
169
|
idet_min = int(math.floor(u0 / det_spacing_vox + center_u - support_u / det_spacing_vox))
|
|
168
170
|
idet_max = int(math.ceil(u0 / det_spacing_vox + center_u + support_u / det_spacing_vox))
|
|
@@ -182,6 +184,6 @@ def _fan_2d_footprint_backward_kernel(
|
|
|
182
184
|
if overlap <= eps:
|
|
183
185
|
continue
|
|
184
186
|
weight = overlap / width_u
|
|
185
|
-
accum += d_sino[iang, idet] * weight *
|
|
187
|
+
accum += d_sino[iang, idet] * weight * amp
|
|
186
188
|
|
|
187
189
|
d_image[iy, ix] = accum
|
|
@@ -37,7 +37,6 @@ def _parallel_2d_footprint_forward_kernel(
|
|
|
37
37
|
u_vec_x = d_det_u_vec[iang, 0]
|
|
38
38
|
u_vec_y = d_det_u_vec[iang, 1]
|
|
39
39
|
|
|
40
|
-
l_phi = _ONE / max(max(abs(dir_x), abs(dir_y)), eps)
|
|
41
40
|
half_u = _HALF * (abs(u_vec_x) + abs(u_vec_y))
|
|
42
41
|
half_u = max(half_u, _HALF * det_spacing_vox)
|
|
43
42
|
width_u = max(half_u + half_u, det_spacing_vox)
|
|
@@ -63,7 +62,9 @@ def _parallel_2d_footprint_forward_kernel(
|
|
|
63
62
|
|
|
64
63
|
fp_lo = u0 - half_u
|
|
65
64
|
fp_hi = u0 + half_u
|
|
66
|
-
|
|
65
|
+
# Mass-conserving footprint amplitude: the output is a voxel-unit line integral
|
|
66
|
+
# averaged over the detector cell, on the same scale as the Siddon projector.
|
|
67
|
+
scaled_val = val / det_spacing_vox
|
|
67
68
|
|
|
68
69
|
for idet in range(idet_min, idet_max + 1):
|
|
69
70
|
pixel_u = (np.float32(idet) - center_u) * det_spacing_vox
|
|
@@ -102,7 +103,6 @@ def _parallel_2d_footprint_backward_kernel(
|
|
|
102
103
|
u_vec_x = d_det_u_vec[iang, 0]
|
|
103
104
|
u_vec_y = d_det_u_vec[iang, 1]
|
|
104
105
|
|
|
105
|
-
l_phi = _ONE / max(max(abs(dir_x), abs(dir_y)), eps)
|
|
106
106
|
half_u = _HALF * (abs(u_vec_x) + abs(u_vec_y))
|
|
107
107
|
half_u = max(half_u, _HALF * det_spacing_vox)
|
|
108
108
|
width_u = max(half_u + half_u, det_spacing_vox)
|
|
@@ -130,6 +130,6 @@ def _parallel_2d_footprint_backward_kernel(
|
|
|
130
130
|
if overlap <= eps:
|
|
131
131
|
continue
|
|
132
132
|
weight = overlap / width_u
|
|
133
|
-
accum += d_sino[iang, idet] * weight
|
|
133
|
+
accum += d_sino[iang, idet] * weight / det_spacing_vox
|
|
134
134
|
|
|
135
135
|
d_image[iy, ix] = accum
|
diffct_mlx/__init__.py
CHANGED
|
@@ -38,6 +38,8 @@ from .projectors import (
|
|
|
38
38
|
cone_backward_footprint,
|
|
39
39
|
)
|
|
40
40
|
from . import geometry
|
|
41
|
+
from . import conventions
|
|
42
|
+
from .conventions import kernel_detector_center, line_integral_scale
|
|
41
43
|
from .geometry import __all__ as _geometry_all
|
|
42
44
|
|
|
43
45
|
# Re-export trajectory generators at top level (mirrors the MLX API).
|
|
@@ -200,11 +202,14 @@ from .tv_gradients import (
|
|
|
200
202
|
awtv_gradient,
|
|
201
203
|
)
|
|
202
204
|
|
|
203
|
-
__version__ = "2.
|
|
205
|
+
__version__ = "2.3.0"
|
|
204
206
|
|
|
205
207
|
__all__ = [
|
|
206
208
|
"backend",
|
|
207
209
|
"geometry",
|
|
210
|
+
"conventions",
|
|
211
|
+
"kernel_detector_center",
|
|
212
|
+
"line_integral_scale",
|
|
208
213
|
# Projector functions
|
|
209
214
|
"parallel_forward",
|
|
210
215
|
"parallel_backward",
|
|
@@ -460,7 +460,11 @@ _CONE_3D_FOOTPRINT_FORWARD_SOURCE = """
|
|
|
460
460
|
float fp_u_hi = u0 + half_u;
|
|
461
461
|
float fp_v_lo = v0 - half_v;
|
|
462
462
|
float fp_v_hi = v0 + half_v;
|
|
463
|
-
|
|
463
|
+
// Mass-conserving footprint amplitude: voxel-unit line integral averaged over the
|
|
464
|
+
// detector cell, on the same scale as the Siddon projector.
|
|
465
|
+
float ray_len = metal::sqrt(rx * rx + ry * ry + rz * rz);
|
|
466
|
+
float amp = (voxel_spacing * voxel_spacing / (du * dv)) * t * t * ray_len * metal::abs(inv_denom);
|
|
467
|
+
float scaled_val = val * amp;
|
|
464
468
|
|
|
465
469
|
for (int iu = iu_min; iu <= iu_max; ++iu) {
|
|
466
470
|
float pixel_u = ((float)iu - center_u) * du;
|
|
@@ -617,6 +621,11 @@ _CONE_3D_FOOTPRINT_BACKWARD_SOURCE = """
|
|
|
617
621
|
float fp_v_lo = v0 - half_v;
|
|
618
622
|
float fp_v_hi = v0 + half_v;
|
|
619
623
|
|
|
624
|
+
// Mass-conserving footprint amplitude: voxel-unit line integral averaged over the
|
|
625
|
+
// detector cell, on the same scale as the Siddon projector.
|
|
626
|
+
float ray_len = metal::sqrt(rx * rx + ry * ry + rz * rz);
|
|
627
|
+
float amp = (voxel_spacing * voxel_spacing / (du * dv)) * t * t * ray_len * metal::abs(inv_denom);
|
|
628
|
+
|
|
620
629
|
for (int iu = iu_min; iu <= iu_max; ++iu) {
|
|
621
630
|
float pixel_u = ((float)iu - center_u) * du;
|
|
622
631
|
float pixel_u_lo = pixel_u - 0.5f * du;
|
|
@@ -632,7 +641,7 @@ _CONE_3D_FOOTPRINT_BACKWARD_SOURCE = """
|
|
|
632
641
|
float overlap_v = metal::min(pixel_v_hi, fp_v_hi) - metal::max(pixel_v_lo, fp_v_lo);
|
|
633
642
|
if (overlap_v <= eps) continue;
|
|
634
643
|
float wv = overlap_v / width_v;
|
|
635
|
-
accum += sino[iview * n_u * n_v + iu * n_v + iv] * wu * wv *
|
|
644
|
+
accum += sino[iview * n_u * n_v + iu * n_v + iv] * wu * wv * amp;
|
|
636
645
|
}
|
|
637
646
|
}
|
|
638
647
|
}
|
|
@@ -770,6 +779,11 @@ _CONE_3D_FOOTPRINT_BACKWARD_SPARSE_SOURCE = """
|
|
|
770
779
|
float fp_v_lo = v0 - half_v;
|
|
771
780
|
float fp_v_hi = v0 + half_v;
|
|
772
781
|
|
|
782
|
+
// Mass-conserving footprint amplitude: voxel-unit line integral averaged over the
|
|
783
|
+
// detector cell, on the same scale as the Siddon projector.
|
|
784
|
+
float ray_len = metal::sqrt(rx * rx + ry * ry + rz * rz);
|
|
785
|
+
float amp = (voxel_spacing * voxel_spacing / (du * dv)) * t * t * ray_len * metal::abs(inv_denom);
|
|
786
|
+
|
|
773
787
|
for (int iu = iu_min; iu <= iu_max; ++iu) {
|
|
774
788
|
float pixel_u = ((float)iu - center_u) * du;
|
|
775
789
|
float pixel_u_lo = pixel_u - 0.5f * du;
|
|
@@ -785,7 +799,7 @@ _CONE_3D_FOOTPRINT_BACKWARD_SPARSE_SOURCE = """
|
|
|
785
799
|
float overlap_v = metal::min(pixel_v_hi, fp_v_hi) - metal::max(pixel_v_lo, fp_v_lo);
|
|
786
800
|
if (overlap_v <= eps) continue;
|
|
787
801
|
float wv = overlap_v / width_v;
|
|
788
|
-
accum += sino[iview * n_u * n_v + iu * n_v + iv] * wu * wv *
|
|
802
|
+
accum += sino[iview * n_u * n_v + iu * n_v + iv] * wu * wv * amp;
|
|
789
803
|
}
|
|
790
804
|
}
|
|
791
805
|
}
|
|
@@ -333,9 +333,9 @@ _FAN_2D_FOOTPRINT_FORWARD_SOURCE = """
|
|
|
333
333
|
|
|
334
334
|
float ray_len = metal::sqrt(rx * rx + ry * ry);
|
|
335
335
|
if (ray_len <= eps) continue;
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
float
|
|
336
|
+
// Mass-conserving footprint amplitude: voxel-unit line integral averaged over the
|
|
337
|
+
// detector cell, on the same scale as the Siddon projector.
|
|
338
|
+
float amp = t * ray_len / (metal::abs(denom) * det_spacing_vox);
|
|
339
339
|
|
|
340
340
|
int idet_min = (int)metal::floor(u0 / det_spacing_vox + center_u - support_u / det_spacing_vox);
|
|
341
341
|
int idet_max = (int)metal::ceil(u0 / det_spacing_vox + center_u + support_u / det_spacing_vox);
|
|
@@ -344,7 +344,7 @@ _FAN_2D_FOOTPRINT_FORWARD_SOURCE = """
|
|
|
344
344
|
|
|
345
345
|
float fp_lo = u0 - half_u;
|
|
346
346
|
float fp_hi = u0 + half_u;
|
|
347
|
-
float scaled_val = val *
|
|
347
|
+
float scaled_val = val * amp;
|
|
348
348
|
|
|
349
349
|
for (int idet = idet_min; idet <= idet_max; ++idet) {
|
|
350
350
|
float pixel_u = ((float)idet - center_u) * det_spacing_vox;
|
|
@@ -431,9 +431,9 @@ _FAN_2D_FOOTPRINT_BACKWARD_SOURCE = """
|
|
|
431
431
|
|
|
432
432
|
float ray_len = metal::sqrt(rx * rx + ry * ry);
|
|
433
433
|
if (ray_len <= eps) continue;
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
float
|
|
434
|
+
// Mass-conserving footprint amplitude: voxel-unit line integral averaged over the
|
|
435
|
+
// detector cell, on the same scale as the Siddon projector.
|
|
436
|
+
float amp = t * ray_len / (metal::abs(denom) * det_spacing_vox);
|
|
437
437
|
|
|
438
438
|
int idet_min = (int)metal::floor(u0 / det_spacing_vox + center_u - support_u / det_spacing_vox);
|
|
439
439
|
int idet_max = (int)metal::ceil(u0 / det_spacing_vox + center_u + support_u / det_spacing_vox);
|
|
@@ -450,7 +450,7 @@ _FAN_2D_FOOTPRINT_BACKWARD_SOURCE = """
|
|
|
450
450
|
float overlap = metal::min(pixel_hi, fp_hi) - metal::max(pixel_lo, fp_lo);
|
|
451
451
|
if (overlap <= eps) continue;
|
|
452
452
|
float weight = overlap / width_u;
|
|
453
|
-
accum += sino[iang * n_det + idet] * weight *
|
|
453
|
+
accum += sino[iang * n_det + idet] * weight * amp;
|
|
454
454
|
}
|
|
455
455
|
}
|
|
456
456
|
|
|
@@ -274,7 +274,6 @@ _PARALLEL_2D_FOOTPRINT_FORWARD_SOURCE = """
|
|
|
274
274
|
float u_vec_x = det_u_vec[iang * 2 + 0];
|
|
275
275
|
float u_vec_y = det_u_vec[iang * 2 + 1];
|
|
276
276
|
|
|
277
|
-
float l_phi = 1.0f / metal::max(metal::max(metal::abs(dir_x), metal::abs(dir_y)), eps);
|
|
278
277
|
float half_u = 0.5f * (metal::abs(u_vec_x) + metal::abs(u_vec_y));
|
|
279
278
|
half_u = metal::max(half_u, 0.5f * det_spacing_vox);
|
|
280
279
|
float width_u = metal::max(2.0f * half_u, det_spacing_vox);
|
|
@@ -297,7 +296,9 @@ _PARALLEL_2D_FOOTPRINT_FORWARD_SOURCE = """
|
|
|
297
296
|
|
|
298
297
|
float fp_lo = u0 - half_u;
|
|
299
298
|
float fp_hi = u0 + half_u;
|
|
300
|
-
|
|
299
|
+
// Mass-conserving footprint amplitude: voxel-unit line integral averaged over the
|
|
300
|
+
// detector cell, on the same scale as the Siddon projector.
|
|
301
|
+
float scaled_val = val / det_spacing_vox;
|
|
301
302
|
|
|
302
303
|
for (int idet = idet_min; idet <= idet_max; ++idet) {
|
|
303
304
|
float pixel_u = ((float)idet - center_u) * det_spacing_vox;
|
|
@@ -352,7 +353,6 @@ _PARALLEL_2D_FOOTPRINT_BACKWARD_SOURCE = """
|
|
|
352
353
|
float u_vec_x = det_u_vec[iang * 2 + 0];
|
|
353
354
|
float u_vec_y = det_u_vec[iang * 2 + 1];
|
|
354
355
|
|
|
355
|
-
float l_phi = 1.0f / metal::max(metal::max(metal::abs(dir_x), metal::abs(dir_y)), eps);
|
|
356
356
|
float half_u = 0.5f * (metal::abs(u_vec_x) + metal::abs(u_vec_y));
|
|
357
357
|
half_u = metal::max(half_u, 0.5f * det_spacing_vox);
|
|
358
358
|
float width_u = metal::max(2.0f * half_u, det_spacing_vox);
|
|
@@ -377,7 +377,7 @@ _PARALLEL_2D_FOOTPRINT_BACKWARD_SOURCE = """
|
|
|
377
377
|
float overlap = metal::min(pixel_hi, fp_hi) - metal::max(pixel_lo, fp_lo);
|
|
378
378
|
if (overlap <= eps) continue;
|
|
379
379
|
float weight = overlap / width_u;
|
|
380
|
-
accum += sino[iang * n_det + idet] * weight
|
|
380
|
+
accum += sino[iang * n_det + idet] * weight / det_spacing_vox;
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Detector and unit conventions of the projectors, and converters between them.
|
|
2
|
+
|
|
3
|
+
The kernels on both backends (Torch/CUDA and MLX/Metal) share the conventions
|
|
4
|
+
of the upstream diffct ``dev`` line they were imported from (v1.3.3.dev0):
|
|
5
|
+
|
|
6
|
+
* **Detector pixels** — pixel ``i`` of an ``N``-pixel row sits at
|
|
7
|
+
``det_center + (i - N/2) * du * u``. ``det_center`` is therefore the centre of
|
|
8
|
+
pixel ``N/2``, half a pixel off the geometric centre of the panel
|
|
9
|
+
(``"kernel"`` convention).
|
|
10
|
+
* **Line integrals** — returned in voxel units. Multiply by ``voxel_spacing``
|
|
11
|
+
to get physical line integrals (``mu * mm``).
|
|
12
|
+
|
|
13
|
+
Upstream diffct >= 2.0.0, DiffCT-MLX 1.x and scanner geometry files instead
|
|
14
|
+
treat ``det_center`` as the geometric panel centre, with pixel ``i`` at
|
|
15
|
+
``(i - (N - 1)/2) * du`` (``"centered"`` convention), and return physical
|
|
16
|
+
line integrals. The operator factories take
|
|
17
|
+
``detector_convention=`` and ``line_integrals=`` to select either convention;
|
|
18
|
+
:func:`kernel_detector_center` does the detector conversion for direct calls
|
|
19
|
+
of the low-level projectors and the analytical FBP/FDK.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
from typing import Any
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"DETECTOR_CONVENTIONS",
|
|
28
|
+
"LINE_INTEGRAL_UNITS",
|
|
29
|
+
"kernel_detector_center",
|
|
30
|
+
"line_integral_scale",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
#: ``"kernel"``: pixel i at (i - N/2)·du (kernel native, diffct dev line).
|
|
34
|
+
#: ``"centered"``: pixel i at (i - (N-1)/2)·du (det_center = panel centre).
|
|
35
|
+
DETECTOR_CONVENTIONS = ("kernel", "centered")
|
|
36
|
+
|
|
37
|
+
#: ``"voxel"``: line integrals in voxel units (kernel native).
|
|
38
|
+
#: ``"physical"``: line integrals in the physical unit of ``voxel_spacing``.
|
|
39
|
+
LINE_INTEGRAL_UNITS = ("voxel", "physical")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _check(value: str, allowed: tuple[str, ...], name: str) -> str:
|
|
43
|
+
key = str(value).strip().lower()
|
|
44
|
+
if key not in allowed:
|
|
45
|
+
raise ValueError(f"{name} must be one of {allowed}, got {value!r}")
|
|
46
|
+
return key
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def kernel_detector_center(
|
|
50
|
+
det_center: Any,
|
|
51
|
+
det_u_vec: Any,
|
|
52
|
+
du: float,
|
|
53
|
+
det_v_vec: Any = None,
|
|
54
|
+
dv: float | None = None,
|
|
55
|
+
*,
|
|
56
|
+
convention: str = "centered",
|
|
57
|
+
) -> Any:
|
|
58
|
+
"""Return the ``det_center`` the kernels need for a given detector convention.
|
|
59
|
+
|
|
60
|
+
``det_center`` is interpreted in ``convention``. For ``"centered"`` (the
|
|
61
|
+
geometric panel centre, pixel ``i`` at ``(i - (N-1)/2)·du``) the result is
|
|
62
|
+
shifted by ``+du/2`` along ``u`` and, for a 2D detector, ``+dv/2`` along
|
|
63
|
+
``v``, so the kernels' ``(i - N/2)·du`` grid lands on the same pixel
|
|
64
|
+
centres. For ``"kernel"`` it is returned unchanged.
|
|
65
|
+
|
|
66
|
+
Works for numpy, torch and MLX arrays (plain arithmetic, autograd-safe).
|
|
67
|
+
For a parallel beam pass ``det_origin`` as ``det_center``.
|
|
68
|
+
"""
|
|
69
|
+
key = _check(convention, DETECTOR_CONVENTIONS, "detector_convention")
|
|
70
|
+
if key == "kernel":
|
|
71
|
+
return det_center
|
|
72
|
+
shifted = det_center + (0.5 * float(du)) * det_u_vec
|
|
73
|
+
if det_v_vec is not None:
|
|
74
|
+
if dv is None:
|
|
75
|
+
raise ValueError("dv is required when det_v_vec is given")
|
|
76
|
+
shifted = shifted + (0.5 * float(dv)) * det_v_vec
|
|
77
|
+
return shifted
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def line_integral_scale(line_integrals: str, voxel_spacing: float) -> float:
|
|
81
|
+
"""Factor that turns kernel output (voxel units) into ``line_integrals`` units."""
|
|
82
|
+
key = _check(line_integrals, LINE_INTEGRAL_UNITS, "line_integrals")
|
|
83
|
+
return float(voxel_spacing) if key == "physical" else 1.0
|
diffct_mlx/operators.py
CHANGED
|
@@ -32,6 +32,7 @@ from __future__ import annotations
|
|
|
32
32
|
from typing import Any, Callable, Sequence
|
|
33
33
|
|
|
34
34
|
from .backend import active as _b
|
|
35
|
+
from .conventions import _check, LINE_INTEGRAL_UNITS, kernel_detector_center, line_integral_scale
|
|
35
36
|
from .projectors import (
|
|
36
37
|
cone_backward,
|
|
37
38
|
cone_backward_footprint,
|
|
@@ -281,6 +282,7 @@ class ProjectionOperator(LinearOperator):
|
|
|
281
282
|
beam: str | None = None,
|
|
282
283
|
views: Any = None,
|
|
283
284
|
voxel_spacing: float = 1.0,
|
|
285
|
+
line_integrals: str = "voxel",
|
|
284
286
|
):
|
|
285
287
|
self._forward_fn = forward_fn
|
|
286
288
|
self._adjoint_fn = adjoint_fn
|
|
@@ -289,11 +291,16 @@ class ProjectionOperator(LinearOperator):
|
|
|
289
291
|
self.n_views = int(n_views)
|
|
290
292
|
self.beam = beam
|
|
291
293
|
self._views = views
|
|
292
|
-
#: Physical voxel pitch of the domain grid.
|
|
293
|
-
#: integrals in VOXEL units; multiply ``A @ x`` by this to obtain
|
|
294
|
-
#: physical line integrals (mu*mm) — e.g. for comparison against
|
|
295
|
-
#: measured -log data or for the physics/simulation chain.
|
|
294
|
+
#: Physical voxel pitch of the domain grid.
|
|
296
295
|
self.voxel_spacing = float(voxel_spacing)
|
|
296
|
+
#: Units of ``A @ x``: ``"voxel"`` (kernel native; multiply by
|
|
297
|
+
#: ``voxel_spacing`` for mu*mm) or ``"physical"`` (already mu*mm).
|
|
298
|
+
self.line_integrals = _check(line_integrals, LINE_INTEGRAL_UNITS, "line_integrals")
|
|
299
|
+
|
|
300
|
+
@property
|
|
301
|
+
def to_physical(self) -> float:
|
|
302
|
+
"""Factor that turns ``A @ x`` into physical line integrals (mu*mm)."""
|
|
303
|
+
return self.voxel_spacing if self.line_integrals == "voxel" else 1.0
|
|
297
304
|
|
|
298
305
|
def _forward(self, x: Array) -> Array:
|
|
299
306
|
return self._forward_fn(x, self._views)
|
|
@@ -323,6 +330,7 @@ class ProjectionOperator(LinearOperator):
|
|
|
323
330
|
beam=self.beam,
|
|
324
331
|
views=view_indices,
|
|
325
332
|
voxel_spacing=self.voxel_spacing,
|
|
333
|
+
line_integrals=self.line_integrals,
|
|
326
334
|
)
|
|
327
335
|
|
|
328
336
|
|
|
@@ -351,6 +359,10 @@ def _index(array: Array, views: Any) -> Array:
|
|
|
351
359
|
return array if views is None else array[views]
|
|
352
360
|
|
|
353
361
|
|
|
362
|
+
def _scaled(y: Array, scale: float) -> Array:
|
|
363
|
+
return y if scale == 1.0 else y * scale
|
|
364
|
+
|
|
365
|
+
|
|
354
366
|
def make_parallel_2d_operator(
|
|
355
367
|
ray_dir: Array,
|
|
356
368
|
det_origin: Array,
|
|
@@ -361,30 +373,45 @@ def make_parallel_2d_operator(
|
|
|
361
373
|
detector_spacing: float = 1.0,
|
|
362
374
|
voxel_spacing: float = 1.0,
|
|
363
375
|
projector_mode: str = "footprint",
|
|
376
|
+
detector_convention: str = "kernel",
|
|
377
|
+
line_integrals: str = "voxel",
|
|
364
378
|
) -> ProjectionOperator:
|
|
365
|
-
"""Build an all-view parallel-beam :class:`ProjectionOperator`.
|
|
379
|
+
"""Build an all-view parallel-beam :class:`ProjectionOperator`.
|
|
380
|
+
|
|
381
|
+
``detector_convention`` selects how ``det_center`` is read: ``"kernel"``
|
|
382
|
+
(default, kernel native: pixel ``i`` at ``(i - N/2)·du``) or ``"centered"``
|
|
383
|
+
(``det_center`` is the geometric panel centre: pixel ``i`` at
|
|
384
|
+
``(i - (N-1)/2)·du``, as in scanner geometry files, upstream diffct >= 2.0
|
|
385
|
+
and DiffCT-MLX 1.x). ``line_integrals`` selects the units of ``A @ x``:
|
|
386
|
+
``"voxel"`` (default) or ``"physical"`` (times ``voxel_spacing``, as in
|
|
387
|
+
upstream diffct >= 2.0 and DiffCT-MLX 1.x). ``A.T`` is scaled alike, so it stays the exact adjoint.
|
|
388
|
+
See :mod:`diffct_mlx.conventions`.
|
|
389
|
+
"""
|
|
366
390
|
ny, nx = image_shape
|
|
367
391
|
forward_op, backward_op = _select_pair("parallel", projector_mode)
|
|
392
|
+
scale = line_integral_scale(line_integrals, voxel_spacing)
|
|
368
393
|
ray_dir = xp.array(ray_dir)
|
|
369
|
-
det_origin = xp.array(det_origin)
|
|
370
394
|
det_u_vec = xp.array(det_u_vec)
|
|
395
|
+
det_origin = kernel_detector_center(
|
|
396
|
+
xp.array(det_origin), det_u_vec, detector_spacing, convention=detector_convention)
|
|
371
397
|
n_views = int(ray_dir.shape[0])
|
|
372
398
|
|
|
373
399
|
def fwd(volume: Array, views: Any) -> Array:
|
|
374
|
-
return forward_op(
|
|
400
|
+
return _scaled(forward_op(
|
|
375
401
|
volume, _index(ray_dir, views), _index(det_origin, views), _index(det_u_vec, views),
|
|
376
402
|
num_detectors=num_detectors, detector_spacing=detector_spacing, voxel_spacing=voxel_spacing,
|
|
377
|
-
)
|
|
403
|
+
), scale)
|
|
378
404
|
|
|
379
405
|
def adj(sino: Array, views: Any) -> Array:
|
|
380
|
-
return backward_op(
|
|
406
|
+
return _scaled(backward_op(
|
|
381
407
|
xp.array(sino, dtype=xp.float32), _index(ray_dir, views), _index(det_origin, views), _index(det_u_vec, views),
|
|
382
408
|
detector_spacing=detector_spacing, H=ny, W=nx, voxel_spacing=voxel_spacing,
|
|
383
|
-
)
|
|
409
|
+
), scale)
|
|
384
410
|
|
|
385
411
|
return ProjectionOperator(
|
|
386
412
|
fwd, adj, domain_shape=(ny, nx), range_shape=(n_views, num_detectors),
|
|
387
413
|
n_views=n_views, beam="parallel", voxel_spacing=voxel_spacing,
|
|
414
|
+
line_integrals=line_integrals,
|
|
388
415
|
)
|
|
389
416
|
|
|
390
417
|
|
|
@@ -398,30 +425,45 @@ def make_fan_2d_operator(
|
|
|
398
425
|
detector_spacing: float = 1.0,
|
|
399
426
|
voxel_spacing: float = 1.0,
|
|
400
427
|
projector_mode: str = "footprint",
|
|
428
|
+
detector_convention: str = "kernel",
|
|
429
|
+
line_integrals: str = "voxel",
|
|
401
430
|
) -> ProjectionOperator:
|
|
402
|
-
"""Build an all-view fan-beam :class:`ProjectionOperator`.
|
|
431
|
+
"""Build an all-view fan-beam :class:`ProjectionOperator`.
|
|
432
|
+
|
|
433
|
+
``detector_convention`` selects how ``det_center`` is read: ``"kernel"``
|
|
434
|
+
(default, kernel native: pixel ``i`` at ``(i - N/2)·du``) or ``"centered"``
|
|
435
|
+
(``det_center`` is the geometric panel centre: pixel ``i`` at
|
|
436
|
+
``(i - (N-1)/2)·du``, as in scanner geometry files, upstream diffct >= 2.0
|
|
437
|
+
and DiffCT-MLX 1.x). ``line_integrals`` selects the units of ``A @ x``:
|
|
438
|
+
``"voxel"`` (default) or ``"physical"`` (times ``voxel_spacing``, as in
|
|
439
|
+
upstream diffct >= 2.0 and DiffCT-MLX 1.x). ``A.T`` is scaled alike, so it stays the exact adjoint.
|
|
440
|
+
See :mod:`diffct_mlx.conventions`.
|
|
441
|
+
"""
|
|
403
442
|
ny, nx = image_shape
|
|
404
443
|
forward_op, backward_op = _select_pair("fan", projector_mode)
|
|
444
|
+
scale = line_integral_scale(line_integrals, voxel_spacing)
|
|
405
445
|
src_pos = xp.array(src_pos)
|
|
406
|
-
det_center = xp.array(det_center)
|
|
407
446
|
det_u_vec = xp.array(det_u_vec)
|
|
447
|
+
det_center = kernel_detector_center(
|
|
448
|
+
xp.array(det_center), det_u_vec, detector_spacing, convention=detector_convention)
|
|
408
449
|
n_views = int(src_pos.shape[0])
|
|
409
450
|
|
|
410
451
|
def fwd(volume: Array, views: Any) -> Array:
|
|
411
|
-
return forward_op(
|
|
452
|
+
return _scaled(forward_op(
|
|
412
453
|
volume, _index(src_pos, views), _index(det_center, views), _index(det_u_vec, views),
|
|
413
454
|
num_detectors=num_detectors, detector_spacing=detector_spacing, voxel_spacing=voxel_spacing,
|
|
414
|
-
)
|
|
455
|
+
), scale)
|
|
415
456
|
|
|
416
457
|
def adj(sino: Array, views: Any) -> Array:
|
|
417
|
-
return backward_op(
|
|
458
|
+
return _scaled(backward_op(
|
|
418
459
|
xp.array(sino, dtype=xp.float32), _index(src_pos, views), _index(det_center, views), _index(det_u_vec, views),
|
|
419
460
|
detector_spacing=detector_spacing, H=ny, W=nx, voxel_spacing=voxel_spacing,
|
|
420
|
-
)
|
|
461
|
+
), scale)
|
|
421
462
|
|
|
422
463
|
return ProjectionOperator(
|
|
423
464
|
fwd, adj, domain_shape=(ny, nx), range_shape=(n_views, num_detectors),
|
|
424
465
|
n_views=n_views, beam="fan", voxel_spacing=voxel_spacing,
|
|
466
|
+
line_integrals=line_integrals,
|
|
425
467
|
)
|
|
426
468
|
|
|
427
469
|
|
|
@@ -437,32 +479,48 @@ def make_cone_3d_operator(
|
|
|
437
479
|
dv: float = 1.0,
|
|
438
480
|
voxel_spacing: float = 1.0,
|
|
439
481
|
projector_mode: str = "footprint",
|
|
482
|
+
detector_convention: str = "kernel",
|
|
483
|
+
line_integrals: str = "voxel",
|
|
440
484
|
) -> ProjectionOperator:
|
|
441
|
-
"""Build an all-view cone-beam :class:`ProjectionOperator`.
|
|
485
|
+
"""Build an all-view cone-beam :class:`ProjectionOperator`.
|
|
486
|
+
|
|
487
|
+
``detector_convention`` selects how ``det_center`` is read: ``"kernel"``
|
|
488
|
+
(default, kernel native: pixel ``i`` at ``(i - N/2)·du``) or ``"centered"``
|
|
489
|
+
(``det_center`` is the geometric panel centre: pixel ``i`` at
|
|
490
|
+
``(i - (N-1)/2)·du``, as in scanner geometry files, upstream diffct >= 2.0
|
|
491
|
+
and DiffCT-MLX 1.x). ``line_integrals`` selects the units of ``A @ x``:
|
|
492
|
+
``"voxel"`` (default) or ``"physical"`` (times ``voxel_spacing``, as in
|
|
493
|
+
upstream diffct >= 2.0 and DiffCT-MLX 1.x). ``A.T`` is scaled alike, so it stays the exact adjoint.
|
|
494
|
+
See :mod:`diffct_mlx.conventions`.
|
|
495
|
+
"""
|
|
442
496
|
nz, ny, nx = volume_shape
|
|
443
497
|
det_u_count, det_v_count = detector_shape
|
|
444
498
|
forward_op, backward_op = _select_pair("cone", projector_mode)
|
|
499
|
+
scale = line_integral_scale(line_integrals, voxel_spacing)
|
|
445
500
|
src_pos = xp.array(src_pos)
|
|
446
|
-
det_center = xp.array(det_center)
|
|
447
501
|
det_u_vec = xp.array(det_u_vec)
|
|
448
502
|
det_v_vec = xp.array(det_v_vec)
|
|
503
|
+
det_center = kernel_detector_center(
|
|
504
|
+
xp.array(det_center), det_u_vec, du, det_v_vec, dv, convention=detector_convention)
|
|
449
505
|
n_views = int(src_pos.shape[0])
|
|
450
506
|
|
|
451
507
|
def fwd(volume: Array, views: Any) -> Array:
|
|
452
|
-
return forward_op(
|
|
508
|
+
return _scaled(forward_op(
|
|
453
509
|
volume, _index(src_pos, views), _index(det_center, views),
|
|
454
510
|
_index(det_u_vec, views), _index(det_v_vec, views),
|
|
455
511
|
det_u=det_u_count, det_v=det_v_count, du=du, dv=dv, voxel_spacing=voxel_spacing,
|
|
456
|
-
)
|
|
512
|
+
), scale)
|
|
457
513
|
|
|
458
514
|
def adj(sino: Array, views: Any) -> Array:
|
|
459
|
-
return backward_op(
|
|
515
|
+
return _scaled(backward_op(
|
|
460
516
|
xp.array(sino, dtype=xp.float32), _index(src_pos, views), _index(det_center, views),
|
|
461
517
|
_index(det_u_vec, views), _index(det_v_vec, views),
|
|
462
518
|
D=nz, H=ny, W=nx, du=du, dv=dv, voxel_spacing=voxel_spacing,
|
|
463
|
-
)
|
|
519
|
+
), scale)
|
|
464
520
|
|
|
465
521
|
return ProjectionOperator(
|
|
466
522
|
fwd, adj, domain_shape=(nz, ny, nx), range_shape=(n_views, det_u_count, det_v_count),
|
|
467
523
|
n_views=n_views, beam="cone", voxel_spacing=voxel_spacing,
|
|
524
|
+
line_integrals=line_integrals,
|
|
468
525
|
)
|
|
526
|
+
|
diffct_mlx/physics/simulate.py
CHANGED
|
@@ -272,7 +272,8 @@ def simulate_scan(
|
|
|
272
272
|
The projectors return line integrals in VOXEL units; the physics
|
|
273
273
|
(``exp(-p)`` transmission, beam-hardening nonlinearity) needs PHYSICAL
|
|
274
274
|
line integrals, so the projection is rescaled by ``voxel_spacing`` first
|
|
275
|
-
(taken from the operator's metadata when not given
|
|
275
|
+
(taken from the operator's metadata when not given; an operator built
|
|
276
|
+
with ``line_integrals="physical"`` is used as is). The returned
|
|
276
277
|
sinogram is therefore physical (mu*mm) — like real measured -log data —
|
|
277
278
|
and identical to previous behaviour at ``voxel_spacing = 1``.
|
|
278
279
|
|
|
@@ -282,7 +283,11 @@ def simulate_scan(
|
|
|
282
283
|
if float(I0) <= 0.0:
|
|
283
284
|
raise ValueError(f"I0 (incident photon count) must be positive, got {I0!r}.")
|
|
284
285
|
if voxel_spacing is None:
|
|
285
|
-
|
|
286
|
+
# operator metadata: voxel-unit operators need * voxel_spacing,
|
|
287
|
+
# operators built with line_integrals="physical" are already mu*mm
|
|
288
|
+
voxel_spacing = getattr(operator, "to_physical", None)
|
|
289
|
+
if voxel_spacing is None:
|
|
290
|
+
voxel_spacing = float(getattr(operator, "voxel_spacing", 1.0))
|
|
286
291
|
if float(voxel_spacing) <= 0.0:
|
|
287
292
|
raise ValueError(f"voxel_spacing must be positive, got {voxel_spacing!r}.")
|
|
288
293
|
x = xp.array(phantom, dtype=_b.float32)
|
|
@@ -11,6 +11,7 @@ from typing import Any, Callable
|
|
|
11
11
|
import numpy as np
|
|
12
12
|
|
|
13
13
|
from ..backend import active as _b
|
|
14
|
+
from ..conventions import kernel_detector_center, line_integral_scale
|
|
14
15
|
|
|
15
16
|
xp = _b.xp
|
|
16
17
|
|
|
@@ -249,6 +250,32 @@ def _build_leap_style_circular_fov_mask(
|
|
|
249
250
|
return np.broadcast_to(radial_keep[None, :, :], (nz, ny, nx)).astype(bool, copy=False)
|
|
250
251
|
|
|
251
252
|
|
|
253
|
+
|
|
254
|
+
def _finish_operators(forward_single, forward_slice, back_single, back_slice, back_project_all, scale):
|
|
255
|
+
"""Attach ``project_slice`` and apply the line-integral unit scale."""
|
|
256
|
+
if scale != 1.0:
|
|
257
|
+
fs, fsl, bs, bsl, ball = forward_single, forward_slice, back_single, back_slice, back_project_all
|
|
258
|
+
|
|
259
|
+
def forward_single(volume, projection_index):
|
|
260
|
+
return fs(volume, projection_index) * scale
|
|
261
|
+
|
|
262
|
+
def forward_slice(volume, start, stop):
|
|
263
|
+
return fsl(volume, start, stop) * scale
|
|
264
|
+
|
|
265
|
+
def back_single(projection, projection_index):
|
|
266
|
+
return bs(projection, projection_index) * scale
|
|
267
|
+
|
|
268
|
+
def back_slice(projection, start, stop):
|
|
269
|
+
return bsl(projection, start, stop) * scale
|
|
270
|
+
|
|
271
|
+
def back_project_all(filtered_sinogram):
|
|
272
|
+
return ball(filtered_sinogram) * scale
|
|
273
|
+
|
|
274
|
+
forward_single.project_slice = forward_slice # type: ignore[attr-defined]
|
|
275
|
+
back_single.project_slice = back_slice # type: ignore[attr-defined]
|
|
276
|
+
return forward_single, back_single, back_project_all
|
|
277
|
+
|
|
278
|
+
|
|
252
279
|
def make_parallel_2d_operators(
|
|
253
280
|
ray_dir: Array,
|
|
254
281
|
det_origin: Array,
|
|
@@ -259,8 +286,19 @@ def make_parallel_2d_operators(
|
|
|
259
286
|
detector_spacing: float = 1.0,
|
|
260
287
|
voxel_spacing: float = 1.0,
|
|
261
288
|
projector_mode: str = "footprint",
|
|
289
|
+
detector_convention: str = "kernel",
|
|
290
|
+
line_integrals: str = "voxel",
|
|
262
291
|
) -> tuple[Callable[[Array, int], Array], Callable[[Array, int], Array], Callable[[Array], Array]]:
|
|
263
|
-
"""Create single-view and all-view parallel-beam projector wrappers.
|
|
292
|
+
"""Create single-view and all-view parallel-beam projector wrappers.
|
|
293
|
+
|
|
294
|
+
``detector_convention`` and ``line_integrals`` select the detector-pixel
|
|
295
|
+
and line-integral conventions; see
|
|
296
|
+
:func:`diffct_mlx.operators.make_cone_3d_operator` and
|
|
297
|
+
:mod:`diffct_mlx.conventions`. Defaults keep the kernel-native behaviour.
|
|
298
|
+
"""
|
|
299
|
+
det_origin = kernel_detector_center(
|
|
300
|
+
det_origin, det_u_vec, detector_spacing, convention=detector_convention)
|
|
301
|
+
scale = line_integral_scale(line_integrals, voxel_spacing)
|
|
264
302
|
ny, nx = image_shape
|
|
265
303
|
projector_key = str(projector_mode).strip().lower()
|
|
266
304
|
if projector_key == "siddon":
|
|
@@ -330,9 +368,9 @@ def make_parallel_2d_operators(
|
|
|
330
368
|
voxel_spacing=voxel_spacing,
|
|
331
369
|
)
|
|
332
370
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
371
|
+
return _finish_operators(
|
|
372
|
+
forward_single, forward_slice, back_single, back_slice, back_project_all, scale
|
|
373
|
+
)
|
|
336
374
|
|
|
337
375
|
|
|
338
376
|
def make_fan_2d_operators(
|
|
@@ -345,8 +383,19 @@ def make_fan_2d_operators(
|
|
|
345
383
|
detector_spacing: float = 1.0,
|
|
346
384
|
voxel_spacing: float = 1.0,
|
|
347
385
|
projector_mode: str = "footprint",
|
|
386
|
+
detector_convention: str = "kernel",
|
|
387
|
+
line_integrals: str = "voxel",
|
|
348
388
|
) -> tuple[Callable[[Array, int], Array], Callable[[Array, int], Array], Callable[[Array], Array]]:
|
|
349
|
-
"""Create single-view and all-view fan-beam projector wrappers.
|
|
389
|
+
"""Create single-view and all-view fan-beam projector wrappers.
|
|
390
|
+
|
|
391
|
+
``detector_convention`` and ``line_integrals`` select the detector-pixel
|
|
392
|
+
and line-integral conventions; see
|
|
393
|
+
:func:`diffct_mlx.operators.make_cone_3d_operator` and
|
|
394
|
+
:mod:`diffct_mlx.conventions`. Defaults keep the kernel-native behaviour.
|
|
395
|
+
"""
|
|
396
|
+
det_center = kernel_detector_center(
|
|
397
|
+
det_center, det_u_vec, detector_spacing, convention=detector_convention)
|
|
398
|
+
scale = line_integral_scale(line_integrals, voxel_spacing)
|
|
350
399
|
ny, nx = image_shape
|
|
351
400
|
projector_key = str(projector_mode).strip().lower()
|
|
352
401
|
if projector_key == "siddon":
|
|
@@ -416,9 +465,9 @@ def make_fan_2d_operators(
|
|
|
416
465
|
voxel_spacing=voxel_spacing,
|
|
417
466
|
)
|
|
418
467
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
468
|
+
return _finish_operators(
|
|
469
|
+
forward_single, forward_slice, back_single, back_slice, back_project_all, scale
|
|
470
|
+
)
|
|
422
471
|
|
|
423
472
|
|
|
424
473
|
def make_cone_3d_operators(
|
|
@@ -433,8 +482,19 @@ def make_cone_3d_operators(
|
|
|
433
482
|
dv: float = 1.0,
|
|
434
483
|
voxel_spacing: float = 1.0,
|
|
435
484
|
projector_mode: str = "footprint",
|
|
485
|
+
detector_convention: str = "kernel",
|
|
486
|
+
line_integrals: str = "voxel",
|
|
436
487
|
) -> tuple[Callable[[Array, int], Array], Callable[[Array, int], Array], Callable[[Array], Array]]:
|
|
437
|
-
"""Create single-view and all-view cone-beam projector wrappers.
|
|
488
|
+
"""Create single-view and all-view cone-beam projector wrappers.
|
|
489
|
+
|
|
490
|
+
``detector_convention`` and ``line_integrals`` select the detector-pixel
|
|
491
|
+
and line-integral conventions; see
|
|
492
|
+
:func:`diffct_mlx.operators.make_cone_3d_operator` and
|
|
493
|
+
:mod:`diffct_mlx.conventions`. Defaults keep the kernel-native behaviour.
|
|
494
|
+
"""
|
|
495
|
+
det_center = kernel_detector_center(
|
|
496
|
+
det_center, det_u_vec, du, det_v_vec, dv, convention=detector_convention)
|
|
497
|
+
scale = line_integral_scale(line_integrals, voxel_spacing)
|
|
438
498
|
nz, ny, nx = volume_shape
|
|
439
499
|
det_u_count, det_v_count = detector_shape
|
|
440
500
|
projector_key = str(projector_mode).strip().lower()
|
|
@@ -520,9 +580,9 @@ def make_cone_3d_operators(
|
|
|
520
580
|
voxel_spacing=voxel_spacing,
|
|
521
581
|
)
|
|
522
582
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
583
|
+
return _finish_operators(
|
|
584
|
+
forward_single, forward_slice, back_single, back_slice, back_project_all, scale
|
|
585
|
+
)
|
|
526
586
|
|
|
527
587
|
|
|
528
588
|
def _quantitative_fdk_operators(src_pos, det_center, det_u_vec, det_v_vec,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: diffct-mlx
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.0
|
|
4
4
|
Summary: Differentiable computed tomography with an auto-selecting backend (Torch/CUDA or Apple MLX)
|
|
5
5
|
Project-URL: Homepage, https://github.com/Linda-SophieSchneider/DiffCT-MLX
|
|
6
6
|
Project-URL: Upstream, https://github.com/sypsyp97/diffct
|
|
@@ -16,6 +16,7 @@ Requires-Python: >=3.9
|
|
|
16
16
|
Requires-Dist: numpy
|
|
17
17
|
Provides-Extra: cuda
|
|
18
18
|
Requires-Dist: numba-cuda; extra == 'cuda'
|
|
19
|
+
Requires-Dist: numpy<2.5; extra == 'cuda'
|
|
19
20
|
Requires-Dist: torch; extra == 'cuda'
|
|
20
21
|
Provides-Extra: mlx
|
|
21
22
|
Requires-Dist: mlx; extra == 'mlx'
|
|
@@ -145,7 +146,10 @@ filter itself now accepts `pad_factor` and `sample_spacing`, and
|
|
|
145
146
|
`FBPParameters`/`FDKParameters` default to `pad_factor=2`.
|
|
146
147
|
|
|
147
148
|
> **Unit convention.** The projectors integrate in **voxel units**: physical
|
|
148
|
-
> line integrals are `(A @ x) * voxel_spacing`.
|
|
149
|
+
> line integrals are `(A @ x) * voxel_spacing`. This holds for both projector
|
|
150
|
+
> modes: since 2.2.0 the footprint kernels are mass-conserving and agree with
|
|
151
|
+
> the Siddon kernels in amplitude (earlier versions scaled footprint output
|
|
152
|
+
> with the detector-cell-to-voxel size ratio). Operators built via
|
|
149
153
|
> `make_*_operator` carry `A.voxel_spacing` as metadata, and the boundaries
|
|
150
154
|
> where physical units matter handle the conversion automatically —
|
|
151
155
|
> `simulate_scan` rescales before the `exp(-p)` / beam-hardening physics (and
|
|
@@ -153,6 +157,17 @@ filter itself now accepts `pad_factor` and `sample_spacing`, and
|
|
|
153
157
|
> encodes it per data source. One consequence to know: **iterative**
|
|
154
158
|
> reconstruction of measured (physical) data converges to attenuation *per
|
|
155
159
|
> voxel*; divide by `case.voxel_spacing` for µ in 1/mm.
|
|
160
|
+
>
|
|
161
|
+
> **Detector convention.** The kernels place detector pixel `i` at
|
|
162
|
+
> `det_center + (i − N/2)·du` (the diffct `dev` line they come from), half a
|
|
163
|
+
> pixel off the geometric panel centre. Upstream diffct ≥ 2.0, DiffCT-MLX 1.x
|
|
164
|
+
> and scanner geometry files use `(i − (N−1)/2)·du` and physical line
|
|
165
|
+
> integrals. To work in that convention, build operators with
|
|
166
|
+
> `detector_convention="centered", line_integrals="physical"`
|
|
167
|
+
> (`make_*_operator` and `make_*_operators`); `A.T` scales alike and stays
|
|
168
|
+
> the exact adjoint, and reconstructions then come out in 1/mm. For direct
|
|
169
|
+
> projector or FBP/FDK calls, `dct.kernel_detector_center(...)` converts a
|
|
170
|
+
> panel-centre `det_center` (shift by `+du/2·u + dv/2·v`).
|
|
156
171
|
|
|
157
172
|
### Operators, solvers, regularizers, physics & simulation
|
|
158
173
|
|
|
@@ -8,18 +8,19 @@ diffct/projectors.py,sha256=tbrwCcsW-tMWK4qbcYMueqIC4gjUPUj88Zb2PorClZI,52223
|
|
|
8
8
|
diffct/utils.py,sha256=qFFjB3mlyHHO-LIzNvcS7OuZ10HDq1S5D2hsabhExgM,9819
|
|
9
9
|
diffct/kernels/__init__.py,sha256=KiMSQmDBtg91Duufi5M7D_XMVQeMptJxVjxrQWS6Q4A,932
|
|
10
10
|
diffct/kernels/cone_beam.py,sha256=Oxsw0GxFdqKOmO0kYFMwUhRdReQJOLJfDyFEJw2fSww,32554
|
|
11
|
-
diffct/kernels/cone_footprint.py,sha256=
|
|
11
|
+
diffct/kernels/cone_footprint.py,sha256=FfI_snSSsJF5ebMmFsglnVJ-1FnHemnYyFUa2LWAY5g,14790
|
|
12
12
|
diffct/kernels/fan_beam.py,sha256=-3cIoGsxc9mIw9CyjKjTd0cSt9qvTg8EVWAnPHRQaFU,15367
|
|
13
|
-
diffct/kernels/fan_footprint.py,sha256=
|
|
13
|
+
diffct/kernels/fan_footprint.py,sha256=o_hw-Z8Z92KR0Ssiam8-HktIZwm7beowpSsqdIwAgvo,6603
|
|
14
14
|
diffct/kernels/parallel_beam.py,sha256=yfueBtQmdaQqQ5f9Zl7m0oHAGIEJ6vnjcaQEGLARV5U,15368
|
|
15
|
-
diffct/kernels/parallel_footprint.py,sha256=
|
|
16
|
-
diffct_mlx/__init__.py,sha256=
|
|
15
|
+
diffct/kernels/parallel_footprint.py,sha256=rK6BpJdWlqgR_cARyyMsi6dgNJxHvyMkKuHP6H96xVA,4868
|
|
16
|
+
diffct_mlx/__init__.py,sha256=GqxI2ozgbEcbR7wqfyG37xEji-NVsOCRqYgnfMRlOfc,9479
|
|
17
17
|
diffct_mlx/analytical.py,sha256=PeSErFI7iPzADcjIm4eSjHVWUdQWZW4y_PgaCXe04YA,775
|
|
18
18
|
diffct_mlx/calibration.py,sha256=ey7enNTnwIr_8KvgSoVTWpLjCmvvvTkYGrk4tqw1iT8,4941
|
|
19
|
+
diffct_mlx/conventions.py,sha256=Z5RFODoqF4Vjuis-jFiWR31Ruosi2Mw8CBv3Mr0zh_I,3361
|
|
19
20
|
diffct_mlx/filters.py,sha256=qVLbbfZ4GKO62su0pkK9AxyLyw8ME_nJ87CtvjgQF8s,13810
|
|
20
21
|
diffct_mlx/functionals.py,sha256=rwHu2wxjRBael1kSJJjFFU4GDqDO8jZiyq5AU5JY6t0,9185
|
|
21
22
|
diffct_mlx/geometry.py,sha256=_iSSXJDTs18KysM7vV2aFWbKkdP653LqplMwQ7tHGbs,7998
|
|
22
|
-
diffct_mlx/operators.py,sha256=
|
|
23
|
+
diffct_mlx/operators.py,sha256=GEEY_b4Yn6FPCUHiHokps0Hbed5t_S7kLjKLd9c7lH8,19548
|
|
23
24
|
diffct_mlx/projectors.py,sha256=IzzZILzHFzPCQNn8Q-x7N5Soeas3PeK7612ERYtnH9U,3308
|
|
24
25
|
diffct_mlx/real_measured_data_helper.py,sha256=ave4mnbvtGX4ZrPrE8Ut5JwbXpYi9CbFiZVyGmaHREQ,21610
|
|
25
26
|
diffct_mlx/rebinning.py,sha256=dWdznfkUelteohk2G3kV8BERhhLzw8RSD3gsoKWOgM8,15802
|
|
@@ -34,9 +35,9 @@ diffct_mlx/backend/metal/geometry.py,sha256=1DfvS5xsb9B7uppXSwY_yrY2KQm6jH3LTU_W
|
|
|
34
35
|
diffct_mlx/backend/metal/projectors.py,sha256=yj8xJc1gz7clkTkG8hIevglDbNIl17uBaSWK0YNVg70,40969
|
|
35
36
|
diffct_mlx/backend/metal/utils.py,sha256=5QHUR1aB0cZEIKMp5Owh5Np8jMdQAlqLH_88R_DoRHk,1620
|
|
36
37
|
diffct_mlx/backend/metal/kernels/__init__.py,sha256=WjAyLbIqGPJzZLdXU6dgN8Et-JveYGcYi569OFRSUig,1295
|
|
37
|
-
diffct_mlx/backend/metal/kernels/cone_beam.py,sha256=
|
|
38
|
-
diffct_mlx/backend/metal/kernels/fan_beam.py,sha256=
|
|
39
|
-
diffct_mlx/backend/metal/kernels/parallel_beam.py,sha256=
|
|
38
|
+
diffct_mlx/backend/metal/kernels/cone_beam.py,sha256=alZZ4K5bsWRr09uw_P7ocg7EhfowI_WjMlFvgiCydcM,42702
|
|
39
|
+
diffct_mlx/backend/metal/kernels/fan_beam.py,sha256=bZ2iGBNfDsFXv309-hq1JckmuwG7PFgsgyl_psk7Rq0,16848
|
|
40
|
+
diffct_mlx/backend/metal/kernels/parallel_beam.py,sha256=OWo2HhNSIL3xURVIGpQ3zLTWZPrbbN6RxH8I9CcPHHk,14325
|
|
40
41
|
diffct_mlx/orchestration/__init__.py,sha256=wdtvwS6h8WhTfFIJnmVtDL0XCh6XiQ4Sz8d4ysbnmkY,1225
|
|
41
42
|
diffct_mlx/orchestration/out_of_core.py,sha256=Alzx9QH_bCTM0kkG0hRhencMCstpk-UPK4O0m5w0EYg,49510
|
|
42
43
|
diffct_mlx/phantoms/__init__.py,sha256=sGCCVKStcPuyr-MKIedEVdkqT6v0uHFNNoWfeXiYtQ4,296
|
|
@@ -45,7 +46,7 @@ diffct_mlx/phantoms/shepp_logan.py,sha256=UYgWehw_elB5aEuqXrZkc0AtS7CFnolejrhkID
|
|
|
45
46
|
diffct_mlx/physics/__init__.py,sha256=_oUFXO1Kw7zO58jFXUts6vLxhBitGKCObJyoPVnmDPg,2041
|
|
46
47
|
diffct_mlx/physics/corrections.py,sha256=6CA6iYgggUVQYHJgV8tyJSIirsWaz9lNCWy0X9m1jps,7260
|
|
47
48
|
diffct_mlx/physics/pipeline.py,sha256=FYOSZAue6xSMwzAycD5N69DmBMbD3pcBt3b94w2yeVU,4463
|
|
48
|
-
diffct_mlx/physics/simulate.py,sha256=
|
|
49
|
+
diffct_mlx/physics/simulate.py,sha256=ZeRbkMDwpUGYpQqbowueD4CGCj-wcXOgWzgGK1TgnjY,13391
|
|
49
50
|
diffct_mlx/physics/spectra.py,sha256=PPoZkt8L16hj_BLeJRlu0OM9HP7RoIZjCyL4pvBn8OE,5718
|
|
50
51
|
diffct_mlx/physics/data/spectra.npz,sha256=Aai7GHcalwD0xzyjSQ6S9bcvBwxKg0ZnsaPIjLzN1H0,16764
|
|
51
52
|
diffct_mlx/reconstruction_algorithms/__init__.py,sha256=7_4HgPf0NICmIM_RpeDs7iXvSeswQc7yw_afzjDweMY,3773
|
|
@@ -54,7 +55,7 @@ diffct_mlx/reconstruction_algorithms/_core.py,sha256=eRp4RB6PIKXe4ASgyJRbHb5TFig
|
|
|
54
55
|
diffct_mlx/reconstruction_algorithms/_solver.py,sha256=K29fsM1Q5KCR1SU9lDBIVpKWh1mCpS1br6IZTto2ZbQ,6557
|
|
55
56
|
diffct_mlx/reconstruction_algorithms/asd_pocs.py,sha256=c0VOY5rD2nf5bmJvgpErERZbfNTsOqXfmP6Jk053d_o,3639
|
|
56
57
|
diffct_mlx/reconstruction_algorithms/awtv_pocs.py,sha256=tJ5-ywA0IvwwxXDbcBDAzLUzOHR_x3RfGSsz034LVWo,3571
|
|
57
|
-
diffct_mlx/reconstruction_algorithms/cases.py,sha256=
|
|
58
|
+
diffct_mlx/reconstruction_algorithms/cases.py,sha256=jOFiDnZTlaYbtEf1VsCHPyj9PWjjeRpVrEDpjATaYCA,47928
|
|
58
59
|
diffct_mlx/reconstruction_algorithms/dart.py,sha256=hFqRLOogUaQYS2Gmjkq3kyKl6QcKlhKhm3OGH-8nAAA,17352
|
|
59
60
|
diffct_mlx/reconstruction_algorithms/fbp.py,sha256=LR2DcfSL-D2xB_XPkC9LjQVbz3w3Pf3VKPm9APJnPg8,2372
|
|
60
61
|
diffct_mlx/reconstruction_algorithms/fdk.py,sha256=2P_Uj0dwCli-uzPYT_OU4wZwe4CFbyNRhZIejGl-z88,2395
|
|
@@ -62,7 +63,7 @@ diffct_mlx/reconstruction_algorithms/sart.py,sha256=-v8cQplbprjJe9tZkFRaXcKk-2Na
|
|
|
62
63
|
diffct_mlx/reconstruction_algorithms/sirt.py,sha256=uMEVwXkozviUZt1hVE09rjX7nJJfN-6DM3vgfJwAAm0,1953
|
|
63
64
|
diffct_mlx/reconstruction_algorithms/solvers.py,sha256=ciGzkNfGVphCkBOlxOPXYhy76Z0HI9gOEh4hWmKgynw,14368
|
|
64
65
|
diffct_mlx/reconstruction_algorithms/tv_pocs.py,sha256=VJGvdtfYBQ4xToIRTPdrj_4YrioPnv8hSTtSC9GoGxE,2772
|
|
65
|
-
diffct_mlx-2.
|
|
66
|
-
diffct_mlx-2.
|
|
67
|
-
diffct_mlx-2.
|
|
68
|
-
diffct_mlx-2.
|
|
66
|
+
diffct_mlx-2.3.0.dist-info/METADATA,sha256=WIBLeZNlRQMHrKtqW4VdeYAIczI5nbCf7lFaLcitL8I,26591
|
|
67
|
+
diffct_mlx-2.3.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
68
|
+
diffct_mlx-2.3.0.dist-info/licenses/LICENSE,sha256=a1fjzGs44LpDnV_LmA2Tzp8z-eJKoNVVdLOnh-F6J6E,11344
|
|
69
|
+
diffct_mlx-2.3.0.dist-info/RECORD,,
|
|
File without changes
|