mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-17 11:32:45 +08:00
Bug fix for imread so images that are already grey-scale do not get flattened.
This commit is contained in:
@@ -10,7 +10,9 @@ def imread(fname, flatten=False, dtype=None):
|
||||
fname : string
|
||||
Image file name, e.g. ``test.jpg``.
|
||||
flatten : bool
|
||||
If true, convert the output to grey-scale.
|
||||
If True, convert color images to grey-scale. If `dtype` is not given,
|
||||
converted color images are returned as 32-bit float images.
|
||||
Images that are already in grey-scale format are not converted.
|
||||
dtype : dtype, optional
|
||||
NumPy data-type specifier. If given, the returned image has this type.
|
||||
If None (default), the data-type is determined automatically.
|
||||
@@ -32,6 +34,6 @@ def imread(fname, flatten=False, dtype=None):
|
||||
" instructions.")
|
||||
|
||||
im = Image.open(fname)
|
||||
if flatten:
|
||||
if flatten and not im.mode in ('1', 'L', 'I', 'F', 'I;16', 'I;16L', 'I;16B'):
|
||||
im = im.convert('F')
|
||||
return np.array(im, dtype=dtype)
|
||||
|
||||
@@ -4,7 +4,14 @@ import numpy as np
|
||||
from scikits.image import data_dir
|
||||
from scikits.image.io import imread
|
||||
|
||||
def test_imread():
|
||||
img = imread(os.path.join(data_dir, 'camera.png'), dtype=np.float32)
|
||||
print img.dtype, type(img)
|
||||
def test_imread_flatten():
|
||||
# a color image is flattened and returned as float32
|
||||
img = imread(os.path.join(data_dir, 'color.png'), flatten=True)
|
||||
assert img.dtype == np.float32
|
||||
img = imread(os.path.join(data_dir, 'camera.png'), flatten=True)
|
||||
# check that flattening does not occur for an image that is grey already.
|
||||
assert np.sctype2char(img.dtype) in np.typecodes['AllInteger']
|
||||
|
||||
def test_imread_dtype():
|
||||
img = imread(os.path.join(data_dir, 'camera.png'), dtype=np.float64)
|
||||
assert img.dtype == np.float64
|
||||
|
||||
Reference in New Issue
Block a user