Question 1

In this section, we will use the defined Sobel filter, which is 3-by-3 filter, to get the g_x and g_y based on the selected image.


In [1]:
%matplotlib inline
import lab004
import numpy as np
import matplotlib.pyplot as plt
# Question 1
# Filter Settings
target = list(lab004.mnist_read('../mAiLab_0003/train-images-idx3-ubyte', '../mAiLab_0003/train-labels-idx1-ubyte'))
plt.figure()
for i in range(5):
    label, img = target[i]
    Gx_result = lab004.Gx(lab004.mnist_padding(img, 30))
    #print mnist_im2str(Gx_result.astype(np.uint8))
    Gx_result.astype(np.uint8)
    Gy_result = lab004.Gy(lab004.mnist_padding(img, 30))
    Gy_result.astype(np.uint8)
    #plt.figure()
    plt.subplot(2, 5, i+1)
    lab004.mnist_show(Gx_result)
    #plt.show()
    plt.subplot(2, 5, i+6)
    #plt.figure()
    lab004.mnist_show(Gy_result)
    #plt.show()
plt.show()