magick wrote:Anthony, the algorithm is encoded in magick/transform.c/ExtractSubimageFromImage() and its quite compact. Feel free to review and improve as you see fit.
I am not the best reader of code, but if I have not misinterpreted, then it looks like it does the following:
1) For each shift position of the small image relative to the larger, get the subsection of the larger image. Initialize "similarity" to zero.
2) Loop over columns and rows and for each pixel:
3) Get the sum of squared differences between each channel normalized (range 0 to 1) value for a given pixel and call it "similarity".
4) Accumulate "similarity across a given row.
5) At the end of a row, take square root and normalize by the number of pixels processed by all rows so far, and call this "normalized_similarity"
6) Compare the "normalized_similarity" to the "similarity_threshold" (which is initialized to fuzz/100). If the normalized similarity > similarity_threshold, stop processing.
7) If not >, continue accumulating with the next row.
8 ) If reach end of subsection, keep "normalized_similarity", which is just the RMSE error for that subsection.
9) Test the returned "normalized_similarity" with the "similarity_threshold". If "normalized_similarity" < current "similarity_threshold", then save "normalized_similarity" as "similarity_threshold" along with X,Y coordinates of shift position of subsection relative to top left corner of larger image.
10) Continue with the next subsection.
11) At the end, we will have the first occurrence of the smallest RMSE value.
Looks like no matter what -metric you supply to compare, it will always compute the RMSE metric and return that!
Anthony or Magick, let me know if this is more or less correct or if I have misunderstood.
Fred