title: OpenCV: Multiply Images in C++ and C
body: <p>I've just used the multiply functions using C api (cvMul) and C++ api (mul and multiply). But I get a different result from the C function and the C++ ones</p>
  
  <ul>
  <li><a href="http://i.stack.imgur.com/0NieG.jpg" rel="nofollow">Result of cvMul</a> (it is a white image)</li>
  <li><a href="http://i.stack.imgur.com/ArvjH.jpg" rel="nofollow">Result of mul and multiply</a></li>
  </ul>
  
  <p>Here is the code I use for both implementations:</p>
  
  <p>C</p>
  
  <pre><code>IplImage * gh = cvCreateImage(cvGetSize(input),IPL_DEPTH_32F,1) ;
  cvSobel(input,gh,1,0) ;
  
  IplImage * gh2 = cvCreateImage(cvGetSize(input),IPL_DEPTH_32F,1) ;
  cvMul(gh,gh,gh2) ;
  </code></pre>
  
  <p>C++</p>
  
  <pre><code>Mat gh = Mat (input.size(), CV_32FC1);
  Sobel(input, gh, CV_32FC1, 1, 0);
  
  Mat gh2 = Mat (input.size(), CV_32FC1);
  gh2 = gh.mul(gh); // multiply (gh, gh, gh2);  
  </code></pre>
  
  <p>The input image is the same, and when I check the horizontal gradient it is also the same for both implementations, so why would the multiplication give different results? (I am interested in getting the result of the C implementation)</p>