ParallelBackprojectorFunction#
- class diffct.ParallelBackprojectorFunction(*args, **kwargs)[source]#
Bases:
FunctionSummary#
PyTorch autograd function for differentiable 2D parallel beam backprojection.
Notes
Provides a differentiable interface to the CUDA-accelerated Siddon ray-tracing method with a cell-constant image basis for parallel beam backprojection. The forward pass computes a 2D reconstruction from sinogram data using parallel beam backprojection, and the backward pass computes gradients via forward projection as the adjoint operation. Requires CUDA-capable hardware and consistent device placements.
Examples
>>> import torch >>> from diffct import ParallelBackprojectorFunction, circular_trajectory_2d_parallel >>> >>> sinogram = torch.randn(180, 192, device='cuda', requires_grad=True) >>> ray_dir, det_origin, det_u_vec = circular_trajectory_2d_parallel(180, device='cuda') >>> image = ParallelBackprojectorFunction.apply(sinogram, ray_dir, det_origin, det_u_vec, 1.0, 128, 128) >>> image.sum().backward() >>> sinogram.grad.shape torch.Size([180, 192])
- static forward(ctx, sinogram, ray_dir, det_origin, det_u_vec, detector_spacing=1.0, H=128, W=128, voxel_spacing=1.0)[source]#
Compute the 2D parallel beam backprojection with arbitrary trajectories using CUDA acceleration.
- Parameters:
sinogram (torch.Tensor) – Floating-point CUDA sinogram of shape (n_views, num_detectors), converted to float32 for execution.
ray_dir (torch.Tensor) – Ray direction unit vectors for each view, shape (n_views, 2).
det_origin (torch.Tensor) – Detector origin positions for each view, shape (n_views, 2), in physical units.
det_u_vec (torch.Tensor) – Detector u-direction unit vectors for each view, shape (n_views, 2).
detector_spacing (float, optional) – Physical spacing between detector elements (default: 1.0).
H (int, optional) – Height of the output reconstruction image (default: 128).
W (int, optional) – Width of the output reconstruction image (default: 128).
voxel_spacing (float, optional) – Physical size of one voxel (in same units as detector_spacing, default: 1.0).
- Returns:
reco – 2D tensor of shape (H, W) containing the reconstructed image on the same device as sinogram.
- Return type:
torch.Tensor
Notes
Geometry tensors are moved to the sinogram’s CUDA device and converted to float32.
Data derivatives support higher orders; geometry derivatives are first-order only.
Supports arbitrary parallel beam geometries.
Uses the adjoint of cell-constant Siddon ray tracing.
Examples
>>> sinogram = torch.randn(180, 128, device='cuda', requires_grad=True) >>> ray_dir, det_origin, det_u_vec = circular_trajectory_2d_parallel(180, device='cuda') >>> reco = ParallelBackprojectorFunction.apply( ... sinogram, ray_dir, det_origin, det_u_vec, 1.0, 128, 128 ... )
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any