reference
labkit.image.ensureRgb
Return image data with exactly three color channels.
Syntax
rgb = labkit.image.ensureRgb(imageData)Description
Converts grayscale image arrays to RGB by copying the same values into the red, green, and blue channels. RGB input passes through unchanged, and input with more than three channels keeps only the first three. This is useful for removing an alpha or auxiliary channel after image import.
The function does not change numeric values, normalize intensity, or convert the input class. Empty input is returned with its original empty shape.
Inputs
imageData- Nonsparse numeric or logical M-by-N grayscale, M-by-N-by-1 grayscale, M-by-N-by-3 RGB, or M-by-N-by-C array with C greater than three.
Outputs
rgb- Array with the same class and first two dimensions as imageData. Nonempty output has exactly three channels.
Errors
labkit:image:ensureRgb:InvalidChannelCount- Nonempty 3-D input has two color channels.
Example
gray = uint8([0 64; 128 255]);
rgb = labkit.image.ensureRgb(gray);Related APIs
labkit.image.im2double— Convert image data to double using MATLAB's im2double contract.labkit.image.rgb2gray— Convert RGB data using MATLAB's rgb2gray call 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/ensureRgb.m.