Good Day!
I can't seem to find the right terms for what I want done in OpenCV. Here's the situation:
I have a grayscale image and color (BGR).
I want to 'apply' the color to the grayscale image but keeping the luma and save it afterwards.
My original thought process was:
This is what I've done so far:
cv::Mat pixelColor(1, 1, CV_8UC3, cv::Scalar(0));
pixelColor.at<cv::Vec3b>(1, 1) = cv::Vec3b(128, 255, 0); // currently hard-coded but it actually comes from another source
cv::cvtColor(pixelColor, pixelColor, CV_BGR2Luv);
pixelColor.at<cv::Vec3b>(1, 1)[0] = image.at<unsigned char>(y, x);
cv::cvtColor(pixelColor, pixelColor, CV_Luv2BGR);
I iterate over all y and x of my grayscale image. The actual color comes elsewhere but it's guaranteed to be BGR.
My questions are: (1) what's the proper term for this process? (2) where am I going wrong?
I suppose you could refer to this process as channel swapping or channel replacing? You shouldn't need to explicitly iterate over the pixels in your images.
It would probably be easiest to split() your LUV image into a vector of Mats.
vector<Mat> channels;
cv::split(LUVMAT,channels);
This gives you 3, single channel Mats L, U, and V in your vector.
Then replace the 'L' Mat in the vector with the grayscale (single-channel) Mat using standard vector operations. Finally, merge the result back into a 3 channel Mat.
Mat newLuma;
cv::merge(temp,newLuma);
Then convert "newLuma" back to BGR.