diffct-mlx 2.0.1__tar.gz → 2.2.0__tar.gz
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-2.0.1 → diffct_mlx-2.2.0}/.github/workflows/publish.yml +3 -2
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/CHANGELOG.md +118 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/PKG-INFO +61 -26
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/README.md +59 -24
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/kernels/cone_footprint.py +20 -3
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/kernels/fan_footprint.py +10 -8
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/kernels/parallel_footprint.py +4 -4
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/__init__.py +3 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/backend/metal/kernels/cone_beam.py +17 -3
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/backend/metal/kernels/fan_beam.py +8 -8
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/backend/metal/kernels/parallel_beam.py +4 -4
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/operators.py +10 -3
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/physics/simulate.py +14 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/__init__.py +2 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/_analytic.py +64 -22
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/cases.py +152 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/fbp.py +3 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/fdk.py +3 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/docs/source/api.rst +16 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/docs/source/conf.py +1 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/docs/source/getting_started.rst +14 -3
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/docs/source/index.rst +14 -12
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/pyproject.toml +1 -1
- diffct_mlx-2.2.0/tests/test_footprint_amplitude.py +150 -0
- diffct_mlx-2.2.0/tests/test_quantitative_fdk.py +200 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/.github/workflows/docs.yml +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/.github/workflows/release.yml +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/.gitignore +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/ATTRIBUTION.md +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/LICENSE +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/analytical.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/constants.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/differentiable.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/footprint.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/geometry.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/kernels/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/kernels/cone_beam.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/kernels/fan_beam.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/kernels/parallel_beam.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/projectors.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct/utils.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/analytical.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/backend/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/backend/_mlx.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/backend/_torch.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/backend/metal/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/backend/metal/constants.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/backend/metal/geometry.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/backend/metal/kernels/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/backend/metal/projectors.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/backend/metal/utils.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/calibration.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/filters.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/functionals.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/geometry.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/orchestration/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/orchestration/out_of_core.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/phantoms/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/phantoms/engine.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/phantoms/shepp_logan.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/physics/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/physics/corrections.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/physics/data/spectra.npz +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/physics/pipeline.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/physics/spectra.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/projectors.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/real_measured_data_helper.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/rebinning.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/_core.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/_solver.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/asd_pocs.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/awtv_pocs.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/dart.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/sart.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/sirt.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/solvers.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/reconstruction_algorithms/tv_pocs.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/regularizers.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/diffct_mlx/tv_gradients.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/docs/Makefile +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/docs/source/_static/.gitkeep +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/docs/source/examples.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/docs/source/fbp_fan_example.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/docs/source/fbp_parallel_example.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/docs/source/fdk_cone_example.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/docs/source/iterative_reco_cone_example.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/docs/source/iterative_reco_fan_example.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/docs/source/iterative_reco_parallel_example.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/examples/circular_trajectory/fbp_fan.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/examples/circular_trajectory/fbp_parallel.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/examples/circular_trajectory/fdk_cone.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/examples/circular_trajectory/iterative_reco_cone.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/examples/circular_trajectory/iterative_reco_fan.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/examples/circular_trajectory/iterative_reco_parallel.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/examples/non_circular_trajectory/iterative_reco_cone.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/examples/non_circular_trajectory/iterative_reco_fan.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/examples/non_circular_trajectory/iterative_reco_parallel.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/examples/plot_trajectory.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/pytest.ini +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/requirements.txt +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/_phantoms.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/benchmarks/README.md +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/benchmarks/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/benchmarks/_common.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/benchmarks/test_bench_cone.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/benchmarks/test_bench_fan.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/benchmarks/test_bench_parallel.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_adjoint_inner_product.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_cone_projector_autograd.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_cuda_smoke.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_diffct_mlx_extensions.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_fbp_fan_accuracy.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_fbp_fan_offsets.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_fbp_parallel_accuracy.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_fdk_cone_accuracy.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_fdk_cone_offsets.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_gradcheck.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_known_operator_gradflow.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_metal_kernel_static.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_ramp_filter_windows.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_regressions.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_siddon_centering.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tests/test_weights.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.2.0}/tools/generate_spectra.py +0 -0
|
@@ -9,6 +9,122 @@ and the project follows [Semantic Versioning](https://semver.org/).
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [2.2.0] - 2026-11-18
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- **Footprint projectors return line integrals.** The separable-footprint
|
|
17
|
+
kernels (parallel, fan, cone; forward, adjoint and the sparse cone adjoint;
|
|
18
|
+
Metal and CUDA) distributed every voxel with weights that sum to one over
|
|
19
|
+
the detector cells it touches (`overlap / footprint_width`). The output was
|
|
20
|
+
therefore not a line integral: the cone sinogram scaled with
|
|
21
|
+
`(detector cell size at the isocentre / voxel size)**2` (0.21x for a 0.28 mm
|
|
22
|
+
cell on 0.6 mm voxels), and the parallel and fan sinograms carried an
|
|
23
|
+
additional view-angle factor `1 / max(|cos|, |sin|)` of up to 1.41x at 45
|
|
24
|
+
degrees plus the factor `detector cell / voxel`. The kernels now use a
|
|
25
|
+
mass-conserving amplitude (parallel: `1 / det_spacing_vox`; fan:
|
|
26
|
+
`t * |r| / (|r.n| * det_spacing_vox)`; cone:
|
|
27
|
+
`vs^2 * t^2 * |r| / (|r.n| * du * dv)` with local magnification `t`), so a
|
|
28
|
+
footprint sinogram is a voxel-unit line integral averaged over the detector
|
|
29
|
+
cell and agrees with the Siddon projector to within 1 % for any detector
|
|
30
|
+
spacing, voxel spacing and magnification
|
|
31
|
+
(`tests/test_footprint_amplitude.py`). The forward/adjoint pairs remain
|
|
32
|
+
exact adjoints.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- **Numerical output of every `*_footprint` projector and of operators built
|
|
37
|
+
with `projector_mode="footprint"` (the default) changes** by the factors
|
|
38
|
+
above. Consequences:
|
|
39
|
+
- Sensitivity-normalised SART (`SARTParameters` default) is unaffected when
|
|
40
|
+
data and operator come from the same footprint pair. Reconstructing
|
|
41
|
+
line-integral data (Siddon simulation, measured data) with the footprint
|
|
42
|
+
pair now yields the correct amplitude; before, the built-in fan and cone
|
|
43
|
+
cases came out 1.4x and 2.4x too large.
|
|
44
|
+
- Physical noise or beam-hardening models applied to footprint sinograms
|
|
45
|
+
(`exp(-p)`) now see the correct attenuation.
|
|
46
|
+
- Unnormalised iterative updates (`voxel_sensitivity_normalization=False`)
|
|
47
|
+
need a `backprojection_scale`: the adjoint of ones is now
|
|
48
|
+
`(vs * t / du)^2` per view instead of one. The case default 0.215 remains
|
|
49
|
+
stable for the built-in cone case.
|
|
50
|
+
- Results that mixed footprint sinograms with absolute thresholds or fixed
|
|
51
|
+
step sizes tuned on 2.1.0 and earlier are not comparable across this
|
|
52
|
+
change.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### Known issues
|
|
56
|
+
|
|
57
|
+
- The quantitative FDK path (`reconstruct_case_fdk`, `fdk_back_project`) is
|
|
58
|
+
**torch/CUDA-only**: it drives the vendored `cone_weighted_backproject`
|
|
59
|
+
gather kernel, which has no Metal counterpart yet. On MLX the cone cases
|
|
60
|
+
fall back to the legacy calibrated path (synthetic cases) or report
|
|
61
|
+
`supports_fdk=False` (measured/npy). Porting needs a Metal FDK gather
|
|
62
|
+
kernel with `(FOD/U)^2` weighting plus a `cone_weighted_backproject`
|
|
63
|
+
equivalent exposed through the backend's `analytical` module — same
|
|
64
|
+
structure as the CUDA one (`diffct/kernels/cone_beam.py::
|
|
65
|
+
_cone_3d_fdk_backproject_kernel`, wired via
|
|
66
|
+
`diffct_mlx/reconstruction_algorithms/cases.py::_quantitative_fdk_operators`).
|
|
67
|
+
|
|
68
|
+
### Notes
|
|
69
|
+
|
|
70
|
+
- Acceptance tests hardened per the FDK review: object-size sweep
|
|
71
|
+
(25/50/75 % FOV, amplitude 0.90–1.08×) and detector-pitch invariance
|
|
72
|
+
(du ∈ {1.0, 0.556, 0.278} mm within 4 % of each other). A proposed
|
|
73
|
+
du-free DFT-bin ramp (`|fftfreq|` without factor 2 and without
|
|
74
|
+
`sample_spacing`) was evaluated against these and rejected: it scales
|
|
75
|
+
the reconstruction by ~`du/2` (0.484/0.269/0.134× across the sweep —
|
|
76
|
+
invisible only at `du = 1`). The physical filtering carries
|
|
77
|
+
`Q = IFFT(FFT(g)·|f_k|)/du`; the quantitative path's
|
|
78
|
+
`sample_spacing`/constants implement exactly that and are
|
|
79
|
+
pitch-invariant (0.966–0.968× across the sweep).
|
|
80
|
+
|
|
81
|
+
## [2.1.0] - 2026-07-16
|
|
82
|
+
|
|
83
|
+
### Added
|
|
84
|
+
|
|
85
|
+
- **Quantitative FDK** (amplitude-true attenuation values) for all cone
|
|
86
|
+
cases, incl. measured data (`supports_fdk=True` on the torch backend) via
|
|
87
|
+
`reconstruct_case_fdk` and the new case fields `fdk_filter` /
|
|
88
|
+
`fdk_back_project`: cosine weights → per-view trapezoidal angular weights
|
|
89
|
+
(actual source angles) → zero-padded physical ramp (`|f|/du`) → voxel-driven
|
|
90
|
+
`(SID/U)²`-weighted FDK gather backprojection with the analytic
|
|
91
|
+
`SDD/(2π·SID)` constant. Sinogram units handled per source (measured −log
|
|
92
|
+
data are physical µ·mm; raw Siddon output is voxel-unit → ×`voxel_spacing`).
|
|
93
|
+
Verified on a known-µ cylinder at real camera geometry (du 0.556 mm, voxel
|
|
94
|
+
0.278 mm, magnification 2, 75 % FOV object): recovers 0.99× true µ where the
|
|
95
|
+
legacy calibrated path gives 0.47× (`tests/test_quantitative_fdk.py`).
|
|
96
|
+
- `ramp_filter`/`ramp_filter_2d`/`ramp_filter_3d` accept `pad_factor`
|
|
97
|
+
(zero-padding against circular-convolution wrap-around — the unpadded ramp
|
|
98
|
+
biases objects by up to 0.40× at 75 % FOV coverage, object-size-DEPENDENT,
|
|
99
|
+
so no constant can compensate) and `sample_spacing` (physical `|f|/du`
|
|
100
|
+
scaling).
|
|
101
|
+
|
|
102
|
+
### Fixed
|
|
103
|
+
|
|
104
|
+
- PyPI publishing now triggers directly from `v*` tag pushes. GitHub suppresses
|
|
105
|
+
follow-up workflows for releases created with `GITHUB_TOKEN`, so the former
|
|
106
|
+
`release.published` trigger required a manual dispatch.
|
|
107
|
+
- `simulate_scan` fed voxel-unit line integrals into the physical
|
|
108
|
+
intensity/beam-hardening chain (`exp(-p)`, polychromatic nonlinearity) —
|
|
109
|
+
silently wrong for `voxel_spacing != 1`. It now rescales by the operator's
|
|
110
|
+
voxel spacing (new `ProjectionOperator.voxel_spacing` metadata, propagated
|
|
111
|
+
by `.subset`; explicit `voxel_spacing=` override) and returns physical,
|
|
112
|
+
scanner-like sinograms. Unchanged at `voxel_spacing = 1`.
|
|
113
|
+
- `ReconstructionCase.voxel_spacing` documents the unit contract: iterative
|
|
114
|
+
reconstruction of physical (measured) sinograms yields attenuation per
|
|
115
|
+
voxel — divide by `voxel_spacing` for 1/mm; the quantitative FDK path
|
|
116
|
+
returns 1/mm directly.
|
|
117
|
+
|
|
118
|
+
### Changed
|
|
119
|
+
|
|
120
|
+
- `main` is the single development line; the redundant `cuda` branch has been
|
|
121
|
+
retired and the README no longer describes branch-specific APIs.
|
|
122
|
+
- `FBPParameters`/`FDKParameters` gained `pad_factor` (default **2**) and
|
|
123
|
+
route their `detector_spacing` into the ramp's `sample_spacing`. Analytic
|
|
124
|
+
reconstructions therefore differ slightly (less interior depression) from
|
|
125
|
+
earlier unpadded results; set `pad_factor=1` to reproduce legacy output.
|
|
126
|
+
The legacy case constants remain valid for the synthetic unit-spacing cases.
|
|
127
|
+
|
|
12
128
|
## [2.0.1] - 2026-07-15
|
|
13
129
|
|
|
14
130
|
### Added
|
|
@@ -360,6 +476,7 @@ necessary for the arbitrary-trajectory kernel API:
|
|
|
360
476
|
when the detector is not plane-aligned to the voxel axes) and will
|
|
361
477
|
be tackled in a dedicated follow-up.
|
|
362
478
|
|
|
363
|
-
[Unreleased]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/compare/v2.0
|
|
479
|
+
[Unreleased]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/compare/v2.1.0...HEAD
|
|
480
|
+
[2.1.0]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/compare/v2.0.1...v2.1.0
|
|
364
481
|
[2.0.1]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/compare/v2.0.0...v2.0.1
|
|
365
482
|
[2.0.0]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/releases/tag/v2.0.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: diffct-mlx
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.2.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
|
|
@@ -26,8 +26,7 @@ Description-Content-Type: text/markdown
|
|
|
26
26
|
# diffct: Differentiable Computed Tomography Operators
|
|
27
27
|
|
|
28
28
|
> [!NOTE]
|
|
29
|
-
> **
|
|
30
|
-
> It is based on diffct's arbitrary-trajectory (`dev`) line, whose module layout and per-view projector convention match the MLX port. This branch hosts the unified **auto-backend** package `diffct_mlx` (MLX/Metal on Apple Silicon, Torch/numba-CUDA elsewhere) so the same code runs on both. Maintained by [Linda-Sophie Schneider](https://github.com/Linda-SophieSchneider).
|
|
29
|
+
> **[DiffCT-MLX](https://github.com/Linda-SophieSchneider/DiffCT-MLX) — the unified auto-backend package `diffct_mlx`** (MLX/Metal on Apple Silicon, Torch/numba-CUDA elsewhere), so the same code runs on both. The Torch/CUDA engine is adapted from the original [diffct](https://github.com/sypsyp97) by Yipeng Sun (Apache-2.0), based on its arbitrary-trajectory (`dev`) line. Maintained by [Linda-Sophie Schneider](https://github.com/Linda-SophieSchneider).
|
|
31
30
|
> See [ATTRIBUTION.md](ATTRIBUTION.md) for full provenance and license details.
|
|
32
31
|
|
|
33
32
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
@@ -48,13 +47,12 @@ custom). Built for optimization and deep-learning integration.
|
|
|
48
47
|
[Linda-Sophie Schneider](https://github.com/Linda-SophieSchneider) at
|
|
49
48
|
[Linda-SophieSchneider/DiffCT-MLX](https://github.com/Linda-SophieSchneider/DiffCT-MLX).
|
|
50
49
|
|
|
51
|
-
## 🧭
|
|
50
|
+
## 🧭 The unified `diffct_mlx` API
|
|
52
51
|
|
|
53
|
-
|
|
52
|
+
**`diffct_mlx`** is a single API that auto-selects its
|
|
54
53
|
compute backend at import — **Torch / numba-CUDA** on NVIDIA GPUs, **Apple MLX**
|
|
55
54
|
on Apple Silicon — so the *same* script runs unchanged on both. It mirrors the
|
|
56
|
-
public API
|
|
57
|
-
(Apple) package name-for-name.
|
|
55
|
+
same public API on both backends name-for-name.
|
|
58
56
|
|
|
59
57
|
```bash
|
|
60
58
|
pip install "diffct-mlx[cuda]" # NVIDIA GPUs (Torch + numba-CUDA)
|
|
@@ -80,11 +78,11 @@ reco = dct.reconstruct_fbp(
|
|
|
80
78
|
|
|
81
79
|
**Parity & status.** FBP/FDK, SART/SIRT, TV-/ASD-/AwTV-POCS, DART, phantoms,
|
|
82
80
|
trajectory generators and the measured-data helpers are all available and were
|
|
83
|
-
verified on NVIDIA GPUs. The **MLX backend** is
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
verified on NVIDIA GPUs. The **MLX backend** is runtime-validated on Apple
|
|
82
|
+
Silicon; its vendored Metal kernels use `mx.custom_function` projectors and
|
|
83
|
+
the same centered Siddon/geometry-gradient conventions as CUDA. The
|
|
84
|
+
backend-neutral `xp` namespace is attribute-identical to the torch one, pinned
|
|
85
|
+
by a static parity test.
|
|
88
86
|
|
|
89
87
|
### Projectors: Siddon vs. separable footprint
|
|
90
88
|
|
|
@@ -117,10 +115,52 @@ evaluation**: `cone_backward_footprint(..., indices=idx)` computes only the give
|
|
|
117
115
|
flattened `(D, H, W)` voxels and returns a 1-D vector (useful for masked / DART
|
|
118
116
|
subproblems).
|
|
119
117
|
|
|
118
|
+
### Quantitative FDK (amplitude-true reconstruction)
|
|
119
|
+
|
|
120
|
+
The legacy case FDK path was a *synthetic-geometry calibration*, not physics:
|
|
121
|
+
an unpadded DFT-bin ramp (circular-convolution wrap-around depresses large
|
|
122
|
+
objects with an object-size-dependent bias — down to 0.40× at 75 % FOV
|
|
123
|
+
coverage), the constant `π·SID/(2·SDD·N)` (only valid for `du = dv = voxel
|
|
124
|
+
= 1`), and the Siddon adjoint (not an FDK backprojector). On measured data
|
|
125
|
+
these stack to ~0.1–0.5× of the true attenuation.
|
|
126
|
+
|
|
127
|
+
The quantitative path fixes all three: cosine pre-weights → per-view
|
|
128
|
+
trapezoidal angular weights (actual source angles, non-uniform trajectories
|
|
129
|
+
included) → zero-padded **physical** ramp (`|f|/du`, `pad_factor=2`) → the
|
|
130
|
+
voxel-driven `(SID/U)²`-weighted FDK gather backprojector with its analytic
|
|
131
|
+
`SDD/(2π·SID)` constant. Verified: a cylinder of known µ at real camera
|
|
132
|
+
geometry (du 0.556 mm, voxel 0.278 mm, magnification 2, object filling 75 %
|
|
133
|
+
of the FOV) reconstructs to **0.99×** the true µ (legacy path: 0.47×).
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
case = dct.build_measured_cone_3d_case(cfg) # supports_fdk=True on CUDA now
|
|
137
|
+
vol_mu = dct.reconstruct_case_fdk(case) # true attenuation units (1/mm)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
All cone cases (synthetic, measured TIFF, npy) carry the quantitative
|
|
141
|
+
operators (`case.fdk_weight` / `fdk_filter` / `fdk_back_project`); sinogram
|
|
142
|
+
units are handled per source (measured −log data are physical; raw Siddon
|
|
143
|
+
projector output is voxel-unit and rescaled by `voxel_spacing`). The ramp
|
|
144
|
+
filter itself now accepts `pad_factor` and `sample_spacing`, and
|
|
145
|
+
`FBPParameters`/`FDKParameters` default to `pad_factor=2`.
|
|
146
|
+
|
|
147
|
+
> **Unit convention.** The projectors integrate in **voxel units**: physical
|
|
148
|
+
> line integrals are `(A @ x) * voxel_spacing`. This holds for both projector
|
|
149
|
+
> modes: since 2.2.0 the footprint kernels are mass-conserving and agree with
|
|
150
|
+
> the Siddon kernels in amplitude (earlier versions scaled footprint output
|
|
151
|
+
> with the detector-cell-to-voxel size ratio). Operators built via
|
|
152
|
+
> `make_*_operator` carry `A.voxel_spacing` as metadata, and the boundaries
|
|
153
|
+
> where physical units matter handle the conversion automatically —
|
|
154
|
+
> `simulate_scan` rescales before the `exp(-p)` / beam-hardening physics (and
|
|
155
|
+
> returns physical, scanner-like sinograms), and the quantitative FDK path
|
|
156
|
+
> encodes it per data source. One consequence to know: **iterative**
|
|
157
|
+
> reconstruction of measured (physical) data converges to attenuation *per
|
|
158
|
+
> voxel*; divide by `case.voxel_spacing` for µ in 1/mm.
|
|
159
|
+
|
|
120
160
|
### Operators, solvers, regularizers, physics & simulation
|
|
121
161
|
|
|
122
|
-
The
|
|
123
|
-
projectors (all GPU-resident, verified on NVIDIA GPUs):
|
|
162
|
+
The unified package provides a composable, differentiable toolkit on top of
|
|
163
|
+
the projectors (all GPU-resident, verified on NVIDIA GPUs):
|
|
124
164
|
|
|
125
165
|
- **Operators** (`diffct_mlx.operators`) — a `LinearOperator` algebra: build a
|
|
126
166
|
projector as `A = dct.make_cone_3d_operator(...)`, then `A @ x`, `A.T @ y`,
|
|
@@ -266,23 +306,18 @@ to ~1e-6, 2-GPU == 1-GPU exact, 2048³ cone-FDK end-to-end with a bounded
|
|
|
266
306
|
working set. This path is CUDA-only (it drives the numba-CUDA kernels
|
|
267
307
|
directly).
|
|
268
308
|
|
|
269
|
-
## 🔀 Branches
|
|
270
|
-
|
|
271
|
-
### `main` — unified auto-backend package
|
|
272
|
-
The unified `diffct_mlx` package described above: one API, two engines
|
|
273
|
-
(Torch/numba-CUDA and MLX/Metal), auto-selected at import. This is the branch
|
|
274
|
-
to use on every platform.
|
|
309
|
+
## 🔀 Branches & releases
|
|
275
310
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
311
|
+
All development happens on **`main`** (the former `cuda` development branch
|
|
312
|
+
has been merged and retired). Versioned releases are tagged and published to
|
|
313
|
+
PyPI via CI (trusted publishing); `gh-pages` hosts the built documentation.
|
|
279
314
|
|
|
280
315
|
Kernels take per-view ``(src_pos, det_center, det_u_vec[, det_v_vec])``
|
|
281
316
|
arrays instead of closed-form ``sdd / sid / beta`` scalars, so **spiral,
|
|
282
317
|
saddle, sinusoidal, laminography, or any user-supplied trajectory** works
|
|
283
318
|
without touching the kernels — on both backends.
|
|
284
319
|
|
|
285
|
-
|
|
320
|
+
If you find any bugs please
|
|
286
321
|
[raise an issue](https://github.com/Linda-SophieSchneider/DiffCT-MLX/issues).
|
|
287
322
|
|
|
288
323
|
## ✨ Features
|
|
@@ -444,7 +479,7 @@ pip install -e .
|
|
|
444
479
|
### Running the tests
|
|
445
480
|
|
|
446
481
|
```bash
|
|
447
|
-
pytest tests/ -q #
|
|
482
|
+
pytest tests/ -q # core suite (backend-specific tests may skip)
|
|
448
483
|
pytest tests/benchmarks/ --benchmark-only # opt-in perf suite
|
|
449
484
|
```
|
|
450
485
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# diffct: Differentiable Computed Tomography Operators
|
|
2
2
|
|
|
3
3
|
> [!NOTE]
|
|
4
|
-
> **
|
|
5
|
-
> It is based on diffct's arbitrary-trajectory (`dev`) line, whose module layout and per-view projector convention match the MLX port. This branch hosts the unified **auto-backend** package `diffct_mlx` (MLX/Metal on Apple Silicon, Torch/numba-CUDA elsewhere) so the same code runs on both. Maintained by [Linda-Sophie Schneider](https://github.com/Linda-SophieSchneider).
|
|
4
|
+
> **[DiffCT-MLX](https://github.com/Linda-SophieSchneider/DiffCT-MLX) — the unified auto-backend package `diffct_mlx`** (MLX/Metal on Apple Silicon, Torch/numba-CUDA elsewhere), so the same code runs on both. The Torch/CUDA engine is adapted from the original [diffct](https://github.com/sypsyp97) by Yipeng Sun (Apache-2.0), based on its arbitrary-trajectory (`dev`) line. Maintained by [Linda-Sophie Schneider](https://github.com/Linda-SophieSchneider).
|
|
6
5
|
> See [ATTRIBUTION.md](ATTRIBUTION.md) for full provenance and license details.
|
|
7
6
|
|
|
8
7
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
@@ -23,13 +22,12 @@ custom). Built for optimization and deep-learning integration.
|
|
|
23
22
|
[Linda-Sophie Schneider](https://github.com/Linda-SophieSchneider) at
|
|
24
23
|
[Linda-SophieSchneider/DiffCT-MLX](https://github.com/Linda-SophieSchneider/DiffCT-MLX).
|
|
25
24
|
|
|
26
|
-
## 🧭
|
|
25
|
+
## 🧭 The unified `diffct_mlx` API
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
**`diffct_mlx`** is a single API that auto-selects its
|
|
29
28
|
compute backend at import — **Torch / numba-CUDA** on NVIDIA GPUs, **Apple MLX**
|
|
30
29
|
on Apple Silicon — so the *same* script runs unchanged on both. It mirrors the
|
|
31
|
-
public API
|
|
32
|
-
(Apple) package name-for-name.
|
|
30
|
+
same public API on both backends name-for-name.
|
|
33
31
|
|
|
34
32
|
```bash
|
|
35
33
|
pip install "diffct-mlx[cuda]" # NVIDIA GPUs (Torch + numba-CUDA)
|
|
@@ -55,11 +53,11 @@ reco = dct.reconstruct_fbp(
|
|
|
55
53
|
|
|
56
54
|
**Parity & status.** FBP/FDK, SART/SIRT, TV-/ASD-/AwTV-POCS, DART, phantoms,
|
|
57
55
|
trajectory generators and the measured-data helpers are all available and were
|
|
58
|
-
verified on NVIDIA GPUs. The **MLX backend** is
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
verified on NVIDIA GPUs. The **MLX backend** is runtime-validated on Apple
|
|
57
|
+
Silicon; its vendored Metal kernels use `mx.custom_function` projectors and
|
|
58
|
+
the same centered Siddon/geometry-gradient conventions as CUDA. The
|
|
59
|
+
backend-neutral `xp` namespace is attribute-identical to the torch one, pinned
|
|
60
|
+
by a static parity test.
|
|
63
61
|
|
|
64
62
|
### Projectors: Siddon vs. separable footprint
|
|
65
63
|
|
|
@@ -92,10 +90,52 @@ evaluation**: `cone_backward_footprint(..., indices=idx)` computes only the give
|
|
|
92
90
|
flattened `(D, H, W)` voxels and returns a 1-D vector (useful for masked / DART
|
|
93
91
|
subproblems).
|
|
94
92
|
|
|
93
|
+
### Quantitative FDK (amplitude-true reconstruction)
|
|
94
|
+
|
|
95
|
+
The legacy case FDK path was a *synthetic-geometry calibration*, not physics:
|
|
96
|
+
an unpadded DFT-bin ramp (circular-convolution wrap-around depresses large
|
|
97
|
+
objects with an object-size-dependent bias — down to 0.40× at 75 % FOV
|
|
98
|
+
coverage), the constant `π·SID/(2·SDD·N)` (only valid for `du = dv = voxel
|
|
99
|
+
= 1`), and the Siddon adjoint (not an FDK backprojector). On measured data
|
|
100
|
+
these stack to ~0.1–0.5× of the true attenuation.
|
|
101
|
+
|
|
102
|
+
The quantitative path fixes all three: cosine pre-weights → per-view
|
|
103
|
+
trapezoidal angular weights (actual source angles, non-uniform trajectories
|
|
104
|
+
included) → zero-padded **physical** ramp (`|f|/du`, `pad_factor=2`) → the
|
|
105
|
+
voxel-driven `(SID/U)²`-weighted FDK gather backprojector with its analytic
|
|
106
|
+
`SDD/(2π·SID)` constant. Verified: a cylinder of known µ at real camera
|
|
107
|
+
geometry (du 0.556 mm, voxel 0.278 mm, magnification 2, object filling 75 %
|
|
108
|
+
of the FOV) reconstructs to **0.99×** the true µ (legacy path: 0.47×).
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
case = dct.build_measured_cone_3d_case(cfg) # supports_fdk=True on CUDA now
|
|
112
|
+
vol_mu = dct.reconstruct_case_fdk(case) # true attenuation units (1/mm)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
All cone cases (synthetic, measured TIFF, npy) carry the quantitative
|
|
116
|
+
operators (`case.fdk_weight` / `fdk_filter` / `fdk_back_project`); sinogram
|
|
117
|
+
units are handled per source (measured −log data are physical; raw Siddon
|
|
118
|
+
projector output is voxel-unit and rescaled by `voxel_spacing`). The ramp
|
|
119
|
+
filter itself now accepts `pad_factor` and `sample_spacing`, and
|
|
120
|
+
`FBPParameters`/`FDKParameters` default to `pad_factor=2`.
|
|
121
|
+
|
|
122
|
+
> **Unit convention.** The projectors integrate in **voxel units**: physical
|
|
123
|
+
> line integrals are `(A @ x) * voxel_spacing`. This holds for both projector
|
|
124
|
+
> modes: since 2.2.0 the footprint kernels are mass-conserving and agree with
|
|
125
|
+
> the Siddon kernels in amplitude (earlier versions scaled footprint output
|
|
126
|
+
> with the detector-cell-to-voxel size ratio). Operators built via
|
|
127
|
+
> `make_*_operator` carry `A.voxel_spacing` as metadata, and the boundaries
|
|
128
|
+
> where physical units matter handle the conversion automatically —
|
|
129
|
+
> `simulate_scan` rescales before the `exp(-p)` / beam-hardening physics (and
|
|
130
|
+
> returns physical, scanner-like sinograms), and the quantitative FDK path
|
|
131
|
+
> encodes it per data source. One consequence to know: **iterative**
|
|
132
|
+
> reconstruction of measured (physical) data converges to attenuation *per
|
|
133
|
+
> voxel*; divide by `case.voxel_spacing` for µ in 1/mm.
|
|
134
|
+
|
|
95
135
|
### Operators, solvers, regularizers, physics & simulation
|
|
96
136
|
|
|
97
|
-
The
|
|
98
|
-
projectors (all GPU-resident, verified on NVIDIA GPUs):
|
|
137
|
+
The unified package provides a composable, differentiable toolkit on top of
|
|
138
|
+
the projectors (all GPU-resident, verified on NVIDIA GPUs):
|
|
99
139
|
|
|
100
140
|
- **Operators** (`diffct_mlx.operators`) — a `LinearOperator` algebra: build a
|
|
101
141
|
projector as `A = dct.make_cone_3d_operator(...)`, then `A @ x`, `A.T @ y`,
|
|
@@ -241,23 +281,18 @@ to ~1e-6, 2-GPU == 1-GPU exact, 2048³ cone-FDK end-to-end with a bounded
|
|
|
241
281
|
working set. This path is CUDA-only (it drives the numba-CUDA kernels
|
|
242
282
|
directly).
|
|
243
283
|
|
|
244
|
-
## 🔀 Branches
|
|
245
|
-
|
|
246
|
-
### `main` — unified auto-backend package
|
|
247
|
-
The unified `diffct_mlx` package described above: one API, two engines
|
|
248
|
-
(Torch/numba-CUDA and MLX/Metal), auto-selected at import. This is the branch
|
|
249
|
-
to use on every platform.
|
|
284
|
+
## 🔀 Branches & releases
|
|
250
285
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
286
|
+
All development happens on **`main`** (the former `cuda` development branch
|
|
287
|
+
has been merged and retired). Versioned releases are tagged and published to
|
|
288
|
+
PyPI via CI (trusted publishing); `gh-pages` hosts the built documentation.
|
|
254
289
|
|
|
255
290
|
Kernels take per-view ``(src_pos, det_center, det_u_vec[, det_v_vec])``
|
|
256
291
|
arrays instead of closed-form ``sdd / sid / beta`` scalars, so **spiral,
|
|
257
292
|
saddle, sinusoidal, laminography, or any user-supplied trajectory** works
|
|
258
293
|
without touching the kernels — on both backends.
|
|
259
294
|
|
|
260
|
-
|
|
295
|
+
If you find any bugs please
|
|
261
296
|
[raise an issue](https://github.com/Linda-SophieSchneider/DiffCT-MLX/issues).
|
|
262
297
|
|
|
263
298
|
## ✨ Features
|
|
@@ -419,7 +454,7 @@ pip install -e .
|
|
|
419
454
|
### Running the tests
|
|
420
455
|
|
|
421
456
|
```bash
|
|
422
|
-
pytest tests/ -q #
|
|
457
|
+
pytest tests/ -q # core suite (backend-specific tests may skip)
|
|
423
458
|
pytest tests/benchmarks/ --benchmark-only # opt-in perf suite
|
|
424
459
|
```
|
|
425
460
|
|
|
@@ -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
|
|
@@ -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
|
|
@@ -85,6 +85,7 @@ from .reconstruction_algorithms import (
|
|
|
85
85
|
build_cone_3d_case,
|
|
86
86
|
build_measured_cone_3d_case,
|
|
87
87
|
build_npy_cone_3d_case,
|
|
88
|
+
reconstruct_case_fdk,
|
|
88
89
|
make_parallel_2d_operators,
|
|
89
90
|
make_fan_2d_operators,
|
|
90
91
|
make_cone_3d_operators,
|
|
@@ -199,7 +200,7 @@ from .tv_gradients import (
|
|
|
199
200
|
awtv_gradient,
|
|
200
201
|
)
|
|
201
202
|
|
|
202
|
-
__version__ = "2.0
|
|
203
|
+
__version__ = "2.2.0"
|
|
203
204
|
|
|
204
205
|
__all__ = [
|
|
205
206
|
"backend",
|
|
@@ -265,6 +266,7 @@ __all__ = [
|
|
|
265
266
|
"build_cone_3d_case",
|
|
266
267
|
"build_measured_cone_3d_case",
|
|
267
268
|
"build_npy_cone_3d_case",
|
|
269
|
+
"reconstruct_case_fdk",
|
|
268
270
|
"make_parallel_2d_operators",
|
|
269
271
|
"make_fan_2d_operators",
|
|
270
272
|
"make_cone_3d_operators",
|
|
@@ -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
|
}
|