Added dtype keyword to imread plus a test for that.

This commit is contained in:
Ralf Gommers
2009-10-12 15:36:02 +02:00
committed by Stefan van der Walt
parent b25ae266a5
commit 44679c7aae
2 changed files with 15 additions and 2 deletions
+5 -2
View File
@@ -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)
+10
View File
@@ -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