title: Setting Pixel (i,j) in Color Image to Black in OpenCV C++
body: <p>I'm looking to segment a color image in order to try and identify certain features. I'm looking to set a pixel to black if it does not meet some decision rule, else I want to leave the pixel the exact same as it was when it was first read. </p>
  
  <p>I'm reading the image using:</p>
  
  <pre><code>Mat apples = imread("C:/Users.......", CV_LOAD_IMAGE_COLOR); 
  </code></pre>
  
  <p>My attempts so far have been, for setting a pixel in row i and column j to black:</p>
  
  <pre><code>apples.at&lt;uchar&gt;(i,j) = 0;
  </code></pre>
  
  <p>Which, when looping over all rows and columns of the image seems to skip over 2/3rds of the image.</p>
  
  <p>I've also tried:</p>
  
  <pre><code>Vec3b black;
  
  black[0] = 0;
  black[1] = 0;
  black[2] = 0; 
  
  apples.at&lt;Vec3b&gt;(i,j) = black;
  </code></pre>
  
  <p>Which seems to almost filter the image as. Any help would be appreciated! </p>
  
  <p><em>edit</em> I'm looping over the image matrix as follows:</p>
  
  <pre><code> for(int i=0;i&lt;apples.rows;i++)
                  {
                      for(int j=0;j&lt;apples.cols;j++)
                          {
                              if(applescopy[0].at&lt;uchar&gt;(i,j) == 0 || applescopy[1].at&lt;uchar&gt;(i,j) == 0 || applescopy[2].at&lt;uchar&gt;(i,j) == 0 )
                                {
                                  apples.at&lt;Vec3b&gt;(i,j) = black;
                                }
                          }
                  }
  </code></pre>
  
  <p>If I eliminate the "if" statement at the end of the second for and just set apples.at uchar (i,j) = 0; unconditionally, only the left third of the image will become black. </p>
  
  <p><em>edit 2</em> I believe my use of "split" on the original color image seemed to modify the original color image. I've since made a copy of it for use in the loop and am getting more expected results, thanks guys!</p>