ParallelProjectorFunction#
- class diffct.ParallelProjectorFunction(*args, **kwargs)[source]#
Bases:
FunctionSummary#
PyTorch autograd function for differentiable 2D parallel beam forward projection.
Notes
Provides a differentiable interface to the CUDA-accelerated Siddon ray-tracing method with a cell-constant image basis for parallel beam CT geometry. The forward pass computes the sinogram from a 2D image using parallel beam geometry. The backward pass computes gradients using the adjoint backprojection operation. Requires NVIDIA CUDA hardware. Geometry tensors are moved to the image’s device; execution uses float32.
Examples
>>> import torch >>> from diffct import ParallelProjectorFunction, circular_trajectory_2d_parallel >>> >>> image = torch.randn(128, 128, device='cuda', requires_grad=True) >>> ray_dir, det_origin, det_u_vec = circular_trajectory_2d_parallel(180, device='cuda') >>> sinogram = ParallelProjectorFunction.apply(image, ray_dir, det_origin, det_u_vec, 192, 1.0) >>> sinogram.sum().backward() >>> image.grad.shape torch.Size([128, 128])
- static forward(ctx, image, ray_dir, det_origin, det_u_vec, num_detectors, detector_spacing=1.0, voxel_spacing=1.0)[source]#
Compute the 2D parallel 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.
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).
num_detectors (int) – Number of detector elements in the sinogram (columns).
detector_spacing (float, optional) – Physical spacing between detector elements (default: 1.0).
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 forward projection (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 parallel beam geometries.
Uses cell-constant Siddon ray tracing.
Examples
>>> image = torch.randn(128, 128, device='cuda', requires_grad=True) >>> ray_dir, det_origin, det_u_vec = circular_trajectory_2d_parallel(180, device='cuda') >>> sinogram = ParallelProjectorFunction.apply( ... image, ray_dir, det_origin, det_u_vec, 128, 1.0 ... )
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any