title: Copying two images pixel by pixel
body: <p>I am trying to work with each pixel from depth map. (I am implementing image segmentation.) I don't know how to work with pixels from image with depth higher than 1.</p>
  
  <p>This sample code copies depth map to another cv::Mat pixel by pixel. It works fine, if I normalize it (depth of normalized image = 1). But it doesn't work with depth = 3, because <code>.at&lt;uchar&gt;</code> is wrong operation for this depth.</p>
  
  <pre><code>cv::Mat res; 
  cv::StereoBM bm(CV_STEREO_BM_NORMALIZED_RESPONSE);
  bm(left, right, res);
  std::cout&lt;&lt;"type "&lt;&lt;res.type()&lt;&lt;" depth "&lt;&lt;res.depth()&lt;&lt;" channels "&lt;&lt;res.channels()&lt;&lt;"\n";// type 3 depth 3 channels 1
  cv::Mat tmp = cv::Mat::zeros(res.rows, res.cols, res.type());
  for(int i = 0; i &lt; res.rows; i++)
  {
      for(int j = 0; j &lt; res.cols; j++)
          {
                  tmp.at&lt;uchar&gt;(i, j) = res.at&lt;uchar&gt;(i, j);
                  //std::cout &lt;&lt; (int)res.at&lt;uchar&gt;(i, j) &lt;&lt; " ";
      }
      //std::cout &lt;&lt; std::endl;
  }
  cv::imshow("tmp", normalize(tmp));
  cv::imshow("res", normalize(res));
  </code></pre>
  
  <p>normilize function</p>
  
  <pre><code>cv::Mat normalize(cv::Mat const &amp;depth_map)
  {
      double min;
      double max;
      cv::minMaxIdx(depth_map, &amp;min, &amp;max);
      cv::Mat adjMap;
      cv::convertScaleAbs(depth_map, adjMap, 255 / max);
      return adjMap;
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/egfgC.jpg" alt="screenshot"></p>
  
  <p>left image - tmp, right image - res</p>
  
  <p>How can I get the pixel from image with depth equal to 3?</p>