title: How to Optimise OpenCV Histogram Comparison for Image Similarity?
body: <p>I use <a href="http://study.marearts.com/2014/11/opencv-emdearth-mover-distance-example.html" rel="nofollow noreferrer">example code</a> to compare HSV histograms using EMD.</p>
  
  <p>I want to find similar images in people's (mobile) picture library. It's quite common that people take several images of the same subject (in a row) with just slight changes: zooming in/out a bit, different angle, different exposure as a result of changing position, other pose, ....</p>
  
  <p>I selected 4 sets of 4 similar images to test this algorithm. When comparing the images inside the sets, I get 22 EMD-L1 values between roughly 0.25 and 2.25 (average 1.47) and 2 outliers around 7.2.</p>
  
  <p>When I cross-comparing between sets I get values between 2 and 15 with an average around 8.</p>
  
  <p>Yes, there is a significant range difference between the two result sets. But I was disappointed that there was no (gap) between these ranges, and instead a small overlap [2.0, 2.25]. I'm hoping to improve the algorithm.</p>
  
  <p>How can I optimise my comparison for my particular use-case? There are various histogram forms, various histogram comparison algorithms, and then each has various parameters.</p>
  
  <p>Does OpenCV implement the fastest known EMD algorithm? I was surprised that the comparison of some histograms took up to a second; especially with the relatively small bin numbers.</p>
  
  <p>Then, some cross-comparisons give good EMD results, but have totally different RGB histograms. Here are two images:</p>
  
  <p><a href="https://i.stack.imgur.com/gRBfE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gRBfE.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/45U8V.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/45U8V.jpg" alt="enter image description here"></a></p>
  
  <p>My current EMD-L1 says 1.95, but the RGB histograms are totally different.</p>