Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

Convert Luminous and Color Opponent Channels to RGB Image

$
0
0
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](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(y, x); pixel[0] = pixel[1] = pixel[2] = channel.at(y, x); For red-green and yellow-blue (I expect this is where the problem is): float opponency = (float)channel.at(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: ![Original image](/upfiles/14718276557571848.jpg) I achieved these RGB representations of each channel ![Luminous](/upfiles/14718279133881573.png) ![redminusgreen](/upfiles/14718279657079265.png) ![yellowminusblue](/upfiles/14718279726572091.png) I then get the original back by taking the average RGB value: ![reconst0](/upfiles/14718285284736472.png) 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: ![reconst1](/upfiles/14718282316643887.png)

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>