1

I want to save image data as a list/array in memory so I can read it somewhere else. The default scripting language is Python 2.7 with numpy added so I have to do can be done with those.

1 Answer 1

1

Creates a list of tuples

from PIL import Image

img = Image.open('ubuntu.jpg')
imglist = list(img.getdata())

print imglist   

For numpy

import numpy

print numpy.array(img.getdata(), numpy.uint8).reshape(img.size[1], img.size[0], 3)
Sign up to request clarification or add additional context in comments.

8 Comments

Thanks but I don't have PIL installed on the company systems.
It's png or bmp, but I can save to other formats if that helps.
I think that without a library you'd be looking at opening and parsing the image files yourself. Can you run in a virtualenv and install PIL?
Thanks I don't know virtualenv but basically I am not allowed to use anything other than what the application comes out of the box which is python 2.7 with numpy.
virtualenv would be ideal. I don't think its there by default, so it might not be an option. So they will let you install numpy but no other packages? It seems incredibly restrictive. You may have no option but to parse the individual image file formats you want to use. That sounds like a lot of work and I don't know how to do this.
|

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.