mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-12 12:30:16 +08:00
Added dtype keyword to imread plus a test for that.
This commit is contained in:
committed by
Stefan van der Walt
parent
b25ae266a5
commit
44679c7aae
@@ -2,7 +2,7 @@ __all__ = ['imread']
|
||||
|
||||
import numpy as np
|
||||
|
||||
def imread(fname, flatten=False):
|
||||
def imread(fname, flatten=False, dtype=None):
|
||||
"""Load an image from file.
|
||||
|
||||
Parameters
|
||||
@@ -11,6 +11,9 @@ def imread(fname, flatten=False):
|
||||
Image file name, e.g. ``test.jpg``.
|
||||
flatten : bool
|
||||
If true, convert the output to grey-scale.
|
||||
dtype : dtype, optional
|
||||
NumPy data-type specifier. If given, the returned image has this type.
|
||||
If None (default), the data-type is determined automatically.
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -31,4 +34,4 @@ def imread(fname, flatten=False):
|
||||
im = Image.open(fname)
|
||||
if flatten:
|
||||
im = im.convert('F')
|
||||
return np.array(im)
|
||||
return np.array(im, dtype=dtype)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import os.path
|
||||
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)
|
||||
assert img.dtype == np.float32
|
||||
Reference in New Issue
Block a user