Is there a cvtColor to Opponent color space?

asked 2014-09-09 10:09:49 -0600

thdrksdfthmn gravatar image

updated 2020-11-07 02:57:41 -0600

I have started to implement a small application that transforms a BGR image to an Opponent color space image based on this link and also on the thing that the channels (O1, O2, O3) have values between 0 and 255. But I want to ask: Is there an OpenCV function that computes it?

This is my code; I have finished it:

cv::Mat img1 = cv::imread("../car.jpg");
cv::imshow("car", img1);
cv::Mat img1Opponent(img1.rows, img1.cols, img1.type());
std::vector< cv::Mat > img1BGR, img1Opp;
cv::split(img1, img1BGR);
cv::Mat O1 = img1BGR[2] - img1BGR[1];
cv::convertScaleAbs(O1, O1, 1/sqrt(2));
O1 = cv::max(0, cv::min(255, O1));

cv::Mat O2;
cv::add(img1BGR[2], img1BGR[1], O2);
cv::scaleAdd(img1BGR[0], 2, O2, O2);
cv::convertScaleAbs(O2, O2, 1/sqrt(6));
O2 = cv::max(0, cv::min(255, O2));

cv::Mat O3;
cv::add(img1BGR[0], img1BGR[1], O3);
cv::add(O3, img1BGR[2], O3);
cv::convertScaleAbs(O3, O3, 1/sqrt(3));
O3 = cv::max(0, cv::min(255, O3));

cv::imshow("O1", O1);
cv::imshow("O2", O2);
cv::imshow("O3", O3);
cv::imshow("R", img1BGR[2]);
cv::imshow("G", img1BGR[1]);
cv::imshow("B", img1BGR[0]);

img1Opp.push_back(O1);
img1Opp.push_back(O2);
img1Opp.push_back(O3);
std::vector< int > from_to = { 0,0, 1,1, 2,2 };
cv::mixChannels(img1Opp, img1Opponent, from_to);
cv::imshow("img1Opponent", img1Opponent);
cv::waitKey();
  1. I am not sure, is it correct?
  2. If there is already an implementation of this conversion, please tell me.
edit retag flag offensive close merge delete

Comments

there is a (private) implementation here

berak gravatar imageberak ( 2014-09-10 10:11:55 -0600 )edit

Thanks, but how shall I display it?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-09-11 03:37:03 -0600 )edit

pardon ? imshow() ?

berak gravatar imageberak ( 2014-09-11 03:40:02 -0600 )edit

very funny! I am talking about how to mix the channels, or this is not important (they have no link to each other)?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-09-11 04:40:48 -0600 )edit

sorry, i just did not understand you before ... (and i probably still don't)

also, instead of mixChannels it could be a simple merge(img1Opp, img1Opponent);

berak gravatar imageberak ( 2014-09-11 04:44:31 -0600 )edit