SciPy

scipy.misc.imsave

scipy.misc.imsave(name, arr)[source]

Save an array as an image.

Parameters :

name : str

Output filename.

arr : ndarray, MxN or MxNx3 or MxNx4

Array containing image values. If the shape is MxN, the array represents a grey-level image. Shape MxNx3 stores the red, green and blue bands along the last dimension. An alpha layer may be included, specified as the last colour band of an MxNx4 array.

Examples

Construct an array of gradient intensity values and save to file:

>>> x = np.zeros((255, 255))
>>> x = np.zeros((255, 255), dtype=np.uint8)
>>> x[:] = np.arange(255)
>>> imsave('/tmp/gradient.png', x)

Construct an array with three colour bands (R, G, B) and store to file:

>>> rgb = np.zeros((255, 255, 3), dtype=np.uint8)
>>> rgb[..., 0] = np.arange(255)
>>> rgb[..., 1] = 55
>>> rgb[..., 2] = 1 - np.arange(255)
>>> imsave('/tmp/rgb_gradient.png', rgb)

Previous topic

scipy.misc.imrotate

Next topic

scipy.misc.imshow