【问题标题】:Change array shape of an image in python在python中更改图像的数组形状
【发布时间】:2016-11-26 02:27:51
【问题描述】:

当我在 OpenCV 中读取彩色图像时,它显示的尺寸为 256x256x3。但我需要将它作为 3x256x256 数组传递给我的神经网络。如何更改阵列形状,保留 BGR 中的像素位置。

【问题讨论】:

    标签: image python-2.7 opencv


    【解决方案1】:

    您可以简单地转置数组。例如,我的图片是 10 x 10 的图片:

    import numpy as np
    
    #my picture
    wrong_format = np.arange(300).reshape(10,10,3)
    
    correct_format = wrong_format.T 
    

    如果它工作正常,那么 correct_format(0,1,1) 应该等于 wrong_format(1,1,0)。我们可以看到它是:

    correct_format(0,1,1) == wrong_format(1,1,0)
    

    是的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-15
      相关资源
      最近更新 更多