Naive question, I'm working with color processing for the first time. I want to swap RGB channel from Mat image. What I'm trying to do create another image from the original image and assign the R and G value as R. And then on another image, assign R and G value as G. Here's my code :
Mat testcolor = imread("tulip.jpg", CV_LOAD_IMAGE_COLOR);
int rows = testcolor.rows;
int cols = testcolor.cols;
Mat leftimg(rows, cols, CV_8UC3);
Mat rightimg(rows, cols, CV_8UC3);
cvtColor(testcolor, testcolor, COLOR_RGB2BGR);
for (int i = 0; i < testcolor.rows; i++) {
for (int j = 0; j < testcolor.cols; j++ ){
leftimg.at<Vec3b>(i, j)[0] = testcolor.at<Vec3b>(i,j)[0];
leftimg.at<Vec3b>(i, j)[1] = testcolor.at<Vec3b>(i,j)[0];
leftimg.at<Vec3b>(i, j)[2] = testcolor.at<Vec3b>(i,j)[2];
rightimg.at<Vec3b>(i, j)[0] = testcolor.at<Vec3b>(i, j)[1];
rightimg.at<Vec3b>(i, j)[1] = testcolor.at<Vec3b>(i, j)[1];
rightimg.at<Vec3b>(i, j)[2] = testcolor.at<Vec3b>(i, j)[2];
}
}
cvtColor(leftimg, leftimg, COLOR_BGR2RGB);
imwrite("leftimg.png", leftimg);
cvtColor(rightimg, rightimg, COLOR_BGR2RGB);
imwrite("rightimg.png", rightimg);
But I don't think I got the result that I expected.
This is the original image.
I expect something like, if I assign R and G as R --> The green part will have some red shades. And if I assign R and G as G, the red part will have some green shades. Did I miss something in my code ? or I'm lacking understanding ?
In this case, I dont have raw image, and I didn't convert my color space because I wanted to see how it worked with RGB. And then if needed I will convert the color space later.