【问题标题】:Creating Numpy Arrays of Images创建 Numpy 图像数组
【发布时间】:2017-12-28 02:02:46
【问题描述】:

我有一个形状为 (200,1,50,50) 的 numpy 图像数组。这是 200 张 50x50 图像的图像。

我想翻转一定百分比的图像并将它们保存在一个全新的数组中。我可以从原始数组中取出图像并将其翻转,但是我不知道如何将图像放入新数组中(需要与原始数组相同的形状 (x,1,50,50)。

如何从 (50,50) 翻转的图像转到新数组中的 (0,1,50,50) 条目?

【问题讨论】:

  • 你能清楚一点你所说的翻转百分比是什么意思吗?

标签: python-2.7 numpy image-processing


【解决方案1】:

如果您想为数组添加额外的维度,请使用内置函数 expand_dims。要翻转图像,请使用cv2.flip,之后您可以将图像裁剪为后期处理步骤。

In [1]: import numpy as np

In [2]: x = np.random.randn(50, 50)

In [3]: x.shape
Out[3]: (50, 50)

In [4]: np.expand_dims(x, axis=0).shape
Out[4]: (1, 50, 50)

In [5]: x_ = np.expand_dims(x, axis=0)

In [6]: x_ = np.expand_dims(x_, axis=0)

In [7]: x_.shape
Out[7]: (1, 1, 50, 50)

【讨论】:

  • 你可以有一个形状为 0 的 numpy 数组:np.zeros(0).shape 给出(0,)。不过,我认为这不是 OP 所要求的
  • 我指的是高维数组
  • 好吧,np.zeros((0,1,50,50)).shape 也给了(0,1,50,50)
猜你喜欢
  • 2016-03-23
  • 2020-09-10
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 2021-08-30
  • 2018-10-16
  • 1970-01-01
相关资源
最近更新 更多