Functions and utilites to display Images
import torch
from fastcore.test import *
from PIL import Image
_, axs = subplots()
test_eq(axs.shape, [1])
plt.close()
_, axs = subplots(2, 3)
test_eq(axs.shape, [2, 3])
plt.close()
show_image
can show PIL images...
im = Image.open("images/puppy.jpg")
ax = show_image(im, cmap="Greys", figsize=(2, 2))
...and color images with standard CHW dim order...
im2 = np.array(Image.open("images/puppy.jpg"))
ax = show_image(im2, figsize=(2, 2))
... also color images with HWC dim order...
im3 = torch.as_tensor(im2).permute(2, 0, 1)
ax = show_image(im3, figsize=(2, 2))
show_titled_image((im3, "A puppy"), figsize=(2, 2))
Show all images ims
as subplots with rows
using titles
. suptitle provides a way to create a figure title for all images. If you use suptitle
, constrained_layout
is used unless you set constrained_layout
to False.
show_images((im2, im3), titles=("puppy", "puppy"), suptitle="Image", imsize=3)
imshow_tensors
uses torchvision.utils.make_grid
to create a grid of Images from tensors and displays them.
batch = torch.from_numpy(np.hstack([im2, im2])).permute(2, 0, 1)
imshow_tensors(batch, normalize=False, nrow=1)