From 44679c7aae5d6b3747c88d46756a3dc96c9a727f Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Mon, 12 Oct 2009 13:48:25 +0200 Subject: [PATCH] Added dtype keyword to imread plus a test for that. --- scikits/image/io/pil_imread.py | 7 +++++-- scikits/image/io/tests/test_imread.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 scikits/image/io/tests/test_imread.py diff --git a/scikits/image/io/pil_imread.py b/scikits/image/io/pil_imread.py index d57348a8..641c61f4 100644 --- a/scikits/image/io/pil_imread.py +++ b/scikits/image/io/pil_imread.py @@ -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) diff --git a/scikits/image/io/tests/test_imread.py b/scikits/image/io/tests/test_imread.py new file mode 100644 index 00000000..3a68f9ee --- /dev/null +++ b/scikits/image/io/tests/test_imread.py @@ -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