【发布时间】:2020-06-02 00:35:04
【问题描述】:
我试图打印一张图像来分析,如果图像是伪造的,像素强度是否有一些变化。无论如何,我的疑问与 numpy.printoptions 有关。 我正在尝试下面的代码并且 numpy.printoptions 不起作用: Image of code snippet 代码:
import numpy
import numpy as np
DIR = "D:/Work/ML/API/MNB/28 - Forgery/data/phase-01-training.tar/dataset-dist/chunks/1500_64_16"
TRAIN_CHUNKS = os.path.join(DIR, "train")
TRAIN_FAKE_CHUNKS = os.path.join(TRAIN_CHUNKS, "fake")
TRAIN_PRISTINE_CHUNKS = os.path.join(TRAIN_CHUNKS, "pristine")
IND=2000
train_chunk_files = os.listdir(TRAIN_FAKE_CHUNKS)
src = cv2.imread(os.path.join(TRAIN_FAKE_CHUNKS, train_chunk_files[IND]))
print(src[:, :, 1].shape)
with numpy.printoptions(threshold=64):
ok = np.copy(src[:, :, 1])
print(ok)
# print(src[:, :, 1])
plt.imshow(src)
plt.show()
但另一方面,numpy printoptions 对 mnist 数据集运行良好!!! Working code snippet 代码:
import tensorflow as tf
print(tf.__version__)
mnist = tf.keras.datasets.fashion_mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()
import numpy as np
np.set_printoptions(linewidth=200)
import matplotlib.pyplot as plt
print(type(training_images[0]))
plt.imshow(training_images[0])
print(training_labels[0])
print(training_images[0])
我在这里做错了什么?如何打印每个通道的 RGB 图像?我已经检查了这两个图像的数据类型,它是 numpy,ndarray。
编辑 1: 使用线宽无法正常工作。 Code with linewidth in np.printoptions
【问题讨论】:
-
图片的形状为:(64, 64, 3)
标签: python python-3.x numpy tensorflow computer-vision