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))