title: Crop and transform image in Matlab
body: <p>I'm trying to crop an image but not with a rectangle (like in <code>imcrop()</code>) but with a polygon that has four corners. I've searched a lot and discovered that I need to perform a homography to reajust the cropped polygon into a rectangle. </p>
  
  <p>So I've used <code>imcrop()</code> to select a polygon in an image :</p>
  
  <pre><code>img = imread('pout.tif');
  imshow(img);
  h = impoly;
  position = wait(h);
  x1 = min(position(:, 1));
  x2 = max(position(:, 1));
  y1 = min(position(:, 2));
  y2 = max(position(:, 2));
  BW = createMask(h);
  </code></pre>
  
  <p>How could I use these two things to crop out an area in the shape of a polygon with four corners ?</p>