Alright, I'm toying around with converting a PIL image object back and forth to a numpy array so I can do some faster pixel by pixel transformations than PIL's PixelAccess
object would allow. I've figured out how to place the pixel information in a useful 3D numpy array by way of:
pic = Image.open("foo.jpg")
pix = numpy.array(pic.getdata()).reshape(pic.size[0], pic.size[1], 3)
But I can't seem to figure out how to load it back into the PIL object after I've done all my awesome transforms. I'm aware of the putdata()
method, but can't quite seem to get it to behave.
pic.size[0]
andpic.size[1]
should be swapped (ie.reshape(pic.size[1], pic.size[0], 3)
), sincesize
iswidth x height
orx * y
, while matrix ordering isrows x columns
. – foges