【问题标题】:How numpy printoptions will work with images?numpy printoptions 如何处理图像?
【发布时间】: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


【解决方案1】:

从您在“代码 sn-p 图像”链接中给出的图表中,似乎 printoptions 打印两种情况下的值,以防如果需要正确打印值(显示所有值),您可以使用, 使用 np.printoptions(linewidth=200): 好的 = np.copy(src[:, :, 1]) 打印(确定)

如果这不是您想要的,请在 cmets 部分告诉我。很高兴更正答案!

【讨论】:

  • 不,通过将其更改为线宽,事情无法正常工作。
  • 我已使用您建议的代码编辑了图像。
猜你喜欢
  • 2011-08-30
  • 2021-08-19
  • 2015-06-18
  • 2018-01-24
  • 1970-01-01
  • 2019-12-15
  • 2012-11-10
  • 2016-10-21
  • 2012-07-30
相关资源
最近更新 更多