title: OpenCV threshold with mask
body: <p>I'm trying to use OpenCV's <code>cv::threshold</code> function (more specific <code>THRESH_OTSU</code>), only that I'd like to do it with a mask (any shape), so that the outside (background) is ignored during calculation.</p>
  
  <p>Image is single channel (as it must be), red color bellow is only to mark an example polygon on an image.</p>
  
  <p>I tried using <code>adaptiveThreshold</code>, but there are a couple of problems that make it inappropriate in my case.</p>
  
  <p><a href="https://i.stack.imgur.com/5G8o8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5G8o8.png" alt="enter image description here"></a></p>