IsImageSimilar use..

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Explosion_Of_Colour

IsImageSimilar use..

Post by Explosion_Of_Colour »

Afternoon folks,

I'm getting a little confused with the IsImageSimilar functionality, as I've used find_similar_region from rmagick where the function returns the position of the similar region found - am I right in thinking IsImageSimilar doesn't? Is there another function that will return the found position?

Thanks very much,
Becky
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: IsImageSimilar use..

Post by magick »

Use MagickCore's SimilarityImage() which includes an offset parameter to return the subimage location.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: IsImageSimilar use..

Post by anthony »

Please note that if the search image is large, then this can very VERY VERY slow.
That is because it compares the image at each and every location.

The functionality is already present on the commandline though the "compare" command. If the second image is smaller than the first, that command outputs two images, the match comparison, plus a image of how good the match was in each location so you can find multiple matches.

I have not yet documented this feature in IM examples though :-(

Currently in progress are additions that should eventually allow you to use Fast Fourier Transforms, to to compare two large images to find their locations, at a much higher speed. This is however still in development with a lot more work to do. However Fred Weinhaus has already written some scripts for FFT sub-image searching using IM, even though it is still not part of the core IM.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Explosion_Of_Colour

Re: IsImageSimilar use..

Post by Explosion_Of_Colour »

Thanks very much for the replies. I think I'll try out this function as it will take a while to work out how to use is via ImageMagickNet anyways - I'll figure it out and report back.

Thanks again,
Becky
Explosion_Of_Colour

Re: IsImageSimilar use..

Post by Explosion_Of_Colour »

I have a large grid on my image and each square is a littlle symbol so I want to compare a symbol I find to the rest of the image to find more of the same symbols - would iterating through each square in the grid and comparing the images give me a good idea about the similarity ( the grid image is scanned in so the symbols will never be an exact match).

Sorry if that's a daft question - still trying to get my head around image/graphics programming.

Thanks,
Becky
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IsImageSimilar use..

Post by fmw42 »

I have a large grid on my image and each square is a littlle symbol so I want to compare a symbol I find to the rest of the image to find more of the same symbols - would iterating through each square in the grid and comparing the images give me a good idea about the similarity ( the grid image is scanned in so the symbols will never be an exact match).
compare -metric rmse largeimage smallimage resultimages

should produce two images. The second output should be the similarity image where the brighter it is, the closer the match.

see http://www.imagemagick.org/script/compare.php

Image

Image


compare -metric rmse mandril3.png mandril3_156_22.jpg mandril3_similarity.png
240.165 (0.00366469) @ 156,22

mandril3_similarity_1.png
Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: IsImageSimilar use..

Post by anthony »

Together Fred and I have looked at various methods of finding the peaks of similarity.

Typically using filters to compare each pixel with an average of the surrounding pixels, then thesholding and outputing the results as a TXT: file to get all the multiple matching coordinates.
http://www.imagemagick.org/Usage/files/#txt


UPDATE: Look at the (raw) notes in the section on Sub Image searching
http://www.imagemagick.org/Usage/compare/#sub-image
This currently outlines a number of search techniques, and finding 'peaks' in the search results.
Also look at Correlations...
http://www.imagemagick.org/Usage/convolve/#correlate


WARNING: As of IM version 6.6.3-7 you must use a -subimage-search option if you want to use the sub-image searching facility of "compare". This was done to remove confusing error messages in normal same sized image comparisons which are much more common. -- Anthony
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: IsImageSimilar use..

Post by fmw42 »

HugoRune used a variation on that approach to find his peaks in the hough transform at viewtopic.php?f=1&t=14491 where he did the following:

"By the way, my current method for finding the local maxima in hough space:
dilate the hough space image ~3 times, then compare the dilated image with the original and set all pixels with differing values to zero. The remaining pixels are local maxima
Works very well."

I have not tried that yet on the similarity images but it seems like an interesting approach.
Post Reply