I need to create a \'red\' image from a grayscale image. I am using this code:
void build_red(const cv::Mat& in, cv::Mat& out) {
out = Mat::zeros
Why are you converting the image if you have a grayscale image present?
Just create two empty matrix of the same size for Blue and Green.
And you have defined your output matrix as 1 channel matrix. Your output matrix must contain at least 3 channels. (Blue, Green and Red). Where Blue and Green will be completely empty and you put your grayscale image as Red channel of the output image.
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>
using namespace std;
using namespace cv;
int main()
{
Mat img, g, fin_img;
img = imread("Lenna.png",CV_LOAD_IMAGE_GRAYSCALE);
vector<Mat> channels;
g = Mat::zeros(Size(img.rows, img.cols), CV_8UC1);
channels.push_back(g);
channels.push_back(g);
channels.push_back(img);
merge(channels, fin_img);
imshow("img", fin_img);
waitKey(0);
return 0;
}