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 using save_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 calls plt.show() with blocking (outside notebook environments). If this is undesired simply use fig = plot(..., show=False, return_fig=True) and plot at your desired location using fig.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 of img_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:#

Stacking and concatenating forward operators.

Stacking and concatenating forward operators.

Reconstructing an image using the deep image prior.

Reconstructing an image using the deep image prior.

Creating your own dataset

Creating your own dataset

Image transforms for equivariance & augmentations

Image transforms for equivariance & augmentations

Using huggingface dataset

Using huggingface dataset

Creating a forward operator.

Creating a forward operator.

3D diffraction PSF

3D diffraction PSF

A tour of forward sensing operators

A tour of forward sensing operators

A tour of blur operators

A tour of blur operators

Random phase retrieval and reconstruction methods.

Random phase retrieval and reconstruction methods.

Image deblurring with Total-Variation (TV) prior

Image deblurring with Total-Variation (TV) prior

Image inpainting with wavelet prior

Image inpainting with wavelet prior

3D wavelet denoising

3D wavelet denoising

Plug-and-Play algorithm with Mirror Descent for Poisson noise inverse problems.

Plug-and-Play algorithm with Mirror Descent for Poisson noise inverse problems.

Vanilla PnP for computed tomography (CT).

Vanilla PnP for computed tomography (CT).

PnP with custom optimization algorithm (Condat-Vu Primal-Dual)

PnP with custom optimization algorithm (Condat-Vu Primal-Dual)

Uncertainty quantification with PnP-ULA.

Uncertainty quantification with PnP-ULA.

Image reconstruction with a diffusion model

Image reconstruction with a diffusion model

Building your custom sampling algorithm.

Building your custom sampling algorithm.

Implementing DPS

Implementing DPS

Implementing DiffPIR

Implementing DiffPIR

Learned Iterative Soft-Thresholding Algorithm (LISTA) for compressed sensing

Learned Iterative Soft-Thresholding Algorithm (LISTA) for compressed sensing

Vanilla Unfolded algorithm for super-resolution

Vanilla Unfolded algorithm for super-resolution

Learned iterative custom prior

Learned iterative custom prior

Deep Equilibrium (DEQ) algorithms for image deblurring

Deep Equilibrium (DEQ) algorithms for image deblurring

Expected Patch Log Likelihood (EPLL) for Denoising and Inpainting

Expected Patch Log Likelihood (EPLL) for Denoising and Inpainting

Patch priors for limited-angle computed tomography

Patch priors for limited-angle computed tomography

Image transformations for Equivariant Imaging

Image transformations for Equivariant Imaging

Self-supervised MRI reconstruction with Artifact2Artifact

Self-supervised MRI reconstruction with Artifact2Artifact

Radio interferometric imaging with deepinverse

Radio interferometric imaging with deepinverse