如何从 misc.imread() 获得的 ndarray 中删除整列值?
How do you delete an entire column of values from an ndarray obtained from misc.imread()?
我正在读取 png 图像,它是 RGBA 格式,我想删除 'A' 部分。我图像的形状是 (694, 1077, 4) 但我希望它是 (694, 1077, 3)。我想删除数组中的最后一列,这样我就只有 RGB 值了。
nd = np.random.randn(60).reshape(3,4,5)
print nd
print nd[:,:,:nd.shape[2]-1].shape #(3L, 4L, 4L)
这将删除最后一列。
只需这样做:
im_without_A = im[:, :, :3]
您可以使用 mode='RGB'
参数 (see docs),它应该省略 alpha 带。
我正在读取 png 图像,它是 RGBA 格式,我想删除 'A' 部分。我图像的形状是 (694, 1077, 4) 但我希望它是 (694, 1077, 3)。我想删除数组中的最后一列,这样我就只有 RGB 值了。
nd = np.random.randn(60).reshape(3,4,5)
print nd
print nd[:,:,:nd.shape[2]-1].shape #(3L, 4L, 4L)
这将删除最后一列。
只需这样做:
im_without_A = im[:, :, :3]
您可以使用 mode='RGB'
参数 (see docs),它应该省略 alpha 带。