Search code examples
pythonmatplotlibresizescikit-imageopencv

How to show or save a resized image?


I want to display and save the resized image. Below is the code for the same.

image = cv2.imread("zagreb_00050_11.png")

#plt.imshow(image)

image_sized=resize_keep_ar(image, 128)

plt.imshow(image_sized)

cv2.imwrite('resized_image.png',image_sized)

Resizing is done using the skimage module. First plt.show() works fine (commented), but after resizing when I tried to view the resized image it gives me below error.

ValueError: Unsupported dtype

<Figure size 432x288 with 1 Axes>

Also, when tried saving the resized image using cv2.imwrite I get the below error.

TypeError: Expected Ptr<cv::UMat> for argument 'img'

Where am I going wrong?


Solution

  • You can save try:

    plt.imsave('resized_image.png', data)
    

    or save the entire figure:

    plt.savefig('resized_image.png')