title: Swap RGB channel color using OpenCV C++
body: <p>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 :</p>
  
  <pre><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 &lt; testcolor.rows; i++) {
      for (int j = 0; j &lt; testcolor.cols; j++  ){ 
          leftimg.at&lt;Vec3b&gt;(i, j)[0] = testcolor.at&lt;Vec3b&gt;(i,j)[0];
          leftimg.at&lt;Vec3b&gt;(i, j)[1] = testcolor.at&lt;Vec3b&gt;(i,j)[0];
          leftimg.at&lt;Vec3b&gt;(i, j)[2] = testcolor.at&lt;Vec3b&gt;(i,j)[2];
  
          rightimg.at&lt;Vec3b&gt;(i, j)[0] = testcolor.at&lt;Vec3b&gt;(i, j)[1];
          rightimg.at&lt;Vec3b&gt;(i, j)[1] = testcolor.at&lt;Vec3b&gt;(i, j)[1];
          rightimg.at&lt;Vec3b&gt;(i, j)[2] = testcolor.at&lt;Vec3b&gt;(i, j)[2];
      }
  }
  
  cvtColor(leftimg, leftimg, COLOR_BGR2RGB);
  imwrite("leftimg.png", leftimg);
  cvtColor(rightimg, rightimg, COLOR_BGR2RGB);
  imwrite("rightimg.png", rightimg);
  </code></pre>
  
  <p>But I don't think I got the result that I expected.
  This is the original image.
  <a href="https://i.stack.imgur.com/BftV1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BftV1.jpg" alt="This is the original image"></a></p>
  
  <p>and this is the reult image :
  <a href="https://i.stack.imgur.com/mLRqI.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mLRqI.jpg" alt="enter image description here"></a></p>
  
  <p>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 ?</p>
  
  <p>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.</p>