Merge pull request #101 from stefanv/pil_bilevel_png

BUG: Correctly load bi-level images via PIL.
This commit is contained in:
tonysyu
2011-12-12 17:00:28 -08:00
3 changed files with 11 additions and 2 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

+3 -2
View File
@@ -21,8 +21,9 @@ def imread(fname, dtype=None):
im = im.convert('L')
else:
im = im.convert('RGB')
if im.mode.startswith('I;16'):
elif im.mode == '1':
im = im.convert('L')
elif im.mode == 'I;16':
shape = im.size
dtype = '>u2' if im.mode.endswith('B') else '<u2'
im = np.fromstring(im.tostring(), dtype)
+8
View File
@@ -43,6 +43,14 @@ def test_palette_is_gray():
color = Image.open(os.path.join(data_dir, 'palette_color.png'))
assert not _palette_is_grayscale(color)
@skipif(not PIL_available)
def test_bilevel():
expected = np.zeros((10, 10))
expected[::2] = 255
img = imread(os.path.join(data_dir, 'checker_bilevel.png'))
assert_array_equal(img, expected)
class TestSave:
def roundtrip(self, dtype, x, scaling=1):
f = NamedTemporaryFile(suffix='.png')