From 06f8f398bd74a0c40da7a6a356f15a37331aec6f Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Fri, 5 Nov 2010 14:44:01 +0200 Subject: [PATCH] API: Remove dtype parameter from imread and collections. Remove as_grey from collections. --- doc/source/api_changes.txt | 3 ++- scikits/image/io/_plugins/test_plugin.py | 1 - scikits/image/io/collection.py | 3 --- scikits/image/io/io.py | 17 +++++++++-------- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/doc/source/api_changes.txt b/doc/source/api_changes.txt index fdf66821..9e6cf28c 100644 --- a/doc/source/api_changes.txt +++ b/doc/source/api_changes.txt @@ -1,4 +1,5 @@ Version 0.3 ----------- -- Remove ``as_grey``, ``dtype`` keywords from imread and ImageCollection +- Remove ``as_grey``, ``dtype`` keyword from ImageCollection +- Remove ``dtype`` from imread - Generalise ImageCollection to accept a load_func diff --git a/scikits/image/io/_plugins/test_plugin.py b/scikits/image/io/_plugins/test_plugin.py index 975d55d9..dbdd542c 100644 --- a/scikits/image/io/_plugins/test_plugin.py +++ b/scikits/image/io/_plugins/test_plugin.py @@ -1,6 +1,5 @@ def imread(fname, as_grey=False, dtype=None): assert fname == 'test.png' - assert as_grey == True assert dtype == 'i4' def imsave(fname, arr): diff --git a/scikits/image/io/collection.py b/scikits/image/io/collection.py index dc3e51db..ea755a77 100644 --- a/scikits/image/io/collection.py +++ b/scikits/image/io/collection.py @@ -23,9 +23,6 @@ class MultiImage(object): conserve_memory : bool, optional Whether to conserve memory by only caching a single frame. Default is True. - dtype : dtype, optional - NumPy data-type specifier. If given, the returned image has this type. - If None (default), the data-type is determined automatically. Attributes ---------- diff --git a/scikits/image/io/io.py b/scikits/image/io/io.py index c920fa64..37b73686 100644 --- a/scikits/image/io/io.py +++ b/scikits/image/io/io.py @@ -1,6 +1,7 @@ __all__ = ['imread', 'imsave', 'imshow', 'show', 'push', 'pop'] from scikits.image.io._plugins import call as call_plugin +from scikits.image.color import rgb2grey import numpy as np # Shared image queue @@ -31,7 +32,7 @@ def pop(): """ return _image_stack.pop() -def imread(fname, as_grey=False, dtype=None, plugin=None, flatten=None, +def imread(fname, as_grey=False, plugin=None, flatten=None, **plugin_args): """Load an image from file. @@ -40,12 +41,8 @@ def imread(fname, as_grey=False, dtype=None, plugin=None, flatten=None, fname : string Image file name, e.g. ``test.jpg``. as_grey : bool - If True, convert color images to grey-scale. If `dtype` is not given, - converted color images are returned as 32-bit float images. + If True, convert color images to grey-scale (32-bit floats). 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. plugin : str Name of plugin to use (Python Imaging Library by default). @@ -71,8 +68,12 @@ def imread(fname, as_grey=False, dtype=None, plugin=None, flatten=None, if flatten is not None: as_grey = flatten - return call_plugin('imread', fname, as_grey=as_grey, dtype=dtype, - plugin=plugin, **plugin_args) + img = call_plugin('imread', fname, plugin=plugin, **plugin_args) + + if as_grey and getattr(img, 'ndim', 0) >= 3: + img = rgb2grey(img) + + return img def imsave(fname, arr, plugin=None, **plugin_args): """Save an image to file.