plot
- deepinv.utils.plot(img_list, titles=None, save_fn=None, save_dir=None, tight=True, max_imgs=4, rescale_mode='min_max', show=True, figsize=None, suptitle=None, cmap='gray', fontsize=17, interpolation='none', cbar=False, dpi=1200, fig=None, axs=None, return_fig=False, return_axs=False)[source]
Plots a list of images.
The images should be of shape [B,C,H,W] or [C, H, W], where B is the batch size, C is the number of channels, H is the height and W is the width. The images are plotted in a grid, where the number of rows is B and the number of columns is the length of the list. If the B is bigger than max_imgs, only the first batches are plotted.
Warning
If the number of channels is 2, the magnitude of the complex images is plotted. If the number of channels is bigger than 3, only the first 3 channels are plotted.
We provide flexibility to save plots either side-by-side using
save_fn
or as individual images usingsave_dir
.Example usage:
import torch from deepinv.utils import plot img = torch.rand(4, 3, 256, 256) plot([img, img, img], titles=["img1", "img2", "img3"], save_dir="test.png")
Note
Using
show=True
callsplt.show()
with blocking (outside notebook environments). If this is undesired simply usefig = plot(..., show=False, return_fig=True)
and plot at your desired location usingfig.show()
.- Parameters:
img_list (list[torch.Tensor], dict[str -> torch.Tensor], torch.Tensor) – list of images, single image, or dict of titles: images to plot.
titles (list[str], str, None) – list of titles for each image, has to be same length as img_list.
save_fn (None, str, Path) – path to save the plot as a single image (i.e. side-by-side).
save_dir (None, str, Path) – path to save the plots as individual images.
tight (bool) – use tight layout.
max_imgs (int) – maximum number of images to plot.
rescale_mode (str) – rescale mode, either ‘min_max’ (images are linearly rescaled between 0 and 1 using their min and max values) or ‘clip’ (images are clipped between 0 and 1).
show (bool) – show the image plot.
figsize (tuple[int]) – size of the figure. If
None
, calculated from the size ofimg_list
.suptitle (str) – title of the figure.
cmap (str) – colormap to use for the images. Default: gray
interpolation (str) – interpolation to use for the images. See https://matplotlib.org/stable/gallery/images_contours_and_fields/interpolation_methods.html for more details. Default: none
dpi (int) – DPI to save images.
Figure (None,) – matplotlib Figure object to plot on. If None, create new Figure. Defaults to None.
Axes (None,) – matplotlib Axes object to plot on. If None, create new Axes. Defaults to None.
return_fig (bool) – return the figure object.
return_axs (bool) – return the axs object.
Examples using plot
:
Radio interferometric imaging with deepinverse
Stacking and concatenating forward operators.
Reconstructing an image using the deep image prior.
Image transforms for equivariance & augmentations
A tour of forward sensing operators
Random phase retrieval and reconstruction methods.
Image deblurring with Total-Variation (TV) prior
Image inpainting with wavelet prior
Expected Patch Log Likelihood (EPLL) for Denoising and Inpainting
Patch priors for limited-angle computed tomography
Vanilla PnP for computed tomography (CT).
PnP with custom optimization algorithm (Condat-Vu Primal-Dual)
Uncertainty quantification with PnP-ULA.
Image reconstruction with a diffusion model
Building your custom sampling algorithm.
Image transformations for Equivariant Imaging
Self-supervised MRI reconstruction with Artifact2Artifact
Learned Iterative Soft-Thresholding Algorithm (LISTA) for compressed sensing
Learned iterative custom prior