title: Align two images from a set of four points each
body: <p>I'm playing around in accord.net in C# and am trying to align two images. I'm new to computer vision and wondered if accord.net can do this or if I will have to write something myself.</p>
  
  <p>I have two images and for each image I have four points per image. The points are assigned anti clockwise around the image starting with top left so (TL, TR, BR, BL)</p>
  
  <p>Example:</p>
  
  <p>Image 1 </p>
  
  <pre><code>Point 1(221, 156)
  Point 2(4740, 156)
  Point 3(4740, 3347)
  Point 4(221, 3347)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/4d3V7.jpg" alt="Image 1 - Box"></p>
  
  <p>Image 2</p>
  
  <pre><code>Point 1(157, 213)
  Point 2(4572, 32)
  Point 3(4697, 3221)
  Point 4(282, 3402)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Aw67T.jpg" alt="Image 2 - Box rotated and scaled down"></p>
  
  <p>In the two images image 1's point 1 correlates to image 2's point 1 same with the remaining points.</p>
  
  <p>So what I would like to do is align the two images so the scale, rotation and alignment matches between the two images and I end up with two images when overlayed should look like this image:</p>
  
  <p><img src="https://i.stack.imgur.com/5aTlw.jpg" alt="Result"> </p>
  
  <p>So far I have this, which works for rotation and alignment but doesn't scale the image. from my understanding RANSAC seems to be over kill for this job as I'm already correlating the points? Plus I'd like the images output separately for further image processing.</p>
  
  <pre><code>// Images
  var img1Path = Path.Combine(filePath, "image1.jpg");
  var image1 = new[] { new PointF(221, 156), new PointF(4740, 156), new PointF(4740, 3347), new PointF(221, 3347) };
  
  var img2Path = Path.Combine(filePath, "image2.jpg");
  var image2 = new[] { new PointF(157, 213), new PointF(4572, 32), new PointF(4697, 3221), new PointF(282, 3402) };
  
  // Create Bitmaps
  var img1 = new Bitmap(img1Path);
  var img2 = new Bitmap(img2Path);
  
  var ransac = new RansacHomographyEstimator(0.001, 0.99);
  var homographyMatrix = ransac.Estimate(image1, image2);
  
  var blend = new Blend(homographyMatrix, img1) { Gradient = false };
  var result = blend.Apply(img2);
  
  result.Save("out.jpg", ImageFormat.Jpeg);
  </code></pre>
  
  <p>Thanks!</p>