visualization
2D Visualization
Uses matplotlib
and imageio
to plot DRRs and animate optimization over DRRs.
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.
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.
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 | 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.
drr_to_mesh
drr_to_mesh (subject:torchio.data.subject.Subject, method:str, threshold:float=150, extract_largest:bool=True, 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:
- Keep only largest connected components (optional)
- Smooth
- Decimate (if
method=="marching_cubes"
) - Fill any holes
- 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 | 150 | Min value for marching cubes (Hounsfield units) |
extract_largest | bool | True | Extract the largest connected component from the mesh |
verbose | bool | True | Display progress bars for mesh processing steps |
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 |
img_to_mesh
img_to_mesh (drr:diffdrr.drr.DRR, pose:diffdrr.pose.RigidTransform, calibration:diffdrr.pose.RigidTransform=None, **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.