Main Content

imapplymatrix

Linear combination of color channels

Description

Y= imapplymatrix(M,X)computes the linear combination of the rows ofMwith the color channels ofX.

Y= imapplymatrix(M,X,C)computes the linear combination of the rows ofMwith the color channels ofX, adding the corresponding constant valueCto each combination.

example

Y= imapplymatrix(___,output_type)returns the result of the linear combination in an array of typeoutput_type.

Examples

collapse all

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.

imshowpair(RGB,gray,'montage')

Figure contains an axes object. The axes object contains an object of type image.

Input Arguments

collapse all

Weighting coefficients for each color channel, specified as aq-by-pnumeric array.pis the length of the third dimension ofX. In other words,p=size(X,3).qis in the range [1,p].

Input image, specified as anm-by-n-by-pnumeric array.

Constant to add to each channel during the linear combination, specified asq-element numeric vector, whereqis the number of rows inM.

Data Types:double

Output data type, specified as one of the following:'double','single',“uint8”,'uint16','uint32','int8','int16', or'int32'.

Data Types:char|string

Output Arguments

collapse all

Output image comprised of the linear combination of the rows ofMwith the color channels ofX, returned as a numeric array. Ifoutput_typeis not specified, the data type ofYis the same as the data type ofX.

版本History

Introduced in R2011b