-
ImageMagick version6.9.13-12 Operating system, version and so onLinux t14s 6.12.6-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.6-1 (2024-12-21) x86_64 GNU/Linux DescriptionHi, I'm trying to locate one picture within another one. I know for sure the picture is present. I asked google for some help and I ended up with this:
The first example is where one picture is a cropped of the other one saved as a JPG (So not binary identical) while the second are non-related pictures. It works pretty well! I have two questions related to this. The first is related to the output. I figured adjusting to those parameters:
makes the things faster. But while I think I understand what similarity-threshold (Thanks to the documentation), dissimilarity-threshold is still a bit obscure to me. Is there a better value I should use for this parameter? Thanks. PS: Because I have 400k pictures to process, performance is important to me. |
Beta Was this translation helpful? Give feedback.
Replies: 0 comments 13 replies
-
Some documentation is at https://imagemagick.org/script/compare.php For "-metric RMSE", the number in parentheses is the score of the best subimage match from 0.0 (exactly the same) to 1.0 (totally different). My rule of thumb is that an RMSE score of less than 0.01 means I can't easily see a difference between the images. Your score of 0.321221 for unrelated images means that the best subimage match was clearly a poor match. The coordinates are the best location (lowest RMSE) of the top-left of the subimage within the large image. Setting "-similarity-threshold 0.01" will stop the search early if any location has that score or better (ie lower). So this may not find the overall best match. Setting "-dissimilarity-threshold 0.1" won't save any time. If the best result is worse than this score, IM will raise an error. The default threshold is less than 1.0, so IM can raise an error even when there is some (fairly poor) match, so I generally use "-dissimilarity-threshold 1". If your IM includes FFTW, this may accelerate the RMSE search. (This is a very recent enhancement to IM.) A multi-scale (aka pyramid) search can greatly improve performance. For example, if you resize both images to 50%, the search space reduces to 1/4, and the number of comparisons also reduces to 1/4, so the total effort reduces to 1/16. The cost is a lack of precision (the found location is plus or minus one), and a theoretical possibility of finding a false match. We can overcome the lack of precision by repeating the search at full size, but heavily cropping the large image so the search space is very small. Even better, we can resize to 50% images to 50%, so the effort is 1/16 * 1/16 = 1/256. And we can keep going while the images are "reasonably" large. This massively accelerates searches. Doing this work in a script is painful, so I have written Process module: multi-scale image search. But that needs you to build IM yourself. |
Beta Was this translation helpful? Give feedback.
-
MSE, RMSE and PSNR are not yet accelerated by FFT processing. But we are currently working on them and they should be added in the very near term. Currently only NCC is accelerated by FFT processing. The current beta has MSE and RMSE seemingly working and we are working on PSNR. But it is a beta. So it could change. |
Beta Was this translation helpful? Give feedback.
-
Use "magick -version". For an installation on my laptop:
So my "Delegates" includes "fftw". I can't find the recent post about RMSE, but see fmw42's response.
This is the score on a scale of 0 to QuantumLevel, which is 65535 for Q16. Note that 366.7 / 65535 = 0.005595. As that number depends on the IM build, I would ignore it.
Yes, but be prepared for IM raising an error. I generally use "-dissimilarity-threshold 1" because that takes no longer, and ensures I won't get that error.
Good stuff.
This is an IM bug. NCC scores in reverse to RMSE: 0.0 is non-match, 1.0 is a match. But the dissimilar test is if the score is greater than the threshold, IM declares the images are too dissimilar. That's another reason to use "-dissimilarity-threshold 1". |
Beta Was this translation helpful? Give feedback.
Some documentation is at https://imagemagick.org/script/compare.php
For "-metric RMSE", the number in parentheses is the score of the best subimage match from 0.0 (exactly the same) to 1.0 (totally different). My rule of thumb is that an RMSE score of less than 0.01 means I can't easily see a difference between the images. Your score of 0.321221 for unrelated images means that the best subimage match was clearly a poor match.
The coordinates are the best location (lowest RMSE) of the top-left of the subimage within the large image.
Setting "-similarity-threshold 0.01" will stop the search early if any location has that score or better (ie lower). So this may not find the overall best match.