From 4d1809a63c3bbdd6d29f240092cde3c4f287bfc8 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sun, 8 Jul 2012 17:49:17 -0700 Subject: [PATCH] BUG: Allow rgb2grey to be called on grey-level images. --- skimage/color/colorconv.py | 3 +++ skimage/color/tests/test_colorconv.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/skimage/color/colorconv.py b/skimage/color/colorconv.py index 274581b5..5e2fa5e1 100644 --- a/skimage/color/colorconv.py +++ b/skimage/color/colorconv.py @@ -511,6 +511,9 @@ def rgb2grey(rgb): >>> lena = imread(os.path.join(data_dir, 'lena.png')) >>> lena_grey = rgb2grey(lena) """ + if rgb.ndim == 2: + return rgb + return _convert(grey_from_rgb, rgb[:, :, :3])[..., 0] rgb2gray = rgb2grey diff --git a/skimage/color/tests/test_colorconv.py b/skimage/color/tests/test_colorconv.py index 84c921b8..cfe81c58 100644 --- a/skimage/color/tests/test_colorconv.py +++ b/skimage/color/tests/test_colorconv.py @@ -146,6 +146,9 @@ class TestColorconv(TestCase): assert_equal(g.shape, (1, 1)) + def test_rgb2grey_on_grey(self): + rgb2grey(np.random.random((5, 5))) + def test_gray2rgb(): x = np.array([0, 0.5, 1])