Loading and displaying images
In order to manipulate images, we will use a package called mahotas. This is an open source package (MIT license, so it can be used in any project) that was developed by one of the authors of the book you are reading. Fortunately, it is based on NumPy
. The NumPy knowledge you have acquired so far can be used for image processing. There are other image packages such as scikit-image (Skimage), the ndimage (n-dimensional image) module in 
SciPy, and the Python
 bindings for OpenCV. All of these work natively with NumPy, so you can even mix and match functionalities from different packages to get your result.
We start by importing mahotas with the mh abbreviation, which we will use throughout this chapter:
import mahotas as mh
Now we can load an image file using imread:
image = mh.imread('imagefile.png')If imagefile.png contains a color image of height h and width w, then image will be an array of shape (h, w, 3). The first dimension is the height, the second the width...
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                