I simply can't for the love of god do a simple damn conversion and it's been bugging me over the last weekend: https://en.wikipedia.org/wiki/Rg_chromaticity
Can anyone help out with an efficient way to do this in OpenCV? I keep getting black images, here's my current attempt:
for (int i = 0; i < mRgb.cols; i++) {
for (int j = 0; j < mRgb.rows; j++) {
Vec3b intensity = mRgb.at<Vec3b>(j, i);
float b = intensity.val[0];
float g = intensity.val[1];
float r = intensity.val[2];
float rgbSum = (float) (r + g + b);
float redNorm = (float) (r / rgbSum);
float greenNorm = (float) (g / rgbSum);
float blueNorm = (float) (b / rgbSum);
res.at<Vec3b>(j, i)[0] = blueNorm;
res.at<Vec3b>(j, i)[1] = greenNorm;
res.at<Vec3b>(j, i)[2] = redNorm;
}
}
I am positive this can be done more efficiently, please help me out. Isn't there a way in which you can split the channels, divide them to the channel sum and then add up the 3 new channels into a new image? In matlab it's done like this: http://stackoverflow.com/questions/21712828/convert-image-to-a-chromaticity-image
Regards!