Scipy.misc.imread和io.imread给了我不同的结果。为什么?

时间:2018-04-15 20:24:28

标签: python scikit-image

我正在尝试用我自己的笔迹运行我的神经网络。要阅读我使用scipy.misc.imread的图片,但我得到了DeprecationWarning: 'imread' is deprecated!

所以我尝试使用io.imread中的skimage,但它给出了截然不同的答案。这两种方法有什么区别?

版本1:

# I read in the file
img_array = scipy.misc.imread('/Users/usr/Desktop/NN/Test_Sets/handwritten/IMG_5.png', flatten=True)

# reshape from 28x28 to list of 784 values
# subtract array values from 255.0
img_data  = 255.0 - img_array.reshape(784)

# then scale data to range from 0.01 to 1.0
img_data = (img_data / 255.0 * 0.99) + 0.01
print("min = ", np.min(img_data))
print("max = ", np.max(img_data))

# plot image
plt.imshow(img_data.reshape(28,28), cmap='Greys', interpolation='None')

# query the network
outputs = n_final.request(img_data)
print (outputs)

# the index of the highest value corresponds to the label
label = np.argmax(outputs)
print("network says ", label)

enter image description here

版本2:

import skimage
from skimage import transform,io

# I read in the file
img_array = io.imread('/Users/usr/Desktop/NN/Training_Sets/handwritten/IMG_5.png', as_grey=True)
small_grey = transform.resize(img_array, (28,28), mode='symmetric', preserve_range=True) 

# reshape from 28x28 to list of 784 values
reshape_img = small_grey.reshape(1, 784)
img_data  = 255.0 - reshape_img

# then scale data to range from 0.01 to 1.0
img_data = (img_data / 255.0 * 0.99) + 0.01
print("min = ", np.min(img_data))
print("max = ", np.max(img_data))

# plot image
plt.imshow(img_data.reshape(28,28), cmap='Greys', interpolation='None')

# query the network
outputs = n_final.request(img_data)
print (outputs)

# the index of the highest value corresponds to the label
label = np.argmax(outputs)
print("network says ", label)

enter image description here

0 个答案:

没有答案