Converting Array into Image (tif) in Python using Pillow -


i trying convert array image (tif) compression (it undone @ other end). however, i'm falling @ first hurdle...

i have following:

pillow_image = image.fromarray(image_data) 

which gives me error:

  file "/users/workspace/test-app/env/lib/python2.7/site-packages/pil/image.py", 

line 2155, in fromarray arr = obj.array_interface attributeerror: 'tuple' object has no attribute 'array_interface'

what i'm doing wrong here?

image_data tuple of 4 numpy arrays, each (probably) of shape (h, w). need image_data single array of shape (h, w, 4). therefore, use np.dstack combine channels.

at least 1 of arrays has dtype int32. use 8-bit color channel, arrays needs of dtype uint8 (so maximum value 255). can convert array dtype uint8 using astype. data not contain values greater 255. if does, astype('uint8') keep least significant bits (i.e. return number modulo 256).

image_data = np.dstack(image_data).astype('uint8') pillow_image = image.fromarray(image_data) 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -