mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-27 19:48:43 +08:00
Merge pull request #1498 from cgohlke/patch-2
Fix skimage.io.imread returns incorrect dimensions
This commit is contained in:
+10
-2
@@ -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
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user