title: Getting mean of an image using a mask
body: <p>I have a series of concentric rectangles and wish to obtain the means of the outer rectangle <strong>excluding</strong> the inner rectangle. See the attached diagram , I need to get the mean for the shaded area.
  <a href="https://i.stack.imgur.com/pdEVv.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pdEVv.png" alt="enter image description here"></a></p>
  
  <p>So I am using a mask of the inner rectangle to pass into the <code>cv2.mean</code> method, but I am not sure how to set the mask. I have the following code:</p>
  
  <pre><code>for i in xrange(0,len(wins)-2,1):
      means_1 = cv2.mean(wins[i])[0]
      msk = cv2.bitwise_and(np.ones_like((wins[i+1]), np.uint8),np.zeros_like((wins[i]), np.uint8))
      means_2 = cv2.mean(wins[i+1],mask=msk)
      means_3 = cv2.mean(wins[i+1])[0]
      print means_1,means_2,means_3
  </code></pre>
  
  <p>I get this error for the <code>means_2</code> (<code>means_3</code> works fine).:</p>
  
  <blockquote>
    <p>error:
    /Users/jenkins/miniconda/0/2.7/conda-bld/work/opencv-2.4.11/modules/core/src/arithm.cpp:1021:
    error: (-209) The operation is neither 'array op array' (where arrays
    have the same size and type), nor 'array op scalar', nor 'scalar op
    array' in function binary_op</p>
  </blockquote>