Opening and Writing Images
The misc package of SciPy comes with some preloaded images. We will use those images to learn about image processing. One such image is provided by the face() function. The face() function will get a colored image of a raccoon face.
Example: Saving image using SciPy
Python3
from scipy import misc import imageio import matplotlib.pyplot as plt # reads a raccoon face face = misc.face() # save the image imageio.imsave( 'raccoon.png' , face) plt.imshow(face) plt.show() |
Output:
Example: Creating NumPy array from the image
Here we will read the image using the imread() function.
Python3
from scipy import misc import imageio import matplotlib.pyplot as plt img = imageio.imread( 'raccoon.png' ) print (img.shape) print (img.dtype) plt.imshow(img) plt.show() |
Output:
(768, 1024, 3) uint8
Image Processing with SciPy and NumPy in Python
In this tutorial, we will discuss Image Processing in Python using the core scientific modules like NumPy and SciPy. The images are made up of NumPy ndarrays so we can process and manipulate images and SciPy provides the submodule scipy.ndimage that provides functions that can operate on the NumPy arrays.
We will discuss how to open and write to images, and will also cover different manipulation and filtering techniques. So before getting started let’s see how to install both modules.