diff --git a/skimage/color/colorconv.py b/skimage/color/colorconv.py index 875c937b..e9da10e5 100644 --- a/skimage/color/colorconv.py +++ b/skimage/color/colorconv.py @@ -709,7 +709,7 @@ def rgb2gray(rgb): """ if rgb.ndim == 2: - return rgb + return np.ascontiguousarray(rgb) rgb = _prepare_colorarray(rgb) @@ -719,6 +719,7 @@ def rgb2gray(rgb): return gray + rgb2grey = rgb2gray diff --git a/skimage/color/tests/test_colorconv.py b/skimage/color/tests/test_colorconv.py index 4c991416..b7805786 100644 --- a/skimage/color/tests/test_colorconv.py +++ b/skimage/color/tests/test_colorconv.py @@ -226,6 +226,11 @@ class TestColorconv(TestCase): assert_equal(g.shape, (1, 1)) + def test_rgb2grey_contiguous(self): + x = np.random.rand(10, 10, 3) + assert rgb2grey(x).flags["C_CONTIGUOUS"] + assert rgb2grey(x[:5, :5]).flags["C_CONTIGUOUS"] + def test_rgb2grey_on_grey(self): rgb2grey(np.random.rand(5, 5))