Find an image location within an image using an approximate key

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
knox
Posts: 2
Joined: 2015-08-18T17:07:42-07:00
Authentication code: 1151

Find an image location within an image using an approximate key

Post by knox »

Hi,

I'm not sure how to go about this (or if it's even possible), but here's my goal:

Image A is the key that I will use to look for Image C
Image B is a fairly large image that has Image C somewhere in it
Image C is the image within Image B, but is slightly different from Image A

I want to find Image C's location within Image B, if it is there at all.

I looked at PHASH, but it warns that it is expensive, and I'm not sure how to set it up so that it looks within Image B. Can anyone offer advice?

Thanks in advance.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Find an image location within an image using an approximate key

Post by snibgo »

I suppose you know about "-subimage-search", which searches for one image (C) within another (B).

I don't know what you mean by "Image A is the key that I will use to look for Image C". Perhaps you can show examples.
snibgo's IM pages: im.snibgo.com
knox
Posts: 2
Joined: 2015-08-18T17:07:42-07:00
Authentication code: 1151

Re: Find an image location within an image using an approximate key

Post by knox »

It's a little difficult to show, but Image A is the sample image I want to look for within Image B. It's the same as Image C except a few pixels that are a slightly different shade. I have it so that ImageMagick knows what to look for when looking for Image C.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Find an image location within an image using an approximate key

Post by fmw42 »

See the compare function, as user snibgo said. See

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

and in the example below, you now need to add -subimage-search to the command line.

viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Find an image location within an image using an approximate key

Post by fmw42 »

Note that compare only works if there is an offset (shift) when looking for the match. It does not work if there is relative scale or rotation between the two images.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Find an image location within an image using an approximate key

Post by snibgo »

knox wrote:It's a little difficult to show, but Image A is the sample image I want to look for within Image B. It's the same as Image C except a few pixels that are a slightly different shade. I have it so that ImageMagick knows what to look for when looking for Image C.
Sorry, I don't understand.

IM can search for C within B. Or it can search for A within B. Would the two searches give different results? If A should give an exact match but C would give only an approximate match, then you should search for A, not C, within B.

Please put up sample images.
snibgo's IM pages: im.snibgo.com
Post Reply