保存后为什么图像尺寸会发生变化?

问题描述 投票:0回答:1

在我应用算法方法后,当我将图像读取为np.array时,我的图像大小(M * N)大小有问题,它的大小改变为另一个值。一些时间增加,一些时间减少取决于图像。

img = cv2.imread('baboon.jpg',1)  # read image (255*255)
na = np.array(img)  # convert it to array
x, y ,pp = img.shape[:3]  # size of 3d
blue = np.array(range(x*y), int).reshape((x, y))
blue[:,:] = na[:, :, 0]
en_split_block_8(red,31,1)  # function algorithm

我使用此代码保存图像,大小从(255 * 255)变为(640 * 480)

plt.imshow(blue,interpolation='nearest',cmap="gray")
plt.savefig('blue.jpg')#(640*480)

我希望图像保持它的大小。 (我不改变图像的大小只是我在处理值)。

original image

image after encryption and save

python python-3.x numpy
1个回答
1
投票

那是因为你用pyplot保存图像,blue将图像显示为图表。你要做的是使用cv2保存cv2.imwrite('blue.jpg', blue)图像:na = np.array(img)

请注意img是多余的,为什么ndarray已经是qazxswpoi。

© www.soinside.com 2019 - 2024. All rights reserved.