FanProjectorFunction#
- class diffct.FanProjectorFunction(*args, **kwargs)[source]#
Bases:
FunctionSummary#
PyTorch autograd function for differentiable 2D fan beam forward projection.
Notes
Provides a differentiable interface to the CUDA-accelerated Siddon ray-tracing method with a cell-constant image basis for fan beam geometry, where rays diverge from a point X-ray source to a linear detector array. The forward pass computes sinograms using divergent beam geometry, and the backward pass computes gradients via adjoint backprojection.
Examples
>>> import torch >>> from diffct import FanProjectorFunction, circular_trajectory_2d_fan >>> >>> image = torch.randn(256, 256, 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') >>> sinogram = FanProjectorFunction.apply(image, src_pos, det_center, det_u_vec, 512, 1.0) >>> sinogram.sum().backward() >>> image.grad.shape torch.Size([256, 256])
- static forward(ctx, image, src_pos, det_center, det_u_vec, num_detectors, detector_spacing, voxel_spacing=1.0)[source]#
Compute the 2D fan beam forward projection with arbitrary trajectories using CUDA acceleration.
- Parameters:
image (torch.Tensor) – Floating-point CUDA image of shape (H, W), 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).
num_detectors (int) – Number of detector elements in the sinogram (columns).
detector_spacing (float) – Physical spacing between detector elements.
voxel_spacing (float, optional) – Physical size of one voxel (in same units as detector_spacing, default: 1.0).
- Returns:
sinogram – 2D tensor of shape (n_views, num_detectors) containing the fan beam sinogram on the same device as image.
- Return type:
torch.Tensor
Notes
Geometry tensors are moved to the image’s CUDA device and converted to float32.
Data derivatives support higher orders; geometry derivatives are first-order only.
Supports arbitrary fan beam geometries.
Uses cell-constant Siddon ray tracing.
Examples
>>> image = torch.randn(256, 256, device='cuda', requires_grad=True) >>> src_pos, det_center, det_u_vec = circular_trajectory_2d_fan(360, 1000.0, 1500.0, device='cuda') >>> sinogram = FanProjectorFunction.apply( ... image, src_pos, det_center, det_u_vec, 512, 1.0 ... )
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any