Linear combination of color channels
returns the result of the linear combination in an array of type
Y = imapplymatrix(___,
Compute Linear Combination of Color Channels
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
q-by-p numeric array
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
q-element numeric vector
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
Y — Output image
Output image comprised of the linear combination of the rows of
M with the color channels of
X, returned as a numeric array. If
output_type is not specified, the data type of
Y is the same as the data type of
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Version HistoryIntroduced in R2011b
R2022b: Support for thread-based environments
imapplymatrix now supports thread-based