magick wrote:The code is templated but it needs more work. Perhaps by tomorrow evening.
OK. No problem and no hurry. If you can, give me a heads up when there is something firmed up to test.
Fred
magick wrote:The code is templated but it needs more work. Perhaps by tomorrow evening.
Yes, the match coordinates (or pixels in the output) reference where the top left corner pixel in the smaller image is located in the larger image.anthony wrote:Fred, in your cross corelation matching of images, the resulting images spikes to mark the top-left corner position for placement of the smaller image.
I don't understand about the 180 rotate. NCC is very sensitive to rotation and the matching will fall apart if the images are not reasonably aligned.anthony wrote: What if the two images being compared are both cropped from a larger image, with partical overlap. The best match may be such that the top left corner of the smaller 'search image' is at a negative location! The cross correlation you have would not find such a match unless both images are rotated 180 degrees!
I don't know for sure. I have never worked on that. But it was a very familiar problem when I was in the virtual tour business. But we used commercial software for that. I believe that they find unique features in the two images in the overlap area and match very small subsections from one to the other in a limited distance. I suspect they do not use FFT, but direct correlation matching in the spatial domain as they have small subsections and know about where to look in the other image, so the search area is also small. This is due often to manual initial coarse alignment. But it has been years since I did any of that.[/quote]anthony wrote: This is probably a common problem when trying to stitch photos together, where you are trying to find the best overlapping location, without using image registration methods.
Any thought on this?
No, unfortunately, I have not seen that. But that may also be included in the process mentioned above after finding match locations for however many feature subsections as they might do. Perhaps it is just a least squares fit of the subsection match locations.anthony wrote: Also do you have any information of finding correspondences between sets of image registration coordinates. These may be a much faster way of doing sub image searches as it vastly reduces the data to correlate, and may also handle scaling and rotational matching of images.
magick wrote:The current implementation of subimage search is extremely naive. We simply scan across the image and look for zero distortion as defined by the -fuzz option. The only speed-up is as the current search exceeds the current distortion level, the search is aborted and we try again at the next (x,y). Feel free to replace the current ExtractSubImageFromImage() method with whatever algorithm might improve the subimage search process.
magick wrote:Let's get a starting point. Try this command sequence. Once it works we will go from there:
Here the compare program successfully found the subimage at (340,160).
- convert logo: logo.png
convert logo.png -crop 150x100+340+160 wizard.png
compare -metric rmse logo.png wizard.png null:
0 (0) @ 340,160
magick wrote:Next up, use the same compare command but first change on pixel in the wizard.png image. If you do not specify the fuzz option, the comparison will fail. However, if you specify a -fuzz 1% option you see how the metric is now useful. The compare program found the subimage and measure the distortion between the original and its reconstruction. You can also visualize which pixel was changed with the difference image. All very cool but very slow (for now until we improve this algorithm).
You might have noticed that what we just said in fact does not work. We have a patch for the problem. Look and updated beta with the patch later tonight or tomorrow.
Code: Select all
convert logo: -resize x180 -gravity center -crop 180x180+0+0! logo.png
convert logo.png -crop 25x25+130+31 star.png
compare -metric rmse logo.png star.png null:
However if I used a JPEG images so pixels will differ slightly!!!0 (0) @ 130,31
Code: Select all
convert logo: -resize x180 -gravity center -crop 180x180+0+0! logo.jpg
convert logo.jpg -crop 25x25+130+31 star.jpg
compare -fuzz 10% -metric rmse logo.jpg star.jpg null:
showing an approximate maximim fuzz difference of about 2.8% over the whole image (not exact). Changing fuzz does not help in any case.1859.64 (0.0283763) @ 0,0
Yeap it does now work for a in-exact JPG imagemagick wrote:We adjusted the algorithm sensitivity and your example now works.
Code: Select all
convert logo: -resize x180 -gravity center -crop 180x180+0+0! logo.jpg
convert logo.jpg -crop 25x25+130+31 star.jpg
compare -fuzz 10% -metric rmse logo.jpg star.jpg null:
removing the fuzz results in an immediate "image size differs" error which I presume indicates the sub image very quickly failed to match at every location.2154.36 (0.0328734) @ 130,31
OK. I can understand using -fuzz as a threshold limit or cut-off on the metric to stop the processing at any given smaller image shift relative to the larger one, since once the fuzz value is reached by the metric, there is no point in evaluating any further pixels in the metric for that shift value. That makes more sense to me than if any pixel exceeds the fuzz threshold.anthony wrote:Because the pixels do not match exactly!!!!!
I am not ceratin on the extact method used but there are two that could be in use.
It would be used to just abort the compare for the current position until a pixel falls outside the fuzz distance, as soon as this happens reject the compare and move on, I believe this is what it does. In other word no chance of getting a map of how closely an image compares (as you get with FFT) at every point, and it is generally a lot faster.
Another way is to add up differences between pixels until the metric goes beyond the fuzz percentage, and then abort. That is the meaning of fuzz depends on the metric, AE for a count of matching pixels (though for that we need a -fuzz for pixel matching and a fuzz for comparison counts), or PAE for peak color difference, or the average count goes about the fuzz threshold.
The former is probably want is being used. while the latter would be slower and harder to implement, but can be more useful. However a different option to -fuzz should be used as a 'comparison limit factor'
Note the the above does not mention anything about WHAT exactly is returned with regard to the best match. Is it the best metric fit? Or just the first match found? Or a list of the best matching positions. All of these could be useful!