rivu
rivu

Reputation: 2534

PIL weird error after resizing image in skimage

I observed this weird issue with PIL and scikit image. When I do

img=io.imread(imgLoc)
pilImg=Image.fromarray(img)

It runs perfect. When I try to resize the image using skimage's rescale method like this:

img=rescale(io.imread(imgLoc),0.5)
pilImg=Image.fromarray(img)

it says

File "/home/abc/activepython/lib/python2.7/site-packages/PIL/Image.py", line 2137, in fromarray
raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type

From the documentation of skimage.io.imread and skimage.transform.rescale both returns numpy.ndarray which I manually checked as well. Can anyone throw some insight into this?

Upvotes: 1

Views: 1660

Answers (1)

user2970139
user2970139

Reputation: 559

rescale returns a floating point image. Try to do pilImg=Image.fromarray(skimage.util.img_as_ubyte(img)).

Upvotes: 1

Related Questions