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:
- SDR : Source-to-Detector radius (half of the source-to-detector distance)
- \(\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_angle
euler_angles
(note: also need to specify theconvention
for the Euler angles)matrix
quaternion
rotation_6d
(Zhou et al., 2019)rotation_10d
(Peretroukhin et al., 2021)quaternion_adjugate
(Hanson and Hanson, 2022)
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. The rotational parameters are detailed in Spherical Coordiantes Tutorial.
DRR
DRR (volume:numpy.ndarray, spacing:numpy.ndarray, sdr:float, height:int, delx:float, width:int|None=None, dely:float|None=None, p_subsample:float|None=None, reshape:bool=True, reverse_x_axis:bool=False, patch_size:int|None=None, bone_attenuation_multiplier:float=1.0)
PyTorch module that computes differentiable digitally reconstructed radiographs.
Type | Default | Details | |
---|---|---|---|
volume | np.ndarray | CT volume | |
spacing | np.ndarray | Dimensions of voxels in the CT volume | |
sdr | float | Source-to-detector radius for the C-arm (half of the source-to-detector distance) | |
height | int | Height of the rendered DRR | |
delx | float | X-axis pixel size | |
width | int | None | None | Width of the rendered DRR (if not provided, set to height ) |
dely | float | None | None | Y-axis pixel size (if not provided, set to delx ) |
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 | False | If pose includes reflection (in E(3) not SE(3)), reverse x-axis |
patch_size | int | None | None | If the entire DRR can’t fit in memory, render patches of the DRR in series |
bone_attenuation_multiplier | float | 1.0 | Contrast ratio of bone to soft tissue |
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.forward
DRR.forward (rotation:torch.Tensor, translation:torch.Tensor, parameterization:str, convention:str=None, pose:pytorch3d.transforms.transform3d.Transform3d=None, bone_attenuation_multiplier:float=None)
Generate DRR with rotational and translational parameters.
Type | Default | Details | |
---|---|---|---|
rotation | torch.Tensor | ||
translation | torch.Tensor | ||
parameterization | str | ||
convention | str | None | |
pose | Transform3d | None | If you have a preformed pose, can pass it directly |
bone_attenuation_multiplier | float | None | Contrast ratio of bone to soft tissue |
Registration
The Registration
module uses the DRR
module to perform differentiable 2D-to-3D registration. Initial guesses for the pose parameters are as stored as nn.Parameters
of the module. This allows the pose parameters to be optimized with any PyTorch optimizer. Furthermore, this design choice allows DRR
to be used purely as a differentiable renderer.
Registration
Registration (drr:__main__.DRR, rotation:torch.Tensor, translation:torch.Tensor, parameterization:str, input_convention:str=None, output_convention:str='ZYX')
Perform automatic 2D-to-3D registration using differentiable rendering.