From: John H. <jdh...@ac...> - 2004-07-08 22:17:11
|
>>>>> "Rein" == Rein van den Boomgaard (UvA) <re...@sc...> writes: Rein> What is the prefered way to read in images in Rein> numarray/matplotlib? No good way, currently. I plan to add a PNG loader in the near future. Would this suffice for you? What do you think are the core set of image formats that matplotlib should support? ... the fewer the better! Rein> I know of PIL but it seems like a lot of overlap with Rein> numarray just to read an image from file. True, but for the record, here is the recipe I use to do the PIL -> numerix conversion import Image from matplotlib.matlab import * im = Image.open('../data/leo_ratner.jpg') s = im.tostring() # convert PIL image -> string # convert string -> numerix array of floats rgb = fromstring(s, UInt8).astype(Float)/255.0 # resize to RGB array rgb = resize(rgb, (im.size[1], im.size[0], 3)) imshow(rgb, interpolation='nearest') axis('off') # don't display the image axis show() |