Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 4615

Converting RGB into LMS model using C++ and OpenCV

$
0
0
I'm trying to convert image with RGB colorspace into LMS model. The transformation matrix value I got from this [paper](https://arxiv.org/pdf/1711.10662.pdf). I read this [Question : RGB to LMS color space conversion with OpenCV](https://stackoverflow.com/questions/35671531/rgb-to-lms-color-space-conversion-with-opencv), we referred to the same paper and I already followed all the instructions in the answer. To make sure my codes do well, I convert the original RGB into LMS, then convert the LMS back into RGB using inverse matrix of the first matrix, and see if the output matches the original image. ![image description](/upfiles/15170623937362908.png) But the output doesn't match the original image source. Here's my code : void test(const Mat &original, Mat &pic, int rows, int cols) { for (int i = 0; i < original.rows; i++) { for (int j = 0; j < original.cols; j++) { //RGB into LMS pic.at(i, j)[0] = original.at(i, j)[0] * 1.4671 + original.at(i, j)[1] * 0.1843 + original.at(i, j)[2] * 0.003; //B-->S pic.at(i, j)[1] = original.at(i, j)[0] * 3.8671 + original.at(i, j)[1] * 27.1554 + original.at(i, j)[2] * 3.4557; //G-->M pic.at(i, j)[2] = original.at(i, j)[0] * 4.1194 + original.at(i, j)[1] * 43.5161 + original.at(i, j)[2] * 17.8824; //R-->L //LMS back into RGB pic.at(i, j)[0] = pic.at(i, j)[0] * 0.6935 + pic.at(i, j)[1] * -0.0041 + pic.at(i, j)[2] * -0.0004; //S-->B pic.at(i, j)[1] = pic.at(i, j)[0] * -0.1136 + pic.at(i, j)[1] * 0.0540 + pic.at(i, j)[2] * -0.0102; //M-->G pic.at(i, j)[2] = pic.at(i, j)[0] * 0.1167 + pic.at(i, j)[1] * -0.1305 + pic.at(i, j)[2] * 0.0809; //L-->R } } } Main int main(int argv, char** argc){ Mat original= imread("original.png", CV_LOAD_IMAGE_COLOR); int rows = original.rows; int cols = original.cols; Mat pic(rows, cols, CV_8UC3); test(original, pic, rows, cols); imwrite("pic.png", pic); } Any suggestion ? Any help will be appreciated.

Viewing all articles
Browse latest Browse all 4615


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