0

I have a gray scale image of type uint16, size = (256,256) ndarray object

I want to use PIL to resize it to (75,75) but it requires the input to be of Image type.

How can I convert image of ndarray object into Image type to use image.resize((75,75), Image.ANTIALIAS)

NOTE: I know I can read image using Image.open if it is saved, but my image is obtained after some image processing steps and is not read from disk

UPDATE: I am trying to provide image that I have :

import scipy.misc
scipy.misc.imsave('image.png', box_img)

enter image description here

# read this similar format image of type ndarray    
image = scipy.ndimage.imread('image.png')
# convert it to Image type

The image attached when read of similar type as I need. I need to convert this image into Image type

Thanks,

Gopi

2

1 Answer 1

3
from PIL import Image
import numpy as np

# An array of ones for example
img_array = np.ones((256,256), dtype='uint16')
img = Image.fromarray(img_array)
img = img.resize((75,75))
Sign up to request clarification or add additional context in comments.

2 Comments

I tried img = img.resize((75,75), Image.ANTIALIAS) and it gives error saying : image has wrong mode
Best used with the package pillow ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.