diffct-mlx 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diffct_mlx/__about__.py +3 -0
- diffct_mlx/__init__.py +223 -0
- diffct_mlx/constants.py +38 -0
- diffct_mlx/geometry.py +802 -0
- diffct_mlx/kernels/__init__.py +39 -0
- diffct_mlx/kernels/cone_beam.py +708 -0
- diffct_mlx/kernels/fan_beam.py +502 -0
- diffct_mlx/kernels/parallel_beam.py +431 -0
- diffct_mlx/phantoms/__init__.py +5 -0
- diffct_mlx/phantoms/shepp_logan.py +118 -0
- diffct_mlx/projectors.py +1084 -0
- diffct_mlx/real_measured_data_helper.py +601 -0
- diffct_mlx/reconstruction_algorithms/__init__.py +85 -0
- diffct_mlx/reconstruction_algorithms/_analytic.py +101 -0
- diffct_mlx/reconstruction_algorithms/_core.py +872 -0
- diffct_mlx/reconstruction_algorithms/asd_pocs.py +114 -0
- diffct_mlx/reconstruction_algorithms/awtv_pocs.py +106 -0
- diffct_mlx/reconstruction_algorithms/cases.py +988 -0
- diffct_mlx/reconstruction_algorithms/dart.py +424 -0
- diffct_mlx/reconstruction_algorithms/fbp.py +69 -0
- diffct_mlx/reconstruction_algorithms/fdk.py +67 -0
- diffct_mlx/reconstruction_algorithms/sart.py +66 -0
- diffct_mlx/reconstruction_algorithms/sirt.py +64 -0
- diffct_mlx/reconstruction_algorithms/tv_pocs.py +85 -0
- diffct_mlx/regularizers.py +122 -0
- diffct_mlx/tv_gradients.py +74 -0
- diffct_mlx/utils.py +64 -0
- diffct_mlx-1.0.1.dist-info/METADATA +315 -0
- diffct_mlx-1.0.1.dist-info/RECORD +31 -0
- diffct_mlx-1.0.1.dist-info/WHEEL +4 -0
- diffct_mlx-1.0.1.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Geometry-agnostic ASD-POCS reconstruction."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Sequence
|
|
7
|
+
|
|
8
|
+
import mlx.core as mx
|
|
9
|
+
|
|
10
|
+
from ..regularizers import asd_pocs as asd_pocs_step
|
|
11
|
+
from ._core import (
|
|
12
|
+
ArrayLike,
|
|
13
|
+
BackProjector,
|
|
14
|
+
ForwardProjector,
|
|
15
|
+
ReconstructionParameters,
|
|
16
|
+
RegularizationParameters,
|
|
17
|
+
clamp_reconstruction_volume,
|
|
18
|
+
initialize_volume,
|
|
19
|
+
normalize_measured_projections,
|
|
20
|
+
print_progress,
|
|
21
|
+
projection_order,
|
|
22
|
+
projection_residual_norm,
|
|
23
|
+
run_iterative_sweeps,
|
|
24
|
+
scalar_norm,
|
|
25
|
+
validate_reconstruction_inputs,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class ASDPOCSParameters(RegularizationParameters):
|
|
31
|
+
"""ASD-POCS regularization parameters."""
|
|
32
|
+
|
|
33
|
+
epsilon: float = 5.0
|
|
34
|
+
r_max: float = 0.95
|
|
35
|
+
alpha_red: float = 0.95
|
|
36
|
+
beta: float = 1.0
|
|
37
|
+
beta_red: float = 0.995
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
ASD_POCS_Parameter = ASDPOCSParameters
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def reconstruct_asd_pocs(
|
|
44
|
+
measured_projections: Sequence[ArrayLike],
|
|
45
|
+
forward_project: ForwardProjector,
|
|
46
|
+
back_project: BackProjector,
|
|
47
|
+
reco_params: ReconstructionParameters,
|
|
48
|
+
reg_params: ASDPOCSParameters,
|
|
49
|
+
*,
|
|
50
|
+
show_progress: bool = False,
|
|
51
|
+
) -> mx.array:
|
|
52
|
+
"""Reconstruct with ASD-POCS using user-provided per-view operators."""
|
|
53
|
+
validate_reconstruction_inputs(reco_params, measured_projections)
|
|
54
|
+
measured = normalize_measured_projections(measured_projections, reco_params.dtype)
|
|
55
|
+
order = projection_order(reco_params, len(measured))
|
|
56
|
+
volume, ones_volume, zero_volume = initialize_volume(reco_params)
|
|
57
|
+
|
|
58
|
+
beta = float(reg_params.beta)
|
|
59
|
+
dtvg = 0.0
|
|
60
|
+
first_projection_index = order[0]
|
|
61
|
+
|
|
62
|
+
for iteration in range(reco_params.iteration_count):
|
|
63
|
+
skip_first_sart = iteration == 0 and reco_params.initial_volume is not None
|
|
64
|
+
iteration_reference = zero_volume if skip_first_sart else volume
|
|
65
|
+
|
|
66
|
+
if not skip_first_sart:
|
|
67
|
+
volume = run_iterative_sweeps(
|
|
68
|
+
volume=volume,
|
|
69
|
+
measured_projections=measured,
|
|
70
|
+
ones_volume=ones_volume,
|
|
71
|
+
forward_project=forward_project,
|
|
72
|
+
back_project=back_project,
|
|
73
|
+
params=reco_params,
|
|
74
|
+
beta=beta,
|
|
75
|
+
outer_iteration_index=iteration,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
volume = clamp_reconstruction_volume(volume, reco_params, stage="iteration")
|
|
79
|
+
|
|
80
|
+
if reg_params.reg_iteration_count > 0 and iteration < (reco_params.iteration_count - 1):
|
|
81
|
+
dd = projection_residual_norm(
|
|
82
|
+
volume,
|
|
83
|
+
measured[first_projection_index],
|
|
84
|
+
forward_project,
|
|
85
|
+
first_projection_index,
|
|
86
|
+
)
|
|
87
|
+
volume, _, dtvg = asd_pocs_step(
|
|
88
|
+
volume,
|
|
89
|
+
iteration_reference,
|
|
90
|
+
iteration,
|
|
91
|
+
reg_params.reg_iteration_count,
|
|
92
|
+
dd,
|
|
93
|
+
dtvg,
|
|
94
|
+
reg_params.alpha,
|
|
95
|
+
reg_params.alpha_red,
|
|
96
|
+
reg_params.r_max,
|
|
97
|
+
reg_params.epsilon,
|
|
98
|
+
eta=reg_params.tv_eps,
|
|
99
|
+
)
|
|
100
|
+
volume = clamp_reconstruction_volume(volume, reco_params, stage="regularization")
|
|
101
|
+
|
|
102
|
+
beta *= float(reg_params.beta_red)
|
|
103
|
+
|
|
104
|
+
mx.eval(volume)
|
|
105
|
+
|
|
106
|
+
if show_progress:
|
|
107
|
+
print_progress(iteration, reco_params.iteration_count)
|
|
108
|
+
|
|
109
|
+
volume = clamp_reconstruction_volume(volume, reco_params, stage="final")
|
|
110
|
+
mx.eval(volume)
|
|
111
|
+
return volume
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
run_asd_pocs = reconstruct_asd_pocs
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Geometry-agnostic AwTV-POCS reconstruction."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Sequence
|
|
7
|
+
|
|
8
|
+
import mlx.core as mx
|
|
9
|
+
import numpy as np
|
|
10
|
+
|
|
11
|
+
from ..regularizers import awtv_pocs as awtv_pocs_step
|
|
12
|
+
from ._core import (
|
|
13
|
+
ArrayLike,
|
|
14
|
+
BackProjector,
|
|
15
|
+
ForwardProjector,
|
|
16
|
+
ReconstructionParameters,
|
|
17
|
+
RegularizationParameters,
|
|
18
|
+
clamp_reconstruction_volume,
|
|
19
|
+
initialize_volume,
|
|
20
|
+
normalize_measured_projections,
|
|
21
|
+
print_progress,
|
|
22
|
+
projection_order,
|
|
23
|
+
run_iterative_sweeps,
|
|
24
|
+
validate_reconstruction_inputs,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass
|
|
29
|
+
class AwTVPOCSParameters(RegularizationParameters):
|
|
30
|
+
"""AwTV-POCS regularization parameters."""
|
|
31
|
+
|
|
32
|
+
epsilon: float = 1.0
|
|
33
|
+
delta: float = 0.6e-2
|
|
34
|
+
beta: float = 1.0
|
|
35
|
+
beta_red: float = 0.995
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
AwTV_POCS_Parameter = AwTVPOCSParameters
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def reconstruct_awtv_pocs(
|
|
42
|
+
measured_projections: Sequence[ArrayLike],
|
|
43
|
+
forward_project: ForwardProjector,
|
|
44
|
+
back_project: BackProjector,
|
|
45
|
+
reco_params: ReconstructionParameters,
|
|
46
|
+
reg_params: AwTVPOCSParameters,
|
|
47
|
+
*,
|
|
48
|
+
show_progress: bool = False,
|
|
49
|
+
) -> mx.array:
|
|
50
|
+
"""Reconstruct with AwTV-POCS using user-provided per-view operators."""
|
|
51
|
+
validate_reconstruction_inputs(reco_params, measured_projections)
|
|
52
|
+
measured = normalize_measured_projections(measured_projections, reco_params.dtype)
|
|
53
|
+
order = projection_order(reco_params, len(measured))
|
|
54
|
+
volume, ones_volume, zero_volume = initialize_volume(reco_params)
|
|
55
|
+
|
|
56
|
+
beta = float(reg_params.beta)
|
|
57
|
+
previous_pocs_projection = None
|
|
58
|
+
first_projection_index = order[0]
|
|
59
|
+
|
|
60
|
+
for iteration in range(reco_params.iteration_count):
|
|
61
|
+
skip_first_sart = iteration == 0 and reco_params.initial_volume is not None
|
|
62
|
+
iteration_reference = zero_volume if skip_first_sart else volume
|
|
63
|
+
|
|
64
|
+
if not skip_first_sart:
|
|
65
|
+
volume = run_iterative_sweeps(
|
|
66
|
+
volume=volume,
|
|
67
|
+
measured_projections=measured,
|
|
68
|
+
ones_volume=ones_volume,
|
|
69
|
+
forward_project=forward_project,
|
|
70
|
+
back_project=back_project,
|
|
71
|
+
params=reco_params,
|
|
72
|
+
beta=beta,
|
|
73
|
+
outer_iteration_index=iteration,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
volume = clamp_reconstruction_volume(volume, reco_params, stage="iteration")
|
|
77
|
+
|
|
78
|
+
if reg_params.reg_iteration_count > 0:
|
|
79
|
+
current_pocs_projection = forward_project(volume, first_projection_index)
|
|
80
|
+
if previous_pocs_projection is not None:
|
|
81
|
+
ds = float(np.asarray(mx.linalg.norm(previous_pocs_projection - current_pocs_projection)))
|
|
82
|
+
if ds < float(reg_params.epsilon):
|
|
83
|
+
beta *= float(reg_params.beta_red)
|
|
84
|
+
|
|
85
|
+
volume, _, _ = awtv_pocs_step(
|
|
86
|
+
volume,
|
|
87
|
+
iteration_reference,
|
|
88
|
+
reg_params.reg_iteration_count,
|
|
89
|
+
reg_params.alpha,
|
|
90
|
+
reg_params.delta,
|
|
91
|
+
eta=reg_params.tv_eps,
|
|
92
|
+
)
|
|
93
|
+
volume = clamp_reconstruction_volume(volume, reco_params, stage="regularization")
|
|
94
|
+
previous_pocs_projection = current_pocs_projection
|
|
95
|
+
|
|
96
|
+
mx.eval(volume)
|
|
97
|
+
|
|
98
|
+
if show_progress:
|
|
99
|
+
print_progress(iteration, reco_params.iteration_count)
|
|
100
|
+
|
|
101
|
+
volume = clamp_reconstruction_volume(volume, reco_params, stage="final")
|
|
102
|
+
mx.eval(volume)
|
|
103
|
+
return volume
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
run_awtv_pocs = reconstruct_awtv_pocs
|