@@ -40,12 +40,12 @@ examples, if you use the -pylab method, you can skip the "mpimg." and
4040Importing image data into Numpy arrays
4141===============================================
4242
43- Plotting image data is supported by the Python Image Library (` PIL
44- <http://www.pythonware.com/products/pil/ > `_). Natively, matplotlib
45- only supports PNG images. The commands shown below fall back on PIL
46- if the native read fails.
43+ Plotting image data is supported by the ` Pillow
44+ <http://python-imaging.github.io/ > `_). Natively, matplotlib only
45+ supports PNG images. The commands shown below fall back on Pillow if the
46+ native read fails.
4747
48- The image used in this example is a PNG file, but keep that PIL
48+ The image used in this example is a PNG file, but keep that Pillow
4949requirement in mind for your own data.
5050
5151Here's the image we're going to play with:
@@ -116,13 +116,13 @@ And here we go...
116116
117117Note the dtype there - float32. Matplotlib has rescaled the 8 bit
118118data from each channel to floating point data between 0.0 and 1.0. As
119- a side note, the only datatype that PIL can work with is uint8.
119+ a side note, the only datatype that Pillow can work with is uint8.
120120Matplotlib plotting can handle float32 and uint8, but image
121121reading/writing for any format other than PNG is limited to uint8
122122data. Why 8 bits? Most displays can only render 8 bits per channel
123123worth of color gradation. Why can they only render 8 bits/channel?
124124Because that's about all the human eye can see. More here (from a
125- photography standpoint): `Luminous Landscape bit depth tutorial
125+ photography standpoint): `Luminous Landscape bit depth tutorial
126126<http://www.luminous-landscape.com/tutorials/bit-depth.shtml> `_.
127127
128128Each inner list represents a pixel. Here, with an RGB image, there
@@ -179,7 +179,7 @@ channel of our data:
179179
180180 In [6]: lum_img = img[:,:,0]
181181
182- This is array slicing. You can read more in the `Numpy tutorial
182+ This is array slicing. You can read more in the `Numpy tutorial
183183<http://www.scipy.org/Tentative_NumPy_Tutorial> `_.
184184
185185.. sourcecode :: ipython
@@ -336,9 +336,9 @@ and the computer has to draw in pixels to fill that space.
336336
337337.. sourcecode :: ipython
338338
339- In [8]: import Image
340- In [9]: img = Image.open('stinkbug.png') # Open image as PIL image object
341- In [10]: rsize = img.resize((img.size[0]/10,img.size[1]/10)) # Use PIL to resize
339+ In [8]: from PIL import Image
340+ In [9]: img = Image.open('stinkbug.png') # Open image as Pillow image object
341+ In [10]: rsize = img.resize((img.size[0]/10,img.size[1]/10)) # Use Pillow to resize
342342 In [11]: rsizeArr = np.asarray(rsize) # Get array back
343343 In [12]: imgplot = plt.imshow(rsizeArr)
344344
@@ -347,8 +347,8 @@ and the computer has to draw in pixels to fill that space.
347347 import matplotlib.pyplot as plt
348348 import matplotlib.image as mpimg
349349 import numpy as np
350- import Image
351- img = Image.open('../_static/stinkbug.png') # opens the file using PIL - it's not an array yet
350+ from PIL import Image
351+ img = Image.open('../_static/stinkbug.png') # opens the file using Pillow - it's not an array yet
352352 rsize = img.resize((img.size[0]/10,img.size[1]/10)) # resize the image
353353 rsizeArr = np.asarray(rsize)
354354 lum_img = rsizeArr[:,:,0]
@@ -368,8 +368,8 @@ Let's try some others:
368368 import matplotlib.pyplot as plt
369369 import matplotlib.image as mpimg
370370 import numpy as np
371- import Image
372- img = Image.open('../_static/stinkbug.png') # opens the file using PIL - it's not an array yet
371+ from PIL import Image
372+ img = Image.open('../_static/stinkbug.png') # opens the file using Pillow - it's not an array yet
373373 rsize = img.resize((img.size[0]/10,img.size[1]/10)) # resize the image
374374 rsizeArr = np.asarray(rsize)
375375 lum_img = rsizeArr[:,:,0]
@@ -385,8 +385,8 @@ Let's try some others:
385385 import matplotlib.pyplot as plt
386386 import matplotlib.image as mpimg
387387 import numpy as np
388- import Image
389- img = Image.open('../_static/stinkbug.png') # opens the file using PIL - it's not an array yet
388+ from PIL import Image
389+ img = Image.open('../_static/stinkbug.png') # opens the file using Pillow - it's not an array yet
390390 rsize = img.resize((img.size[0]/10,img.size[1]/10)) # resize the image
391391 rsizeArr = np.asarray(rsize)
392392 lum_img = rsizeArr[:,:,0]
0 commit comments