<< Input output | Input output | imread >>

scicv >> Input output > cvtColor

# cvtColor

Converts an image from one color space to another.

### Syntax

    img_out = cvtColor(img_in, code[, nchannels])

### Parameters

img_in

  Input image (Mat).

code

  Color space conversion code (double matrix).

nchannels

  number of channels of the output image (double matrix) (default 0, the number of channels is deduced from the input image and the code).

img_out

  Output image (Mat).

### Description

`cvtColor` convert an input image from one color space to another.

The conversion code name format is `CV_<colorspace_src>2<colorspace_dst>`. Some typical examples:

- CV_BGR2GRAY: convert a RBG color image to a grayscale image (OpenCV channels have the BGR order).
- CV_GRAY2BGR: reverse of the previous conversion.
- CV_BGR2HSV: convert a RBG color image to a HSV color image.

### Examples

    scicv_Init();

    img = imread(getSampleImage("lena.jpg"));

    img_gray = cvtColor(img, CV_BGR2GRAY);

    matplot(img_gray);

    delete_Mat(img);
    delete_Mat(img_gray);

Report an issue
<< Input output | Input output | imread >>