title: Implement white balance algorithm from wiki
body: <p>I would like to implement some white balance algorithms from wiki
  <a href="http://en.wikipedia.org/wiki/Color_balance" rel="nofollow">http://en.wikipedia.org/wiki/Color_balance</a></p>
  
  <p>They are just some simple matrix manipulation
  Do openCV offer any functions to do some multiplication
  on a group of pixels like following?</p>
  
  <p>example, 2 x 2, 3 channels Mat A =</p>
  
  <pre><code>0 0 0 1 1 1
  2 2 2 3 3 3
  </code></pre>
  
  <p>3 x 3, 1 channels Mat B =</p>
  
  <pre><code>1 0 0
  0 2 0
  0 0 3
  </code></pre>
  
  <p>A x B = C and C =</p>
  
  <pre><code>0 0 0 1 2 3
  2 4 6 3 6 9
  </code></pre>
  
  <p>I have wrote some generic functions to deal with pixel transformation
  but I would prefer the build in function of openCV if it exist since the
  functions of openCV may do some optimization</p>
  
  <pre><code>template&lt;typename T, typename UnaryFunctor&gt;
  void transform_channel(cv::Mat &amp;src, int channel, UnaryFunctor functor)
  {
      int const channels = src.channels();
      if(channels == 1 &amp;&amp; src.isContinuous()){
          return transform_continuous_channel&lt;T&gt;(src, functor);
      }
  
      for(int row = 0; row != src.rows; ++row)
      {
          auto dst_ptr = get_pointer&lt;T&gt;(src, row, channel);
          for(int col = 0; col != src.cols; ++col){
              *dst_ptr = functor(*dst_ptr);
              dst_ptr += channels;
          }
      }
  }
  </code></pre>