title: The fast efficient way to normalize each channel of an image with different value
body: <p>I have to divide all the pixels of each channel by a value (normalization). What I do is split the image into three channels, divide all pixels and then merge back the three channels. Here is how I do it:</p>
  
  <pre><code>template &lt;typename T, typename ... Ts&gt;
  void insert_all(std::vector&lt;T&gt; &amp;vec, Ts ... ts)
  {
      (vec.push_back(ts), ...);
  } 
  
  std::vector&lt;cv::Mat&gt; rgb, rgbN; 
  cv::split(src, rgb); //src is my RGB image
  
  rgbN.reserve(3);
  insert_all(rgbN, cv::Mat_&lt;float&gt;(rgb[0])/A0, 
                   cv::Mat_&lt;float&gt;(rgb[1])/A1, 
                   cv::Mat_&lt;float&gt;(rgb[2])/A2);
  cv::Mat srcN;
  cv::merge(rgbN, srcN_gray); 
  </code></pre>
  
  <p>I think it is too much code for a simple normalization, is there a better way to do it, probably without spiting and merging?</p>