subimage with different size

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
betty1978
Posts: 5
Joined: 2011-11-16T04:43:45-07:00
Authentication code: 8675308

subimage with different size

Post by betty1978 »

hello,
i have a problem and i can't find a solution. I created a marker, and i want to search this marker on a Pictue. I think the Problem is the different size from the marker in my image or i need another marker for ImageMagick.

This is the created marker:
Image

And this is my Picture:
Image

I convert the image with follow Command:

Code: Select all

convert original1.png -colorspace Gray -negate -edge 1 -negate original.png
The result is this image:
Image

Now i search the marker with this Command:

Code: Select all

compare -metric rmse -subimage-search original.png maske.png result.png
17735.4 (0.270625) @ 234,198

Image

This position is wrong, and i make a new Image with this Command

Code: Select all

convert original1.png -fuzz 20% -fill black -opaque "#3b3b38" -fuzz 20% -fill white -opaque "#989692" test.png
The result is:
Image

Code: Select all

compare -metric rmse -subimage-search test.png maske.png result1.png
17861.8 (0.272554) @ 230,87

Image

The same Problem, now is the position on top from my marker.
Has anyone any idea what can i do?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: subimage with different size

Post by snibgo »

betty1978 wrote:I think the Problem is the different size from the marker in my image ...
Yes, that is the main problem. IM won't automatically resize images to search for a match. If you place one image over the other, you can see that if one corner mark lines up, the others won't.

One trick is to look for small distinctive features. The diagonal cross is distinctive. So crop to that, and then search:

Code: Select all

convert maske.png -gravity center -crop 50%%x50%%+0+0 m.png

compare -metric rmse -subimage-search original.png m.png result.png
The result is then correct.
snibgo's IM pages: im.snibgo.com
Post Reply