# imapplymatrix

Linear combination of color channels

## Syntax

`Y = imapplymatrix(M,X)Y = imapplymatrix(M,X,C)Y = imapplymatrix(..., output_type)`

## Description

`Y = imapplymatrix(M,X)` computes the linear combination of the rows of `M` with the color channels of `X`. The output data type is the same as the type of `X`.

`Y = imapplymatrix(M,X,C)` computes the linear combination of the rows of `M` with the color channels of `X`, adding the corresponding constant value from `C` to each combination. The output data type is the same as the type of `X`.

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

## Input Arguments

 `M` Matrix that contains the coefficients of the weighting matrix. If `X` is m-by-n-by-p, `M` must be q-by-p, where q is in the range [1,p]. `X` An image. `C` A vector with the same number of elements as the number of rows in `M`, or a scalar applied to every channel. `output_type` A string that describes the output type. Possible values include `uint8`, `int8`, `uint16`, `int16`, `uint32`, `int32`, `single`, or `double`.

## Output Arguments

 `Y` Array that contains the linear combination of the rows of `M` with the color channels of `X`.

## Examples

Convert RGB values to grayscale:

```RGB = imread('peppers.png'); M = [0.30, 0.59, 0.11]; gray = imapplymatrix(M, RGB); figure subplot(1,2,1), imshow(RGB), title('Original RGB') subplot(1,2,2), imshow(gray), title('Grayscale Conversion')```