4

I was trying to resize the input image using OpenCV but I am having problems converting the resized np array into the original format.

image = imageio.imread(filename) #<class 'imageio.core.util.Image'>
image_re = cv2.resize(image, (256, 256)) #<class 'numpy.ndarray'>
#convert into <class 'imageio.core.util.Image'> here

Thanks in advance.

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Pablo Gonzalez
  • 673
  • 2
  • 10
  • 24

2 Answers2

3

imageio.core.util.Image is just a subclass of np.ndarray with a meta attribute. Why do you want to go back to it?

Some further explanation of your objectives would probably help clarify the question.

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Mr K.
  • 1,064
  • 3
  • 19
  • 22
  • Thank you for reply. I hope you can help me out. My problem is, the input image was 512x512 but I need it with size 256x256. So, I used cv2 resize function to resize the image to the desired size but this function outputs a numpy.ndarray and I need it back to imageio.core.util.Image for next step since the code is expecting that type. Maybe it is an easy question but I am newbie in python and I still cannot find the way in google – Pablo Gonzalez Mar 15 '18 at 08:57
  • 1
    What's the next step? imageio is used to read/write images, videos, etc so once you already have the information you can just write it to disk using imageio.imwrite() – Mr K. Mar 15 '18 at 09:11
0

use the following code

width = height = 256
dim = (width, height)

file_name = "your file address here"    
image = imageio.imread(file_name )
resized = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
image2 = imageio.core.util.Array(resized)

what you need to use is image2

Abey Bruck
  • 532
  • 5
  • 7