Image hashing in c++, with similar images feature
<p>I'm developing a <a href="https://en.wikipedia.org/wiki/Memoization" rel="nofollow noreferrer">memoization</a> system for similar images. I will divide this question in two subquestions since one is the next step of the other, but I could post two different questions if you think that's more appropriate.</p>

<p><strong>First thing to know:</strong> I don't know nothing about image processing, so please be gentle with this poor guy :)</p>

<p><strong>PROBLEM DESCRIPTION</strong></p>

<p>We have a function <code>ReturnType foo(Image)</code> that takes an image, make some time expensive computation on it and it returns something (which depends on the application). The memoizator that I'm designing is an <code>unordered_map&lt;ImageHash,ReturnType&gt;</code> (or an equivalent structure), so if the user submit the same image twice, it returns directly the already computed <code>ReturnType</code> value. </p>

<p><strong>WHAT I NEED</strong></p>

<p>As you can imagine, I need some <code>HashFunction</code> s.t. <code>HashFunction(Image)=ImageHash</code>, where <code>ImageHash</code> is unique with high probability. </p>

<p>Notice that this <code>ImageHash</code> <strong>must</strong> not depend on the particular run, machine, time. This because the <code>unordered_map</code> will be serialized on file (so it can be used in different runs) and by shared with other users.</p>

<p>Since performance is really crucial, a fast hash function would be good. </p>

<p>I found <a href="https://stackoverflow.com/questions/11336209/fast-and-simple-image-hashing-algorithm">this question</a> about the topic, but the author introduces a lot of constraints on the image (and in addiction no good solution is given).</p>

<p><strong>Note:</strong> There is no constraint on the image, so you can propose any solution you prefer (include the set of image that it's designed for).</p>

<p><strong>Note:</strong> could be SHA-1 a possible solution? I used it only for strings, I don't know if it possible to use it for images (and if it exists a C++ implementation)</p>

<p><strong>THE NEXT STEP</strong></p>

<p>I would like to extend the previous solution so we return the same result for <strong>similar images</strong>. So formally, given <code>Image image1</code> similar to <code>Image image2</code>, then the system returns <code>ReturnType result</code> for <code>image1</code> if <code>(image1,result)</code> <strong>OR</strong> <code>(image2,result)</code> were already previously computed.</p>

<p>I've heard about <a href="http://www.phash.org/" rel="nofollow noreferrer">phash</a> but I don't know if it's suitable for this purpose.</p>