reference
labkit.image.rgb2gray
Convert RGB data using MATLAB's rgb2gray call contract.
Syntax
gray = labkit.image.rgb2gray(rgb)Description
Converts an RGB image with the ITU-R BT.601 luma coefficients 0.2989, 0.5870, and 0.1140 for red, green, and blue. The output retains the input numeric class. Integer results therefore use MATLAB's normal cast and rounding behavior.
For an M-by-3 colormap, each row is converted to one luma value and that value is repeated across three columns. This preserves the colormap shape while removing color. The function does not clamp floating-point input.
Inputs
rgb- Real, nonsparse M-by-N-by-3 RGB image or M-by-3 colormap of class uint8, uint16, int16, single, or double.
Outputs
gray- M-by-N grayscale image or M-by-3 grayscale colormap with the same numeric class as rgb.
Errors
labkit:image:rgb2gray:InvalidShape- rgb is neither an RGB image nor an M-by-3 colormap.
Example
rgb = cat(3, ones(2), zeros(2), zeros(2));
gray = labkit.image.rgb2gray(rgb);Related APIs
labkit.image.ensureRgb— Return image data with exactly three color channels.labkit.image.im2double— Convert image data to double using MATLAB's im2double contract.labkit.image.adjustBrightnessContrast— Apply simple brightness and contrast adjustment.labkit.image.adjustHueSaturation— Apply HSV hue and saturation adjustment.labkit.image.assertSupportedPaths— Throw when any path has an unsupported image extension.labkit.image.displayName— Return a short image-file display name.labkit.image.fileDialogFilter— Return a file-chooser-compatible image filter.labkit.image.grayWorldWhiteBalance— Apply generic gray-world white balance.
Source
This page is generated from the MATLAB help text in +labkit/+image/rgb2gray.m.