如何显示图像

时间:2016-12-22 07:33:13

标签: tensorflow

我正在尝试显示CIFAR-10 TensorFlow教程中的图像。图像被转换,以便读取的值在-1和3之间浮动更少。我没有显示应用了什么样的转换。如何显示它们以查看原始内容?

以下是图像输出的部分:

StringProperty

...

 array([[ 1.24836731,  0.04940184, -1.49835348],\n       [ 1.117571  ,    0.02760247, -1.56375158],\n       [ 1.24836731,  0.18019807, -1.41115606],\n       [ 1.18296909,  0.09300058, -1.47655416],\n       [ 1.13937044,  0.02760247, -1.54195225],\n       [ 1.13937044,  0.09300058, -1.52015293],\n 

这是教程的链接: https://www.tensorflow.org/tutorials/deep_cnn/

编辑:

重新缩放对我来说似乎不起作用:

enter image description here

2 个答案:

答案 0 :(得分:0)

尝试将图像缩放到0到25​​5之间?减去min并除以新的最大值

答案 1 :(得分:0)

对于灰度MNIST图像,有两种方法可以做到这一点:

tmp = mnist.train.images[0]
tmp = tmp.reshape((28,28))

plt.imshow(tmp, cmap = cm.Greys)
plt.show()

或者,对于CIFAR-10图像: 以下代码取自this教程

def visualize_sample(X_train, y_train, classes, samples_per_class=7):
"""visualize some samples in the training datasets """
num_classes = len(classes)
for y, cls in enumerate(classes):
    idxs = np.flatnonzero(y_train == y) # get all the indexes of cls
    idxs = np.random.choice(idxs, samples_per_class, replace=False)
    for i, idx in enumerate(idxs): # plot the image one by one
        plt_idx = i * num_classes + y + 1 # i*num_classes and y+1 determine the row and column respectively
        plt.subplot(samples_per_class, num_classes, plt_idx)
        plt.imshow(X_train[idx].astype('uint8'))
        plt.axis('off')
        if i == 0:
            plt.title(cls)
plt.show()