FanBackprojectorFunction#
- class diffct.FanBackprojectorFunction(*args, **kwargs)[source]#
Bases:
FunctionSummary#
PyTorch autograd function for differentiable 2D fan beam backprojection.
Notes
Provides a differentiable interface to the CUDA-accelerated Siddon ray-tracing method with a cell-constant image basis for fan beam backprojection. Implements the adjoint of the fan beam projection operator, distributing sinogram values back into the reconstruction volume along divergent ray paths. The forward pass computes reconstruction from sinogram data, and the backward pass computes gradients via forward projection.
Examples
>>> import torch >>> from diffct import FanBackprojectorFunction, circular_trajectory_2d_fan >>> >>> sinogram = torch.randn(360, 512, device='cuda', requires_grad=True) >>> src_pos, det_center, det_u_vec = circular_trajectory_2d_fan(360, sid=1000.0, sdd=1500.0, device='cuda') >>> image = FanBackprojectorFunction.apply(sinogram, src_pos, det_center, det_u_vec, 1.0, 256, 256) >>> image.sum().backward() >>> sinogram.grad.shape torch.Size([360, 512])
- static forward(ctx, sinogram, src_pos, det_center, det_u_vec, detector_spacing, H, W, voxel_spacing=1.0)[source]#
Compute the 2D fan beam backprojection with arbitrary trajectories using CUDA acceleration.
- Parameters:
sinogram (torch.Tensor) – Floating-point CUDA fan sinogram of shape (n_views, num_detectors), converted to float32 for execution.
src_pos (torch.Tensor) – Source positions for each view, shape (n_views, 2), in physical units.
det_center (torch.Tensor) – Detector center 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) – Physical spacing between detector elements.
H (int) – Height of the output reconstruction image.
W (int) – Width of the output reconstruction image.
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 fan beam geometries.
Uses the adjoint of cell-constant Siddon ray tracing.
Examples
>>> sinogram = torch.randn(360, 512, device='cuda', requires_grad=True) >>> src_pos, det_center, det_u_vec = circular_trajectory_2d_fan(360, 1000.0, 1500.0, device='cuda') >>> reco = FanBackprojectorFunction.apply( ... sinogram, src_pos, det_center, det_u_vec, 1.0, 256, 256 ... )
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any