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, cmap:str='gray',
           **imshow_kwargs)

Plot an image generated by a DRR module.


source

plot_mask

 plot_mask (img:torch.Tensor, axs:matplotlib.axes._axes.Axes,
            colors=['rgb(102,194,165)', 'rgb(252,141,98)',
            'rgb(141,160,203)', 'rgb(231,138,195)', 'rgb(166,216,84)',
            'rgb(255,217,47)', 'rgb(229,196,148)'], alpha=0.625,
            return_masks=False)

Plot a 2D rendered segmentation mask. Meant to be called after plot_drr.


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,
          dtype=torch.float32, 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
dtype dtype torch.float32
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 (subject:torchio.data.subject.Subject, method:str,
              threshold:float=300, verbose:bool=True)

Convert the CT in a DRR object into a mesh.

If using method=="surface_nets", ensure you have pyvista>=0.43 and vtk>=9.3 installed.

The mesh processing steps are:

  1. Keep only largest connected components
  2. Smooth
  3. Decimate (if method=="marching_cubes")
  4. Fill any holes
  5. Clean (remove any redundant vertices/edges)
Type Default Details
subject Subject torchio.Subject with a volume attribute
method str Either surface_nets or marching_cubes
threshold float 300 Min value for marching cubes (Hounsfield units)
verbose bool True Display progress bars for mesh processing steps

source

labelmap_to_mesh

 labelmap_to_mesh (subject:torchio.data.subject.Subject,
                   verbose:bool=True)
Type Default Details
subject Subject torchio.Subject with a mask attribute
verbose bool True Display progress bars for mesh processing steps

source

img_to_mesh

 img_to_mesh (drr:diffdrr.drr.DRR, pose:diffdrr.pose.RigidTransform,
              **kwargs)

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.