图像尺寸(M * N)有问题 当我应用算法方法将图像读取为np.array时,其更改大小为另一个值。有时会增加,有时会减少取决于图像。
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)
我希望图像保持其大小。 (我不会更改图像的大小,而只是在处理值)。
答案 0 :(得分:1)
那是因为要使用pyplot
保存图像,该图像将图像显示为图表。相反,您要做的是使用blue
和cv2
保存cv2.imwrite('blue.jpg', blue)
图片。
请注意,na = np.array(img)
对于为什么img
已经是ndarray
是多余的。