Converting greyscaled images into colored ones using OpenCV (C++)

  

This page explains the way to convert greyscale images into colored images using OpenCV's function. Note that the contents of the page is in C++.

Environment:

  • OpenCV 4.6

  • Ubuntu 20.04

Method#

Use cv::cvtColor to convert color.

cv::Mat grey_image;// contains grey image data
cv::Mat color_image;
cv::cvtColor(original_image, color_image, cv::COLOR_GRAY2RGB);

Description#

cv::cvtColor is a API for conversion from one color space to another. As noted above, if you have greyslace image as an ordinary image file, you can convert it by imread . This page's method is for greyscale data generated from binary data like get RAW data from the CMOS image sensor or etc.

cv::cvtColor takes variety of arguments since the API is for color space conversion. See the API manual linked below.

OpenCV
C++