@@ -40,12 +40,12 @@ examples, if you use the -pylab method, you can skip the "mpimg." and
40
40
Importing image data into Numpy arrays
41
41
===============================================
42
42
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.
47
47
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
49
49
requirement in mind for your own data.
50
50
51
51
Here's the image we're going to play with:
@@ -116,13 +116,13 @@ And here we go...
116
116
117
117
Note the dtype there - float32. Matplotlib has rescaled the 8 bit
118
118
data 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.
120
120
Matplotlib plotting can handle float32 and uint8, but image
121
121
reading/writing for any format other than PNG is limited to uint8
122
122
data. Why 8 bits? Most displays can only render 8 bits per channel
123
123
worth of color gradation. Why can they only render 8 bits/channel?
124
124
Because 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
126
126
<http://www.luminous-landscape.com/tutorials/bit-depth.shtml> `_.
127
127
128
128
Each inner list represents a pixel. Here, with an RGB image, there
@@ -179,7 +179,7 @@ channel of our data:
179
179
180
180
In [6]: lum_img = img[:,:,0]
181
181
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
183
183
<http://www.scipy.org/Tentative_NumPy_Tutorial> `_.
184
184
185
185
.. sourcecode :: ipython
@@ -336,9 +336,9 @@ and the computer has to draw in pixels to fill that space.
336
336
337
337
.. sourcecode :: ipython
338
338
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
342
342
In [11]: rsizeArr = np.asarray(rsize) # Get array back
343
343
In [12]: imgplot = plt.imshow(rsizeArr)
344
344
@@ -347,8 +347,8 @@ and the computer has to draw in pixels to fill that space.
347
347
import matplotlib.pyplot as plt
348
348
import matplotlib.image as mpimg
349
349
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
352
352
rsize = img.resize((img.size[0]/10,img.size[1]/10)) # resize the image
353
353
rsizeArr = np.asarray(rsize)
354
354
lum_img = rsizeArr[:,:,0]
@@ -368,8 +368,8 @@ Let's try some others:
368
368
import matplotlib.pyplot as plt
369
369
import matplotlib.image as mpimg
370
370
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
373
373
rsize = img.resize((img.size[0]/10,img.size[1]/10)) # resize the image
374
374
rsizeArr = np.asarray(rsize)
375
375
lum_img = rsizeArr[:,:,0]
@@ -385,8 +385,8 @@ Let's try some others:
385
385
import matplotlib.pyplot as plt
386
386
import matplotlib.image as mpimg
387
387
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
390
390
rsize = img.resize((img.size[0]/10,img.size[1]/10)) # resize the image
391
391
rsizeArr = np.asarray(rsize)
392
392
lum_img = rsizeArr[:,:,0]
0 commit comments