visualization

Visualize and animate DRRs in 2D and 3D

2D Visualization

Uses matplotlib and imageio to plot DRRs and animate optimization over DRRs.


source

plot_drr

 plot_drr (img:torch.Tensor, title:str|None=None, ticks:bool|None=True,
           axs:matplotlib.axes._axes.Axes|None=None)

Plot an image generated by a DRR module.


source

animate

 animate (out:str|pathlib.Path, df:pandas.core.frame.DataFrame,
          drr:diffdrr.drr.DRR, parameterization:str, convention:str=None,
          ground_truth:torch.Tensor|None=None, verbose:bool=True,
          device='cpu', **kwargs)

Animate the optimization of a DRR.

Type Default Details
out str | pathlib.Path Savepath
df pandas.DataFrame
drr DRR
parameterization str
convention str None
ground_truth torch.Tensor | None None
verbose bool True
device str cpu
kwargs

df is a pandas.DataFrame with columns ["alpha", "beta", "gamma", "bx", "by", "bz"]. Each row in df is an iteration of optimization with the updated values for that timestep.

3D Visualization

Uses pyvista and trame to interactively visualize DRR geometry in 3D.


source

drr_to_mesh

 drr_to_mesh (drr:diffdrr.drr.DRR, threshold:float=0.2, verbose:bool=True)

Convert the CT in a DRR object into a mesh.

Mesh processing steps:

  1. Keep only largest connected components
  2. Smooth
  3. Decimate
  4. Fill any holes
  5. Clean (remove any redundant vertices/edges)
Type Default Details
drr DRR
threshold float 0.2 Min value for marching cubes
verbose bool True Display progress bars for mesh processing steps

source

img_to_mesh

 img_to_mesh (drr:diffdrr.drr.DRR, rotations, translations,
              parameterization, convention=None)

For a given pose (not batched), turn the camera and detector into a mesh. Additionally, render the DRR for the pose. Convert into a texture that can be applied to the detector mesh.