I've done some exercises without any systematic or consistent record. So I think it's time to post some results here to record my own understanding as well as to push myself to keep going forward.
The exercise here is a test of Gaussian blurring given in pp.31-32 of the PCVP book. The following is my code and output images.
from PIL import Image from PIL import Image import numpy as np from scipy.ndimage import filters import matplotlib.pylab as plt img = Image.open('../data/empire.jpg') im0 = np.array(img) #original image im1 = np.array(img.convert('L')) #convert to grayscale im2 = filters.gaussian_filter(im0,2) im3 = filters.gaussian_filter(im0,5) im4 = filters.gaussian_filter(im0,10) for i in range(5): plt.subplot(1,5,i+1).set_axis_off() plt.title( '(' + str(unichr(97+i)) + ')' ) #plt.imshow(eval('im'+str(i))) # This will output the grayscale image with colors plt.imshow(eval('im'+str(i)), cmap=plt.cm.Greys_r) plt.show()
|From left to right: (a) original image, (b) grayscale image, (c) Gaussian filter with σ = 2, (d) σ = 5, (e) σ = 10.|
Actually, the Gaussian blurring has no problems but the convert('L') and the imshow() functions bothered me for a while. I expected the imshow() function will gave me a grayscale image as the one shown in the PCVP book, but it gave me an image with colors as the second one listed in the following figure.
The solution I found  and tested is to add a cmap option to tell the imshow() which colormap  I want it to apply on the output image.
 Display image as grayscale using matplotlib
 Matplotlib Color Maps