title: How to mask a floating-point image in OpenCV?
body: <p>I have a <code>Nx1</code> matrix of floating-point values. I wish to get the average of only those values starting from the <code>22nd</code> to the <code>Nth</code> item.  I have created a binary mask of <code>Nx1</code> dimensions, put <code>0s</code> in the range <code>[0,21]</code> and <code>1s</code> in the rest. Applying that mask while calculating the average (using inbuilt functions for maximum speed) gives an error. The code snippet is given below.</p>
  
  <p>The error is:</p>
  
  <blockquote>
    <p>sizes on input arguments do not match in cvSvg()"</p>
  </blockquote>
  
  <p>What should be the correct mask? I have tried using floating-points instead of integers in the mask, still not working.</p>
  
  <pre><code>CvMat mask;
  int i;
  int N = img-&gt;width;
  IplImage* W = cvCreateImage( cvSize(N, 1), IPL_DEPTH_32F , 1 );
  IplImage* A = cvCreateImage( cvGetSize(img), IPL_DEPTH_32F , 1 );
  cvConvertScale(img, A);
  int* vals = (int*)malloc(N*sizeof(int));
  
  for(i=0; i&lt;N; i++)
  {
      if(i&lt;22)
          vals[i] = 0;
      else
          vals[i] = 1;
  }
  cvInitMatHeader(&amp;mask, N, 1, CV_8U, vals);
  
  cvSVD(A, W, NULL, NULL, CV_SVD_MODIFY_A);
  
  CvScalar mean = cvAvg(W, &amp;mask);
  </code></pre>