【问题标题】:Loading images and reshaping resulting numpy array加载图像并重塑生成的 numpy 数组
【发布时间】:2018-02-23 18:06:45
【问题描述】:

您好,我正在尝试从使用 OpenCv 加载的图像中重塑一个充满像素数据的数组。生成的组合数组的形状为 (100,28,28,3) 我正在尝试使其成形 (100,28,28) 并且不能使用 np.delete 或 reshape 完全删除它。任何帮助都会很棒!到目前为止,这是我的代码:

import cv2
import glob
import numpy as np

hand_dig = []
files = glob.glob ("C:/Users/xxx/Desktop/digits/hand/*.PNG")
for myFile in files:
    print(myFile)
    image = cv2.imread (myFile)
    hand_dig.append (image)

print('hand_digit shape:', np.array(hand_dig).shape)
hand_dig=np.reshape(hand_dig,(100,28,28))
print(hand_dig.shape)

【问题讨论】:

    标签: python arrays image numpy reshape


    【解决方案1】:

    根据您上面给出的内容,您似乎有 100 个形状的 RGB 图像 (28,28)。 不,您不能丢弃像素,因为这可能会导致您丢失大量信息。 更好的选择是将每个图像转换为灰色,然后将其堆叠。

    读取图像后,添加以下行:

    image=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
    

    【讨论】:

      猜你喜欢
      • 2021-02-16
      • 1970-01-01
      • 2020-11-16
      • 2020-12-21
      • 2018-02-17
      • 1970-01-01
      • 2019-09-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多