Menu

[r510]: / trunk / users_guide / code / from_pil.py  Maximize  Restore  History

Download this file

16 lines (11 with data), 392 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.