Let's define what we discussing exactly.
If we're talking about «compare 2 images, common case» for similarity (i.e. calculate some abstract difference) which can be used in different contexts (comparing 2 photos in series, compare original and processed image, compare screenshots) – it worths discussing. In contrast, any partial solution (like screenshot-only comparison) should be implemented outside AM.
In any case, we need at least «compensate the motion» before comparing, eliminate shift and size difference. In other words, find overlapping rectangle. Otherwise even for the 1 pixel offset, we will get high absolute error count. The funny part is recursion – in order to find this «overlapping», we need a method to (fuzzy) comparing images' parts!
No doubts, trying to implement it is surely reinventing the wheel.
OpenCV looks a proper tool, but it's a very heavy dependency for the AM. Of course, we do not need a whole OpenCV, but someone should fork needed parts and maintain it over years. Here's a relatively fresh
imagemagick port, but it looks like one-time homework.
The good news is that we can use a ready and well-tested
code from
geeqie (i'm used «find duplicates» in geeqie many times and it's good):
1. I've compared original car photo with sharpened/cropped version, got 96 similarity
2. 2 screenshots, which I took carelessly (significant shift and size difference), got 96 similarity
3. 2 screenshots, which I took carefully, got 99 similarity
The C source code is not complex and can be easily ported to Java or whatever needed.