Module for computing digitally reconstructed radiographs
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
Tip
DiffDRR can take a rotation parameterized in any of the following forms to move the detector plane:
axis_angle
euler_angles (note: also need to specify the convention for the Euler angles)
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):
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.
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):
def forward(*args, # 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):
Generate DRR with rotational and translational parameters.