title: Image Processing: how to imwarp with mask on destination
body: <p>I want to implement a function similar to Matlab's imwarp</p>
  <p><a href="https://www.mathworks.com/help/images/ref/imwarp.html?requestedDomain=www.mathworks.com" rel="nofollow noreferrer">https://www.mathworks.com/help/images/ref/imwarp.html?requestedDomain=www.mathworks.com</a></p>
  <pre><code>function [output] = maskedImwarp(im, tform, mask)
      ???
  end
  </code></pre>
  <p>so that it will do the same as imwarp (for projective2d is enough, no need for any extras), but will only calculate for the ROI defined by mask.</p>
  <p>I want to reduce the runtime by doing less calculations.</p>
  <p>How can this be done in the most efficient and elegant way?</p>
  <p>I would just do a for loop on every '1' in the mask, and calculate where it came from in 'im', and then interpolate, but I think it would be much slower than possible if I used some matrix magic.</p>