In the earlier example, the magnitude and direction of the edges were shown in different images. We can create an RGB image and set the R, G, and B values as follows to display both magnitude and direction in the same image:
With the same code as in the last example, we only replace the right bottom subplot code with the following code:
im = np.zeros((im.shape[0],im.shape[1],3))
im[...,0] = im_mag*np.sin(im_ang)
im[...,1] = im_mag*np.cos(im_ang)
pylab.title(r'||grad||+$ heta$', size=30), pylab.imshow(im), pylab.axis('off')
And then, using a tiger image instead, we get the output shown in the following screenshot. The last subplot shows both the magnitude and the direction of edges with colors: