Is there a cvtColor to Opponent color space?
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();
- I am not sure, is it correct?
- If there is already an implementation of this conversion, please tell me.
there is a (private) implementation here
Thanks, but how shall I display it?
pardon ? imshow() ?
very funny! I am talking about how to mix the channels, or this is not important (they have no link to each other)?
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);