I converted the RGB channels of an image to luminous and color opponent channels; now I am trying to convert the opponent channels back to RGB (using only luminous and the opponent channels), but I do not know how to compute R, G, and B given luminous, red-green, and yellow-blue. How do we go back to RGB from luminuous, red-green, and yellow-blue?
My Method
I converted the RGB image to the opponent channels using the method here: https://github.com/opencv/opencv/blob/2.4/modules/features2d/src/descriptors.cpp#L126. I am not sure why this method does green-red for the red-green channel; for the moment I changed that part to do red-green instead.
To get the original image back, i converted each channel to RGB. For luminous:
cv::Vec3b& pixel = rgbEquivalent->at<cv::Vec3b>(y, x);
pixel[0] = pixel[1] = pixel[2] = channel.at<uchar>(y, x);
For red-green and yellow-blue (I expect this is where the problem is):
float opponency = (float)channel.at<uchar>(y, x);
//Depending on the opponent channel, may represent red or yellow.
float redOrYellow = (opponency - 128.0f) * 2.0f;
//Depending on the opponent channel, may represent green or blue.
float greenOrBlue = (128.0f - opponency) * 2.0f;
if (redOrYellow < 0.0f)
redOrYellow = 0.0f;
if (greenOrBlue < 0.0f)
greenOrBlue = 0.0f;
if (type == RED_MINUS_GREEN)
{
pixel[0] = 0;
pixel[1] = (uchar)greenOrBlue;
pixel[2] = (uchar)redOrYellow;
}
else
{
pixel[0] = (uchar)greenOrBlue;
pixel[1] = (uchar)redOrYellow;
pixel[2] = (uchar)redOrYellow;
}
For the image:
I achieved these RGB representations of each channel
I then get the original back by taking the average RGB value:
But this image is too dark. Maybe the color difference channels are too dark to begin with?
Summing all the RGB values is not right either: it results in random color patches due to some values going above 255: