Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 14a4386

Browse files
committed
Merge pull request #616
1 parent 513ac45 commit 14a4386

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2012-06-05 Images loaded through PIL are now ordered correctly - CG
2+
13
2012-06-02 Add new Axes method and pyplot function, hist2d. - PO
24

35
2012-05-29 pcolormesh now obeys the passed in "edgecolor" kwarg.

examples/pylab_examples/image_demo3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
figure(figsize=figsize)
1616
ax = axes([0,0,1,1], frameon=False)
1717
ax.set_axis_off()
18-
im = imshow(lena, origin='lower')
18+
im = imshow(lena)
1919

2020
show()
2121

lib/matplotlib/image.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
from __future__ import division, print_function
77
import os, warnings
8+
import math
89

910
import numpy as np
1011
from numpy import ma
@@ -325,7 +326,7 @@ def _draw_unsampled_image(self, renderer, gc):
325326

326327
im._url = self.get_url()
327328
im._gid = self.get_gid()
328-
329+
329330
renderer.draw_image(gc, xmin, ymin, im, dxintv, dyintv,
330331
trans_ic_to_canvas)
331332

@@ -1184,6 +1185,9 @@ def pilread():
11841185
if cbook.is_string_like(fname):
11851186
basename, ext = os.path.splitext(fname)
11861187
ext = ext.lower()[1:]
1188+
elif hasattr(fname, 'name'):
1189+
basename, ext = os.path.splitext(fname.name)
1190+
ext = ext.lower()[1:]
11871191
else:
11881192
ext = 'png'
11891193
else:
@@ -1251,14 +1255,14 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
12511255

12521256
def pil_to_array( pilImage ):
12531257
"""
1254-
load a PIL image and return it as a numpy array of uint8. For
1255-
grayscale images, the return array is MxN. For RGB images, the
1256-
return value is MxNx3. For RGBA images the return value is MxNx4
1258+
Load a PIL image and return it as a numpy array. For grayscale
1259+
images, the return array is MxN. For RGB images, the return value
1260+
is MxNx3. For RGBA images the return value is MxNx4
12571261
"""
1258-
def toarray(im):
1259-
"""Teturn a 1D array of floats."""
1260-
x_str = im.tostring('raw',im.mode,0,-1)
1261-
x = np.fromstring(x_str,np.uint8)
1262+
def toarray(im, dtype=np.uint8):
1263+
"""Teturn a 1D array of dtype."""
1264+
x_str = im.tostring('raw', im.mode)
1265+
x = np.fromstring(x_str, dtype)
12621266
return x
12631267

12641268
if pilImage.mode in ('RGBA', 'RGBX'):
@@ -1275,7 +1279,15 @@ def toarray(im):
12751279
x = toarray(im)
12761280
x.shape = im.size[1], im.size[0], 3
12771281
return x
1278-
1282+
elif pilImage.mode.startswith('I;16'):
1283+
# return MxN luminance array of uint16
1284+
im = pilImage
1285+
if im.mode.endswith('B'):
1286+
x = toarray(im, '>u2')
1287+
else:
1288+
x = toarray(im, '<u2')
1289+
x.shape = im.size[1], im.size[0]
1290+
return x.astype('=u2')
12791291
else: # try to convert to an rgba image
12801292
try:
12811293
im = pilImage.convert('RGBA')
Binary file not shown.

lib/matplotlib/tests/test_image.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ def test_image_python_io():
7676
buffer.seek(0)
7777
plt.imread(buffer)
7878

79+
def test_imread_pil_uint16():
80+
img = plt.imread(os.path.join(os.path.dirname(__file__),
81+
'baseline_images/test_image/uint16.tif'))
82+
assert (img.dtype == np.uint16)
83+
assert np.sum(img) == 134184960
84+
7985
# def test_image_unicode_io():
8086
# fig = plt.figure()
8187
# ax = fig.add_subplot(111)

0 commit comments

Comments
 (0)