From 4cb251bbe6fd641e40219513287c7fd94c1b8532 Mon Sep 17 00:00:00 2001 From: Ankit Agrawal Date: Tue, 30 Apr 2013 18:44:42 +0530 Subject: [PATCH] Deprecating is_gray and replacing it with is_gray_2d --- skimage/color/colorconv.py | 17 ++++++++++++++--- skimage/color/tests/test_colorconv.py | 13 +++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/skimage/color/colorconv.py b/skimage/color/colorconv.py index fc9ab342..e7e7720a 100644 --- a/skimage/color/colorconv.py +++ b/skimage/color/colorconv.py @@ -52,7 +52,7 @@ __all__ = ['convert_colorspace', 'rgb2hsv', 'hsv2rgb', 'rgb2xyz', 'xyz2rgb', 'rgb_from_gdx', 'gdx_from_rgb', 'rgb_from_hax', 'hax_from_rgb', 'rgb_from_bro', 'bro_from_rgb', 'rgb_from_bpx', 'bpx_from_rgb', 'rgb_from_ahx', 'ahx_from_rgb', 'rgb_from_hpx', 'hpx_from_rgb', - 'is_rgb', 'is_gray' + 'is_rgb', 'is_gray', 'is_gray_2d' ] __docformat__ = "restructuredtext en" @@ -60,6 +60,7 @@ __docformat__ = "restructuredtext en" import numpy as np from scipy import linalg from ..util import dtype +from skimage._shared.utils import deprecated def is_rgb(image): @@ -73,7 +74,7 @@ def is_rgb(image): """ return (image.ndim == 3 and image.shape[2] in (3, 4)) - +@deprecated('is_gray_2d') def is_gray(image): """Test whether the image is gray (i.e. has only one color band). @@ -83,8 +84,18 @@ def is_gray(image): Input image. """ - return image.ndim == 2 + return is_gray_2d(image) +def is_gray_2d(image): + """Test whether the image is 2d and grayscale. + + Parameters + ---------- + image : ndarray + Input image. + + """ + return np.squeeze(image).ndim == 2 def convert_colorspace(arr, fromspace, tospace): """Convert an image array to a new color space. diff --git a/skimage/color/tests/test_colorconv.py b/skimage/color/tests/test_colorconv.py index 3365bb1c..2cdde1fe 100644 --- a/skimage/color/tests/test_colorconv.py +++ b/skimage/color/tests/test_colorconv.py @@ -29,7 +29,7 @@ from skimage.color import ( rgb2grey, gray2rgb, xyz2lab, lab2xyz, lab2rgb, rgb2lab, - is_rgb, is_gray + is_rgb, is_gray, is_gray_2d ) from skimage import data_dir, data @@ -232,19 +232,16 @@ class TestColorconv(TestCase): assert_array_almost_equal(lab2rgb(rgb2lab(img_rgb)), img_rgb) def test_gray2rgb(): - x = np.array([0, 0.5, 1]) - assert_raises(ValueError, gray2rgb, x) - - x = x.reshape((3, 1)) + x = np.array([[0, 0.5, 1], [0, 0.5, 1]]) y = gray2rgb(x) - assert_equal(y.shape, (3, 1, 3)) + assert_equal(y.shape, (2, 3, 3)) assert_equal(y.dtype, x.dtype) - x = np.array([[0, 128, 255]], dtype=np.uint8) + x = np.array([[0, 128], [128, 255], [255, 0]], dtype=np.uint8) z = gray2rgb(x) - assert_equal(z.shape, (1, 3, 3)) + assert_equal(z.shape, (3, 2, 3)) assert_equal(z[..., 0], x) assert_equal(z[0, 1, :], [128, 128, 128])