From 65a29071fe31e7ea6e89f0d09e36e6cb3db2e0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 31 Jan 2016 19:21:03 +0100 Subject: [PATCH] Speedup rgb2gray and return congiguous array --- skimage/color/colorconv.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/skimage/color/colorconv.py b/skimage/color/colorconv.py index 137c14c0..875c937b 100644 --- a/skimage/color/colorconv.py +++ b/skimage/color/colorconv.py @@ -707,10 +707,17 @@ def rgb2gray(rgb): >>> img = data.astronaut() >>> img_gray = rgb2gray(img) """ + if rgb.ndim == 2: return rgb - return _convert(gray_from_rgb, rgb[:, :, :3])[..., 0] + rgb = _prepare_colorarray(rgb) + + gray = 0.2125 * rgb[..., 0] + gray[:] += 0.7154 * rgb[..., 1] + gray[:] += 0.0721 * rgb[..., 2] + + return gray rgb2grey = rgb2gray