title: How to detect if two images are the same with different cropping ratios?
body: <p>I have two different images with different dimensions:</p>
  <p>100px</p>
  <p><a href="https://i.stack.imgur.com/aIlRk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aIlRk.jpg" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/2Shhq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2Shhq.jpg" alt="enter image description here" /></a></p>
  <p>and 400px</p>
  <p><a href="https://i.stack.imgur.com/MR16I.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MR16I.jpg" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/MwxbV.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MwxbV.jpg" alt="enter image description here" /></a></p>
  <p>As you can see the two are clearly the &quot;same&quot; from a human point of view. Now I wanna detect if they are the same. I have been using image magic via the ruby gem called <code>rmagick</code> like so:</p>
  <pre><code>img1 = Magick::Image.from_blob(File.read(&quot;image_1.jpeg&quot;)).first
  img2 = Magick::Image.from_blob(File.read(&quot;image_2.jpeg&quot;)).first
  
  if img1.difference(img2).first &lt; 4000.0 # I have found this to be a good threshold, but does not work for cropped images
    puts &quot;they are the same!!!&quot;
  end
  </code></pre>
  <p>While this works well for images that have same ratio/cropping, it is not ideal when they have slightly different cropping and has been resized to the same width.</p>
  <p>Is there a way to do it for images with different cropping? I am interested in a solution where I can say something like: One image is contained inside the other and covers somewhere around e.g. 90% of it.</p>
  <p>PS. I can get the images in higher resolution if that helps (e.g. the double)</p>