In [20]:
%matplotlib inline
import numpy as np
from scipy.misc import imread
from plt_utils import *
In [21]:
# img = np.array(data.lena()).astype('uint8')
img = imread('ducks.jpg')
img_float = img.astype('float32')
img_float_gray = img.mean(-1) # will be float type
img_stacked = np.concatenate((img, img), axis=2)
Display 2D arrays as a grayscale image (or as a heatmap).
In [22]:
# basic use case
grayshow(img_float_gray)
In [23]:
# inputs are always scaled to be between 0 and 1 before displaying
# (also: british spelling)
greyshow(img_float_gray*400)
In [24]:
# can also display as a heatmap
grayshow(img_float_gray, heat=True)
In [25]:
# clip values in array before displaying
grayshow(img_float_gray, clip=[0, 125])
Display a 3D NxMx3 array as a color (RGB) image.
In [26]:
# basic use case (uint8 array)
colorshow(img)
In [27]:
# float inputs are scale to be between 0 and 1 before displaying
colorshow(img_float*400)
Convenience wrapper around grayshow and colorshow that "does the right thing" (most of the time).
In [28]:
# display 2D array as grayscale image
imshow(img_float_gray)
In [29]:
# display 3D array with 3 channels as RGB image
imshow(img)
In [30]:
# Float inputs are scaled to be between 0 and 1 before display
imshow(img_float*1000)
In [31]:
# display 3D array with 3 channels as mosaic of separate channels
imshow(img, split=True)
In [32]:
# display 3D array with number of channels != 3 as mosaic of separate channels
imshow(img_stacked)
Stitch multiple images (of the same shape) into one.
In [33]:
# display a list of color images in a mosaic
imshow(mosaic([img]*5))
In [34]:
# control how images get stitched together
imshow(mosaic([img]*15, padding=50, num_row=2))
In [35]:
# display a list of grayscale images
imshow(mosaic([img_float_gray]*5))
In [36]:
# if images have different ranges, it might be difficult to
# see some of them after stitching
imshow(mosaic([img_float_gray, img_float_gray*2, img_float_gray*3], num_row=1))
In [37]:
# can normalize to (0,1) and/or clip images before stitching together
imshow(mosaic([img_float_gray, img_float_gray*2, img_float_gray*3], num_row=1, normalize=True, clip=(.3,.5)))
In [38]:
# can do the same for color images
imshow(mosaic([img_float, img_float*2, img_float*3], num_row=1, normalize=True))