Linear combination of color channels
Y = imapplymatrix(M,X)
Y = imapplymatrix(M,X,C)
Y = imapplymatrix(___,output_type)
This example shows how to create a grayscale image by computing the linear combination of three colors channels.
Read a truecolor image into the workspace.
RGB = imread('peppers.png');
Create a coefficient matrix
M = [0.30, 0.59, 0.11];
Compute the linear combination of the RGB channels using the coefficient matrix.
gray = imapplymatrix(M, RGB);
Display the original image and the grayscale conversion.
M— Weighting coefficients for each color channel
Weighting coefficients for each color channel, specified as a
q-by-p numeric array.
p is the length of the third dimension of
X. In other words,
is in the range [1,p].
X— Input image
Input image, specified as an m-by-n-by-p numeric array.
C— Constant to add to each channel
Constant to add to each channel during the linear combination, specified
as q-element numeric vector, where q
is the number of rows in
output_type— Output data type
Output data type, specified as one of the following: