This is a development version (0.26.1rc0.dev0) and may be unstable.Go to latest (0.26.1rc0.dev0+git20260530.b607368ff)
{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0 / skimage / color / colorconv / rgb2gray

function

skimage.color.colorconv:rgb2gray

source: /_skimage2/color/colorconv.py:936

Signature

def rgb2gray(rgb, *, channel_axis = -1)

Summary

Compute luminance of an RGB image.

Parameters

rgb : (..., C=3, ...) array_like

The image in RGB format. By default, the final dimension denotes channels.

Returns

out : ndarray

The luminance image - an array which is the same size as the input array, but with the channel dimension removed.

Raises

: ValueError

If rgb is not at least 2-D with shape (..., C=3, ...).

Notes

The weights used in this conversion are calibrated for contemporary CRT phosphors

Y = 0.2125 R + 0.7154 G + 0.0721 B

If there is an alpha channel present, it is ignored.

Examples

from skimage.color import rgb2gray
from skimage import data
img = data.astronaut()
img_gray = rgb2gray(img)
✓

Aliases

  • skimage.color.rgb2gray