DRR
DRR
DRR is a PyTorch module that compues differentiable digitally reconstructed radiographs. The viewing angle for the DRR (known generally in computer graphics as the camera pose) is parameterized by the following parameters:
- SDD : source-to-detector distance (i.e., the focal length of the C-arm)
- \(\mathbf R \in \mathrm{SO}(3)\) : a rotation
- \(\mathbf t \in \mathbb R^3\) : a translation
DiffDRR can take a rotation parameterized in any of the following forms to move the detector plane:
axis_angleeuler_angles(note: also need to specify theconventionfor the Euler angles)matrixquaternionquaternion_adjugate(Hanson and Hanson, 2022)rotation_6d(Zhou et al., 2019)rotation_10d(Peretroukhin et al., 2021)`se3_log_map
If using Euler angles, the parameters are
alpha: Azimuthal anglebeta: Polar anglegamma: Plane rotation anglebx: X-dir translationby: Y-dir translationbz: Z-dir translationconvention: Order of angles (e.g.,ZYX)
(bx, by, bz) are translational parameters and (alpha, beta, gamma) are rotational parameters.
DRR
def DRR(
subject:Subject, # TorchIO wrapper for the CT volume
sdd:float, # Source-to-detector distance (i.e., the C-arm's focal length)
height:int, # Height of the rendered DRR
delx:float, # X-axis pixel size
width:int | None=None, # Width of the rendered DRR (default to `height`)
dely:float | None=None, # Y-axis pixel size (if not provided, set to `delx`)
x0:float=0.0, # Principal point X-offset
y0:float=0.0, # Principal point Y-offset
p_subsample:float | None=None, # Proportion of pixels to randomly subsample
reshape:bool=True, # Return DRR with shape (b, 1, h, w)
reverse_x_axis:bool=True, # If True, obey radiologic convention (e.g., heart on right)
patch_size:int | None=None, # Render patches of the DRR in series
renderer:str='siddon', # Rendering backend, either "siddon" or "trilinear"
voxel_shift:float=0.5, # 0 or 0.5, depending if the voxel is at the top left corner or the center
persistent:bool=True, # Set persistent value in `torch.nn.Module.register_buffer`
compile_renderer:bool=False, # Compile the renderer for performance boost
checkpoint_gradients:bool=False, # Checkpoint gradients to improve memory usage
renderer_kwargs:VAR_KEYWORD
):
PyTorch module that computes differentiable digitally reconstructed radiographs.
The forward pass of the DRR module generated DRRs from the input CT volume. The pose parameters (i.e., viewing angles) from which the DRRs are generated are passed to the forward call.
DRR.render
def render(
density:torch.tensor, # Volume from which to render DRRs
source:torch.tensor, # World coordinates of X-ray source
target:torch.tensor, # World coordinates of X-ray target
mask_to_channels:bool=False, # If True, structures from the CT mask are rendered in separate channels
kwargs:VAR_KEYWORD
):
DRR.forward
def forward(
args:VAR_POSITIONAL, # Some batched representation of SE(3)
parameterization:str=None, # Specifies the representation of the rotation
convention:str=None, # If parameterization is Euler angles, specify convention
calibration:RigidTransform=None, # Optional calibration matrix with the detector's intrinsic parameters
mask_to_channels:bool=False, # If True, structures from the CT mask are rendered in separate channels
degrees:bool=False, # If parameterization is Euler angles, use degrees instead of radians
kwargs:VAR_KEYWORD
):
Generate DRR with rotational and translational parameters.
DRR.rescale_detector_
def rescale_detector_(
scale:float
):
Rescale the detector plane (inplace).
DRR.perspective_projection
def perspective_projection(
pose:RigidTransform, pts:torch.Tensor
):
Project points in world coordinates (3D) onto the pixel plane (2D).
DRR.inverse_projection
def inverse_projection(
pose:RigidTransform, pts:torch.Tensor
):
Backproject points in pixel plane (2D) onto the image plane in world coordinates (3D).