Merge pull request #1498 from cgohlke/patch-2

Fix skimage.io.imread returns incorrect dimensions
This commit is contained in:
Steven Silvester
2015-05-09 09:02:41 -05:00
2 changed files with 25 additions and 2 deletions
+10 -2
View File
@@ -53,8 +53,16 @@ def imread(fname, as_grey=False, plugin=None, flatten=None,
with file_or_url_context(fname) as fname:
img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
if as_grey and getattr(img, 'ndim', 0) >= 3:
img = rgb2grey(img)
if not hasattr(img, 'ndim'):
return img
if img.ndim > 2:
if img.shape[-1] not in (3, 4) and img.shape[-3] in (3, 4):
img = np.swapaxes(img, -1, -3)
img = np.swapaxes(img, -2, -3)
if as_grey:
img = rgb2grey(img)
return img
+15
View File
@@ -1,3 +1,4 @@
import os
import os.path
import numpy as np
from numpy.testing import *
@@ -60,6 +61,20 @@ def test_bilevel():
assert_array_equal(img.astype(bool), expected)
@skipif(not imread_available)
def test_imread_separate_channels():
# Test that imread returns RGBA values contiguously even when they are
# stored in separate planes.
x = np.random.rand(3, 16, 8)
f = NamedTemporaryFile(suffix='.tif')
fname = f.name
f.close()
imsave(fname, x, plugin='tifffile')
img = imread(fname, plugin='tifffile')
os.remove(fname)
assert img.shape == (16, 8, 3), img.shape
class TestSave:
def roundtrip(self, x, scaling=1):
f = NamedTemporaryFile(suffix='.png')