diffct-mlx 2.0.1__tar.gz → 2.1.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.1.0}/.github/workflows/publish.yml +3 -2
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/CHANGELOG.md +49 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/PKG-INFO +57 -25
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/README.md +56 -24
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/__init__.py +3 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/operators.py +10 -3
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/physics/simulate.py +14 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/__init__.py +2 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/_analytic.py +64 -22
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/cases.py +152 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/fbp.py +3 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/fdk.py +3 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/docs/source/api.rst +16 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/docs/source/conf.py +1 -1
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/docs/source/getting_started.rst +14 -3
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/docs/source/index.rst +14 -12
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/pyproject.toml +1 -1
- diffct_mlx-2.1.0/tests/test_quantitative_fdk.py +147 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/.github/workflows/docs.yml +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/.github/workflows/release.yml +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/.gitignore +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/ATTRIBUTION.md +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/LICENSE +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/analytical.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/constants.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/differentiable.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/footprint.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/geometry.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/kernels/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/kernels/cone_beam.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/kernels/cone_footprint.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/kernels/fan_beam.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/kernels/fan_footprint.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/kernels/parallel_beam.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/kernels/parallel_footprint.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/projectors.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct/utils.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/analytical.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/backend/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/backend/_mlx.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/backend/_torch.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/backend/metal/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/backend/metal/constants.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/backend/metal/geometry.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/backend/metal/kernels/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/backend/metal/kernels/cone_beam.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/backend/metal/kernels/fan_beam.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/backend/metal/kernels/parallel_beam.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/backend/metal/projectors.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/backend/metal/utils.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/calibration.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/filters.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/functionals.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/geometry.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/orchestration/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/orchestration/out_of_core.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/phantoms/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/phantoms/engine.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/phantoms/shepp_logan.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/physics/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/physics/corrections.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/physics/data/spectra.npz +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/physics/pipeline.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/physics/spectra.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/projectors.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/real_measured_data_helper.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/rebinning.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/_core.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/_solver.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/asd_pocs.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/awtv_pocs.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/dart.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/sart.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/sirt.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/solvers.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/reconstruction_algorithms/tv_pocs.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/regularizers.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/diffct_mlx/tv_gradients.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/docs/Makefile +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/docs/source/_static/.gitkeep +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/docs/source/examples.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/docs/source/fbp_fan_example.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/docs/source/fbp_parallel_example.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/docs/source/fdk_cone_example.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/docs/source/iterative_reco_cone_example.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/docs/source/iterative_reco_fan_example.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/docs/source/iterative_reco_parallel_example.rst +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/examples/circular_trajectory/fbp_fan.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/examples/circular_trajectory/fbp_parallel.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/examples/circular_trajectory/fdk_cone.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/examples/circular_trajectory/iterative_reco_cone.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/examples/circular_trajectory/iterative_reco_fan.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/examples/circular_trajectory/iterative_reco_parallel.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/examples/non_circular_trajectory/iterative_reco_cone.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/examples/non_circular_trajectory/iterative_reco_fan.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/examples/non_circular_trajectory/iterative_reco_parallel.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/examples/plot_trajectory.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/pytest.ini +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/requirements.txt +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/_phantoms.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/benchmarks/README.md +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/benchmarks/__init__.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/benchmarks/_common.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/benchmarks/test_bench_cone.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/benchmarks/test_bench_fan.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/benchmarks/test_bench_parallel.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_adjoint_inner_product.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_cone_projector_autograd.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_cuda_smoke.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_diffct_mlx_extensions.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_fbp_fan_accuracy.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_fbp_fan_offsets.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_fbp_parallel_accuracy.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_fdk_cone_accuracy.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_fdk_cone_offsets.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_gradcheck.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_known_operator_gradflow.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_metal_kernel_static.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_ramp_filter_windows.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_regressions.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_siddon_centering.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tests/test_weights.py +0 -0
- {diffct_mlx-2.0.1 → diffct_mlx-2.1.0}/tools/generate_spectra.py +0 -0
|
@@ -9,6 +9,53 @@ and the project follows [Semantic Versioning](https://semver.org/).
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [2.1.0] - 2026-07-16
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- **Quantitative FDK** (amplitude-true attenuation values) for all cone
|
|
17
|
+
cases, incl. measured data (`supports_fdk=True` on the torch backend) via
|
|
18
|
+
`reconstruct_case_fdk` and the new case fields `fdk_filter` /
|
|
19
|
+
`fdk_back_project`: cosine weights → per-view trapezoidal angular weights
|
|
20
|
+
(actual source angles) → zero-padded physical ramp (`|f|/du`) → voxel-driven
|
|
21
|
+
`(SID/U)²`-weighted FDK gather backprojection with the analytic
|
|
22
|
+
`SDD/(2π·SID)` constant. Sinogram units handled per source (measured −log
|
|
23
|
+
data are physical µ·mm; raw Siddon output is voxel-unit → ×`voxel_spacing`).
|
|
24
|
+
Verified on a known-µ cylinder at real camera geometry (du 0.556 mm, voxel
|
|
25
|
+
0.278 mm, magnification 2, 75 % FOV object): recovers 0.99× true µ where the
|
|
26
|
+
legacy calibrated path gives 0.47× (`tests/test_quantitative_fdk.py`).
|
|
27
|
+
- `ramp_filter`/`ramp_filter_2d`/`ramp_filter_3d` accept `pad_factor`
|
|
28
|
+
(zero-padding against circular-convolution wrap-around — the unpadded ramp
|
|
29
|
+
biases objects by up to 0.40× at 75 % FOV coverage, object-size-DEPENDENT,
|
|
30
|
+
so no constant can compensate) and `sample_spacing` (physical `|f|/du`
|
|
31
|
+
scaling).
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
|
|
35
|
+
- PyPI publishing now triggers directly from `v*` tag pushes. GitHub suppresses
|
|
36
|
+
follow-up workflows for releases created with `GITHUB_TOKEN`, so the former
|
|
37
|
+
`release.published` trigger required a manual dispatch.
|
|
38
|
+
- `simulate_scan` fed voxel-unit line integrals into the physical
|
|
39
|
+
intensity/beam-hardening chain (`exp(-p)`, polychromatic nonlinearity) —
|
|
40
|
+
silently wrong for `voxel_spacing != 1`. It now rescales by the operator's
|
|
41
|
+
voxel spacing (new `ProjectionOperator.voxel_spacing` metadata, propagated
|
|
42
|
+
by `.subset`; explicit `voxel_spacing=` override) and returns physical,
|
|
43
|
+
scanner-like sinograms. Unchanged at `voxel_spacing = 1`.
|
|
44
|
+
- `ReconstructionCase.voxel_spacing` documents the unit contract: iterative
|
|
45
|
+
reconstruction of physical (measured) sinograms yields attenuation per
|
|
46
|
+
voxel — divide by `voxel_spacing` for 1/mm; the quantitative FDK path
|
|
47
|
+
returns 1/mm directly.
|
|
48
|
+
|
|
49
|
+
### Changed
|
|
50
|
+
|
|
51
|
+
- `main` is the single development line; the redundant `cuda` branch has been
|
|
52
|
+
retired and the README no longer describes branch-specific APIs.
|
|
53
|
+
- `FBPParameters`/`FDKParameters` gained `pad_factor` (default **2**) and
|
|
54
|
+
route their `detector_spacing` into the ramp's `sample_spacing`. Analytic
|
|
55
|
+
reconstructions therefore differ slightly (less interior depression) from
|
|
56
|
+
earlier unpadded results; set `pad_factor=1` to reproduce legacy output.
|
|
57
|
+
The legacy case constants remain valid for the synthetic unit-spacing cases.
|
|
58
|
+
|
|
12
59
|
## [2.0.1] - 2026-07-15
|
|
13
60
|
|
|
14
61
|
### Added
|
|
@@ -360,6 +407,7 @@ necessary for the arbitrary-trajectory kernel API:
|
|
|
360
407
|
when the detector is not plane-aligned to the voxel axes) and will
|
|
361
408
|
be tackled in a dedicated follow-up.
|
|
362
409
|
|
|
363
|
-
[Unreleased]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/compare/v2.0
|
|
410
|
+
[Unreleased]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/compare/v2.1.0...HEAD
|
|
411
|
+
[2.1.0]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/compare/v2.0.1...v2.1.0
|
|
364
412
|
[2.0.1]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/compare/v2.0.0...v2.0.1
|
|
365
413
|
[2.0.0]: https://github.com/Linda-SophieSchneider/DiffCT-MLX/releases/tag/v2.0.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: diffct-mlx
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.1.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,49 @@ 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`. Operators built via
|
|
149
|
+
> `make_*_operator` carry `A.voxel_spacing` as metadata, and the boundaries
|
|
150
|
+
> where physical units matter handle the conversion automatically —
|
|
151
|
+
> `simulate_scan` rescales before the `exp(-p)` / beam-hardening physics (and
|
|
152
|
+
> returns physical, scanner-like sinograms), and the quantitative FDK path
|
|
153
|
+
> encodes it per data source. One consequence to know: **iterative**
|
|
154
|
+
> reconstruction of measured (physical) data converges to attenuation *per
|
|
155
|
+
> voxel*; divide by `case.voxel_spacing` for µ in 1/mm.
|
|
156
|
+
|
|
120
157
|
### Operators, solvers, regularizers, physics & simulation
|
|
121
158
|
|
|
122
|
-
The
|
|
123
|
-
projectors (all GPU-resident, verified on NVIDIA GPUs):
|
|
159
|
+
The unified package provides a composable, differentiable toolkit on top of
|
|
160
|
+
the projectors (all GPU-resident, verified on NVIDIA GPUs):
|
|
124
161
|
|
|
125
162
|
- **Operators** (`diffct_mlx.operators`) — a `LinearOperator` algebra: build a
|
|
126
163
|
projector as `A = dct.make_cone_3d_operator(...)`, then `A @ x`, `A.T @ y`,
|
|
@@ -266,23 +303,18 @@ to ~1e-6, 2-GPU == 1-GPU exact, 2048³ cone-FDK end-to-end with a bounded
|
|
|
266
303
|
working set. This path is CUDA-only (it drives the numba-CUDA kernels
|
|
267
304
|
directly).
|
|
268
305
|
|
|
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.
|
|
306
|
+
## 🔀 Branches & releases
|
|
275
307
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
308
|
+
All development happens on **`main`** (the former `cuda` development branch
|
|
309
|
+
has been merged and retired). Versioned releases are tagged and published to
|
|
310
|
+
PyPI via CI (trusted publishing); `gh-pages` hosts the built documentation.
|
|
279
311
|
|
|
280
312
|
Kernels take per-view ``(src_pos, det_center, det_u_vec[, det_v_vec])``
|
|
281
313
|
arrays instead of closed-form ``sdd / sid / beta`` scalars, so **spiral,
|
|
282
314
|
saddle, sinusoidal, laminography, or any user-supplied trajectory** works
|
|
283
315
|
without touching the kernels — on both backends.
|
|
284
316
|
|
|
285
|
-
|
|
317
|
+
If you find any bugs please
|
|
286
318
|
[raise an issue](https://github.com/Linda-SophieSchneider/DiffCT-MLX/issues).
|
|
287
319
|
|
|
288
320
|
## ✨ Features
|
|
@@ -444,7 +476,7 @@ pip install -e .
|
|
|
444
476
|
### Running the tests
|
|
445
477
|
|
|
446
478
|
```bash
|
|
447
|
-
pytest tests/ -q #
|
|
479
|
+
pytest tests/ -q # core suite (backend-specific tests may skip)
|
|
448
480
|
pytest tests/benchmarks/ --benchmark-only # opt-in perf suite
|
|
449
481
|
```
|
|
450
482
|
|
|
@@ -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,49 @@ 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`. Operators built via
|
|
124
|
+
> `make_*_operator` carry `A.voxel_spacing` as metadata, and the boundaries
|
|
125
|
+
> where physical units matter handle the conversion automatically —
|
|
126
|
+
> `simulate_scan` rescales before the `exp(-p)` / beam-hardening physics (and
|
|
127
|
+
> returns physical, scanner-like sinograms), and the quantitative FDK path
|
|
128
|
+
> encodes it per data source. One consequence to know: **iterative**
|
|
129
|
+
> reconstruction of measured (physical) data converges to attenuation *per
|
|
130
|
+
> voxel*; divide by `case.voxel_spacing` for µ in 1/mm.
|
|
131
|
+
|
|
95
132
|
### Operators, solvers, regularizers, physics & simulation
|
|
96
133
|
|
|
97
|
-
The
|
|
98
|
-
projectors (all GPU-resident, verified on NVIDIA GPUs):
|
|
134
|
+
The unified package provides a composable, differentiable toolkit on top of
|
|
135
|
+
the projectors (all GPU-resident, verified on NVIDIA GPUs):
|
|
99
136
|
|
|
100
137
|
- **Operators** (`diffct_mlx.operators`) — a `LinearOperator` algebra: build a
|
|
101
138
|
projector as `A = dct.make_cone_3d_operator(...)`, then `A @ x`, `A.T @ y`,
|
|
@@ -241,23 +278,18 @@ to ~1e-6, 2-GPU == 1-GPU exact, 2048³ cone-FDK end-to-end with a bounded
|
|
|
241
278
|
working set. This path is CUDA-only (it drives the numba-CUDA kernels
|
|
242
279
|
directly).
|
|
243
280
|
|
|
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.
|
|
281
|
+
## 🔀 Branches & releases
|
|
250
282
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
283
|
+
All development happens on **`main`** (the former `cuda` development branch
|
|
284
|
+
has been merged and retired). Versioned releases are tagged and published to
|
|
285
|
+
PyPI via CI (trusted publishing); `gh-pages` hosts the built documentation.
|
|
254
286
|
|
|
255
287
|
Kernels take per-view ``(src_pos, det_center, det_u_vec[, det_v_vec])``
|
|
256
288
|
arrays instead of closed-form ``sdd / sid / beta`` scalars, so **spiral,
|
|
257
289
|
saddle, sinusoidal, laminography, or any user-supplied trajectory** works
|
|
258
290
|
without touching the kernels — on both backends.
|
|
259
291
|
|
|
260
|
-
|
|
292
|
+
If you find any bugs please
|
|
261
293
|
[raise an issue](https://github.com/Linda-SophieSchneider/DiffCT-MLX/issues).
|
|
262
294
|
|
|
263
295
|
## ✨ Features
|
|
@@ -419,7 +451,7 @@ pip install -e .
|
|
|
419
451
|
### Running the tests
|
|
420
452
|
|
|
421
453
|
```bash
|
|
422
|
-
pytest tests/ -q #
|
|
454
|
+
pytest tests/ -q # core suite (backend-specific tests may skip)
|
|
423
455
|
pytest tests/benchmarks/ --benchmark-only # opt-in perf suite
|
|
424
456
|
```
|
|
425
457
|
|
|
@@ -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.1.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",
|
|
@@ -280,6 +280,7 @@ class ProjectionOperator(LinearOperator):
|
|
|
280
280
|
n_views: int,
|
|
281
281
|
beam: str | None = None,
|
|
282
282
|
views: Any = None,
|
|
283
|
+
voxel_spacing: float = 1.0,
|
|
283
284
|
):
|
|
284
285
|
self._forward_fn = forward_fn
|
|
285
286
|
self._adjoint_fn = adjoint_fn
|
|
@@ -288,6 +289,11 @@ class ProjectionOperator(LinearOperator):
|
|
|
288
289
|
self.n_views = int(n_views)
|
|
289
290
|
self.beam = beam
|
|
290
291
|
self._views = views
|
|
292
|
+
#: Physical voxel pitch of the domain grid. The projectors return line
|
|
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.
|
|
296
|
+
self.voxel_spacing = float(voxel_spacing)
|
|
291
297
|
|
|
292
298
|
def _forward(self, x: Array) -> Array:
|
|
293
299
|
return self._forward_fn(x, self._views)
|
|
@@ -316,6 +322,7 @@ class ProjectionOperator(LinearOperator):
|
|
|
316
322
|
n_views=int(n),
|
|
317
323
|
beam=self.beam,
|
|
318
324
|
views=view_indices,
|
|
325
|
+
voxel_spacing=self.voxel_spacing,
|
|
319
326
|
)
|
|
320
327
|
|
|
321
328
|
|
|
@@ -377,7 +384,7 @@ def make_parallel_2d_operator(
|
|
|
377
384
|
|
|
378
385
|
return ProjectionOperator(
|
|
379
386
|
fwd, adj, domain_shape=(ny, nx), range_shape=(n_views, num_detectors),
|
|
380
|
-
n_views=n_views, beam="parallel",
|
|
387
|
+
n_views=n_views, beam="parallel", voxel_spacing=voxel_spacing,
|
|
381
388
|
)
|
|
382
389
|
|
|
383
390
|
|
|
@@ -414,7 +421,7 @@ def make_fan_2d_operator(
|
|
|
414
421
|
|
|
415
422
|
return ProjectionOperator(
|
|
416
423
|
fwd, adj, domain_shape=(ny, nx), range_shape=(n_views, num_detectors),
|
|
417
|
-
n_views=n_views, beam="fan",
|
|
424
|
+
n_views=n_views, beam="fan", voxel_spacing=voxel_spacing,
|
|
418
425
|
)
|
|
419
426
|
|
|
420
427
|
|
|
@@ -457,5 +464,5 @@ def make_cone_3d_operator(
|
|
|
457
464
|
|
|
458
465
|
return ProjectionOperator(
|
|
459
466
|
fwd, adj, domain_shape=(nz, ny, nx), range_shape=(n_views, det_u_count, det_v_count),
|
|
460
|
-
n_views=n_views, beam="cone",
|
|
467
|
+
n_views=n_views, beam="cone", voxel_spacing=voxel_spacing,
|
|
461
468
|
)
|
|
@@ -258,6 +258,7 @@ def simulate_scan(
|
|
|
258
258
|
poisson: bool = True,
|
|
259
259
|
seed: int = 0,
|
|
260
260
|
return_counts: bool = False,
|
|
261
|
+
voxel_spacing: float | None = None,
|
|
261
262
|
):
|
|
262
263
|
"""Simulate a realistic scan: phantom -> (beam hardening) -> counts -> sinogram.
|
|
263
264
|
|
|
@@ -268,13 +269,25 @@ def simulate_scan(
|
|
|
268
269
|
ring gain), then Poisson noise, then the negative-log brings it back to an
|
|
269
270
|
attenuation sinogram ready for reconstruction.
|
|
270
271
|
|
|
272
|
+
The projectors return line integrals in VOXEL units; the physics
|
|
273
|
+
(``exp(-p)`` transmission, beam-hardening nonlinearity) needs PHYSICAL
|
|
274
|
+
line integrals, so the projection is rescaled by ``voxel_spacing`` first
|
|
275
|
+
(taken from the operator's metadata when not given). The returned
|
|
276
|
+
sinogram is therefore physical (mu*mm) — like real measured -log data —
|
|
277
|
+
and identical to previous behaviour at ``voxel_spacing = 1``.
|
|
278
|
+
|
|
271
279
|
Returns the attenuation sinogram (default) or the raw photon counts
|
|
272
280
|
(``return_counts=True``).
|
|
273
281
|
"""
|
|
274
282
|
if float(I0) <= 0.0:
|
|
275
283
|
raise ValueError(f"I0 (incident photon count) must be positive, got {I0!r}.")
|
|
284
|
+
if voxel_spacing is None:
|
|
285
|
+
voxel_spacing = float(getattr(operator, "voxel_spacing", 1.0))
|
|
286
|
+
if float(voxel_spacing) <= 0.0:
|
|
287
|
+
raise ValueError(f"voxel_spacing must be positive, got {voxel_spacing!r}.")
|
|
276
288
|
x = xp.array(phantom, dtype=_b.float32)
|
|
277
|
-
|
|
289
|
+
# reference-energy line integrals, rescaled to physical units (mu*mm)
|
|
290
|
+
p = (operator @ x) * float(voxel_spacing)
|
|
278
291
|
if spectrum is not None and material_attenuation is not None:
|
|
279
292
|
p = apply_beam_hardening(p, spectrum, material_attenuation, reference_energy)
|
|
280
293
|
|
|
@@ -25,6 +25,7 @@ from .cases import (
|
|
|
25
25
|
build_fan_2d_case,
|
|
26
26
|
build_measured_cone_3d_case,
|
|
27
27
|
build_npy_cone_3d_case,
|
|
28
|
+
reconstruct_case_fdk,
|
|
28
29
|
build_parallel_2d_case,
|
|
29
30
|
make_cone_3d_operators,
|
|
30
31
|
make_fan_2d_operators,
|
|
@@ -98,6 +99,7 @@ __all__ = [
|
|
|
98
99
|
"build_cone_3d_case",
|
|
99
100
|
"build_measured_cone_3d_case",
|
|
100
101
|
"build_npy_cone_3d_case",
|
|
102
|
+
"reconstruct_case_fdk",
|
|
101
103
|
"make_parallel_2d_operators",
|
|
102
104
|
"make_fan_2d_operators",
|
|
103
105
|
"make_cone_3d_operators",
|
|
@@ -28,10 +28,20 @@ AnalyticalBackProjector = Callable[[Any], Any]
|
|
|
28
28
|
class AnalyticalReconstructionParameters:
|
|
29
29
|
"""Common parameters for analytical reconstruction algorithms."""
|
|
30
30
|
|
|
31
|
+
#: Physical detector pitch along the filter axis. Used as the ramp
|
|
32
|
+
#: filter's ``sample_spacing`` (``|f|/du``): leave at 1.0 for the legacy
|
|
33
|
+
#: DFT-bin convention that the case normalization constants assume; set to
|
|
34
|
+
#: the real pitch for quantitative pipelines.
|
|
31
35
|
detector_spacing: float = 1.0
|
|
32
36
|
voxel_spacing: float = 1.0
|
|
33
37
|
enforce_positivity: bool = True
|
|
34
38
|
normalization_scale: float | None = None
|
|
39
|
+
#: Zero-pad the detector axis to ``pad_factor * n`` before the ramp FFT.
|
|
40
|
+
#: Padding suppresses the circular-convolution wrap-around that depresses
|
|
41
|
+
#: large objects (object-size-DEPENDENT bias, up to 0.40x at 75 % FOV
|
|
42
|
+
#: coverage) — keep the default 2 unless you must reproduce legacy
|
|
43
|
+
#: unpadded results (set 1).
|
|
44
|
+
pad_factor: int = 2
|
|
35
45
|
dtype: Any = field(default_factory=lambda: _b.float32)
|
|
36
46
|
|
|
37
47
|
|
|
@@ -57,18 +67,38 @@ def default_angular_normalization(num_views: int) -> float:
|
|
|
57
67
|
return math.pi / float(num_views)
|
|
58
68
|
|
|
59
69
|
|
|
60
|
-
def _ramp_numpy(sino_np, axis):
|
|
61
|
-
"""CPU reference ramp filter (``2*|fftfreq
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
70
|
+
def _ramp_numpy(sino_np, axis, pad_factor=1, sample_spacing=1.0):
|
|
71
|
+
"""CPU reference ramp filter (``2*|fftfreq|/sample_spacing`` convention).
|
|
72
|
+
|
|
73
|
+
``pad_factor > 1`` zero-pads the detector axis to ``pad_factor * n`` before
|
|
74
|
+
the FFT and crops afterwards. Without padding the ramp's negative side
|
|
75
|
+
lobes wrap around (circular convolution) and depress the interior of
|
|
76
|
+
objects that fill a large fraction of the detector — the bias grows with
|
|
77
|
+
object size (measured: 0.94x/0.74x/0.40x of the true value for objects
|
|
78
|
+
covering 25/50/75 % of the FOV; with 2x padding 0.99x/0.94x/0.90x), so no
|
|
79
|
+
global constant can compensate it. ``sample_spacing`` rescales the DFT-bin
|
|
80
|
+
frequencies to physical units (``|f|/du``) for quantitative pipelines.
|
|
81
|
+
"""
|
|
82
|
+
n = sino_np.shape[axis]
|
|
83
|
+
n_pad = max(int(pad_factor), 1) * n
|
|
84
|
+
if n_pad > n:
|
|
85
|
+
pad_width = [(0, 0)] * sino_np.ndim
|
|
86
|
+
pad_width[axis] = (0, n_pad - n)
|
|
87
|
+
sino_np = np.pad(sino_np, pad_width)
|
|
88
|
+
freqs = np.fft.fftfreq(n_pad)
|
|
89
|
+
ramp = (2.0 * np.abs(freqs) / float(sample_spacing)).astype(np.float32)
|
|
65
90
|
shape = [1] * sino_np.ndim
|
|
66
|
-
shape[axis] =
|
|
91
|
+
shape[axis] = n_pad
|
|
67
92
|
sino_fft = np.fft.fft(sino_np, axis=axis)
|
|
68
|
-
|
|
93
|
+
filtered = np.real(np.fft.ifft(sino_fft * ramp.reshape(shape), axis=axis)).astype(np.float32)
|
|
94
|
+
if n_pad > n:
|
|
95
|
+
index = [slice(None)] * filtered.ndim
|
|
96
|
+
index[axis] = slice(0, n)
|
|
97
|
+
filtered = filtered[tuple(index)]
|
|
98
|
+
return filtered
|
|
69
99
|
|
|
70
100
|
|
|
71
|
-
def _ramp_device(sinogram, axis):
|
|
101
|
+
def _ramp_device(sinogram, axis, pad_factor=1, sample_spacing=1.0):
|
|
72
102
|
"""On-device ramp filter reproducing the ``2*|fftfreq|`` DFT convention.
|
|
73
103
|
|
|
74
104
|
Identical maths to :func:`_ramp_numpy` (same DFT-bin ramp — no ``2*pi`` and
|
|
@@ -77,17 +107,27 @@ def _ramp_device(sinogram, axis):
|
|
|
77
107
|
normalization constant (see ``cases.py``) is unchanged.
|
|
78
108
|
"""
|
|
79
109
|
n = int(sinogram.shape[axis])
|
|
80
|
-
|
|
81
|
-
|
|
110
|
+
n_pad = max(int(pad_factor), 1) * n
|
|
111
|
+
if n_pad > n:
|
|
112
|
+
pad_shape = [int(d) for d in sinogram.shape]
|
|
113
|
+
pad_shape[axis] = n_pad - n
|
|
114
|
+
sinogram = xp.concatenate(
|
|
115
|
+
[sinogram, xp.zeros(pad_shape, dtype=_b.float32)], axis=axis)
|
|
116
|
+
freqs = xp.fft.fftfreq(n_pad)
|
|
117
|
+
ramp = 2.0 * xp.abs(freqs) / float(sample_spacing)
|
|
82
118
|
shape = [1] * sinogram.ndim
|
|
83
|
-
shape[axis] =
|
|
119
|
+
shape[axis] = n_pad
|
|
84
120
|
ramp = xp.reshape(ramp, shape)
|
|
85
121
|
spectrum = xp.fft.fft(sinogram, axis=axis)
|
|
86
|
-
filtered = xp.fft.ifft(spectrum * ramp, axis=axis)
|
|
87
|
-
|
|
122
|
+
filtered = xp.real(xp.fft.ifft(spectrum * ramp, axis=axis))
|
|
123
|
+
if n_pad > n:
|
|
124
|
+
index = [slice(None)] * filtered.ndim
|
|
125
|
+
index[axis] = slice(0, n)
|
|
126
|
+
filtered = filtered[tuple(index)]
|
|
127
|
+
return filtered
|
|
88
128
|
|
|
89
129
|
|
|
90
|
-
def _ramp(sinogram, axis):
|
|
130
|
+
def _ramp(sinogram, axis, pad_factor=1, sample_spacing=1.0):
|
|
91
131
|
"""Ramp filter along ``axis`` — on-device when the backend exposes an FFT.
|
|
92
132
|
|
|
93
133
|
Falls back to the numpy reference (host round-trip) only if the backend has
|
|
@@ -96,31 +136,33 @@ def _ramp(sinogram, axis):
|
|
|
96
136
|
"""
|
|
97
137
|
if getattr(xp, "fft", None) is not None:
|
|
98
138
|
try:
|
|
99
|
-
return _ramp_device(_b.as_array(sinogram, dtype=_b.float32), axis
|
|
139
|
+
return _ramp_device(_b.as_array(sinogram, dtype=_b.float32), axis,
|
|
140
|
+
pad_factor=pad_factor, sample_spacing=sample_spacing)
|
|
100
141
|
except Exception: # pragma: no cover - defensive host fallback
|
|
101
142
|
pass
|
|
102
143
|
dev = _b.device_of(sinogram)
|
|
103
144
|
sino_np = _b.to_numpy(sinogram).astype(np.float32)
|
|
104
|
-
return _b.as_array(_ramp_numpy(sino_np, axis
|
|
145
|
+
return _b.as_array(_ramp_numpy(sino_np, axis, pad_factor=pad_factor,
|
|
146
|
+
sample_spacing=sample_spacing), device=dev)
|
|
105
147
|
|
|
106
148
|
|
|
107
|
-
def ramp_filter_2d(sinogram):
|
|
149
|
+
def ramp_filter_2d(sinogram, pad_factor=1, sample_spacing=1.0):
|
|
108
150
|
"""Apply a ramp filter along the detector axis of a 2D sinogram."""
|
|
109
151
|
sinogram = _b.as_array(sinogram, dtype=_b.float32)
|
|
110
152
|
if sinogram.ndim != 2:
|
|
111
153
|
raise ValueError(f"Expected a 2D sinogram, got shape {tuple(sinogram.shape)!r}.")
|
|
112
|
-
return _ramp(sinogram, 1)
|
|
154
|
+
return _ramp(sinogram, 1, pad_factor=pad_factor, sample_spacing=sample_spacing)
|
|
113
155
|
|
|
114
156
|
|
|
115
|
-
def ramp_filter_3d(sinogram):
|
|
157
|
+
def ramp_filter_3d(sinogram, pad_factor=1, sample_spacing=1.0):
|
|
116
158
|
"""Apply a ramp filter along the detector-u axis of a 3D cone sinogram."""
|
|
117
159
|
sinogram = _b.as_array(sinogram, dtype=_b.float32)
|
|
118
160
|
if sinogram.ndim != 3:
|
|
119
161
|
raise ValueError(f"Expected a 3D sinogram, got shape {tuple(sinogram.shape)!r}.")
|
|
120
|
-
return _ramp(sinogram, 1)
|
|
162
|
+
return _ramp(sinogram, 1, pad_factor=pad_factor, sample_spacing=sample_spacing)
|
|
121
163
|
|
|
122
164
|
|
|
123
|
-
def ramp_filter(sinogram, axis=1):
|
|
165
|
+
def ramp_filter(sinogram, axis=1, pad_factor=1, sample_spacing=1.0):
|
|
124
166
|
"""Apply a ramp filter along an arbitrary detector axis."""
|
|
125
167
|
sinogram = _b.as_array(sinogram, dtype=_b.float32)
|
|
126
168
|
if sinogram.ndim < 2:
|
|
@@ -130,4 +172,4 @@ def ramp_filter(sinogram, axis=1):
|
|
|
130
172
|
axis += sinogram.ndim
|
|
131
173
|
if axis < 0 or axis >= sinogram.ndim:
|
|
132
174
|
raise ValueError(f"Invalid filter axis {axis} for sinogram with ndim={sinogram.ndim}.")
|
|
133
|
-
return _ramp(sinogram, axis)
|
|
175
|
+
return _ramp(sinogram, axis, pad_factor=pad_factor, sample_spacing=sample_spacing)
|