# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# 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`.

`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.

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

## Input Arguments

collapse all

Weighting coefficients for each color channel, specified as a numeric array. If `X` is size m-by-n-by-p, `M` must be size q-by-p, where q is in the range [1,p]. `M` must be type `double`.

Data Types: `double`

Input image, specified as a numeric array of size m-by-n-by-p.

Constant to add to each channel during the linear combination, specified as a numeric vector of length q, where q is number of rows in `M`.

Data Types: `double`

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

## Output Arguments

collapse all

Output image, comprised of the linear combination of the rows of `M` with the color channels of `X`. If `output_type` is not specified, the data type of `Y` is the same as the data type of `X`.

## 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')`