提问人:Willy Lutz 提问时间:10/18/2023 更新时间:10/18/2023 访问量:22
Numpy 将图像调整为列主要顺序正在复制我的图片
Numpy reshape image to column major order is duplicating my picture
问:
出于自监督学习的目的,我需要创建一个由自定义图片组成的数据集。 我想将我的图片存储在 bin 文件中,作为形状 (3, 256, 256) 的 numpy 数组,按列主要顺序排列。
我的图片形状(256、256、3)为 tiff 文件。我像往常一样打开它。PIL.Image
但是,使用下面的代码,我得到以下结果:
im = Image.open(file)
imarr = np.array(im)
imarr = imarr.reshape((3, 256, 256), order='F')
# for plotting
img = np.transpose(imarr, (1, 2, 0))
plt.imshow(img)
plt.title('generate bin files')
plt.show()
作为规范,不使用或其他值作为“C”或“A”会导致这种错误的图片:order
我怎样才能做到它只是我图片的 9 个重复中的一个?
谢谢你的帮助。img
答:
0赞
Willy Lutz
10/18/2023
#1
实际上我发现我误用了.np.reshape
而不是
imarr = imarr.reshape((3, 256, 256), order='F')
我使用
imarr = np.transpose(imarr, (2, 0, 1))
具有形状(3,256,256),它就像一个魅力。
上一个:使用 Excel 重塑表格
评论