From 4e5c4d3c4d7242c408cab7214db825c08efc215b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 31 Jan 2016 21:50:56 +0100 Subject: [PATCH] Fix rgb2grey for alpha channel --- skimage/color/colorconv.py | 2 +- skimage/color/tests/test_colorconv.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/skimage/color/colorconv.py b/skimage/color/colorconv.py index e9da10e5..1eb63721 100644 --- a/skimage/color/colorconv.py +++ b/skimage/color/colorconv.py @@ -711,7 +711,7 @@ def rgb2gray(rgb): if rgb.ndim == 2: return np.ascontiguousarray(rgb) - rgb = _prepare_colorarray(rgb) + rgb = _prepare_colorarray(rgb[..., :3]) gray = 0.2125 * rgb[..., 0] gray[:] += 0.7154 * rgb[..., 1] diff --git a/skimage/color/tests/test_colorconv.py b/skimage/color/tests/test_colorconv.py index b7805786..96057e3b 100644 --- a/skimage/color/tests/test_colorconv.py +++ b/skimage/color/tests/test_colorconv.py @@ -231,6 +231,10 @@ class TestColorconv(TestCase): assert rgb2grey(x).flags["C_CONTIGUOUS"] assert rgb2grey(x[:5, :5]).flags["C_CONTIGUOUS"] + def test_rgb2grey_alpha(self): + x = np.random.rand(10, 10, 4) + assert rgb2grey(x).ndim == 2 + def test_rgb2grey_on_grey(self): rgb2grey(np.random.rand(5, 5))