Page 1 of 1

ImageMagick: How to Search for sub image in a bigger image

Posted: 2012-10-12T12:22:57-07:00
by Crazy_Bash
I have a forum on which users often upload images with watermark of our competitors, I would like to search for the logo on the image and replace or cut it.

I know that ImageMagick has an option called subimage-search, but i had no luck with it

what I've tried so far:

compare -subimage-search logo.png sub.png similarity.png
compare -subimage-search -metric rmse large_image.png sub-image.png result.png
compare -subimage-search -metric pae large_image.png sub-image.png result.png
compare -subimage-search -metric ncc large_image.png sub-image.png result.png

Re: ImageMagick: How to Search for sub image in a bigger ima

Posted: 2012-10-12T13:23:28-07:00
by Bonzo
I have a forum on which users often upload images with watermark of our competitors, I would like to search for the logo on the image and replace or cut it.
I assume your competitors watermark their image for this reason.

If anything you should be removing the image rather than removing the watermark.

Re: ImageMagick: How to Search for sub image in a bigger ima

Posted: 2012-10-12T13:41:36-07:00
by fmw42
What version of IM and platform? -subimage-search was added at version 6.6.3-6

I have used successfully for quite some time now, the following syntax.

compare -metric rmse -subimage-search large_image.png sub-image.png result.png

That should produce two result.png images, -0 and -1. The second one will be the similarity image.

see
http://www.imagemagick.org/script/comma ... age-search
http://www.imagemagick.org/Usage/compare/
http://www.imagemagick.org/script/compare.php
viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076 (though current versions of IM now require the addition of -subimage-search)

Perhaps you should post links to your two images so others can test.

Re: ImageMagick: How to Search for sub image in a bigger ima

Posted: 2012-10-12T16:51:20-07:00
by Crazy_Bash
fmw42 wrote:What version of IM and platform? -subimage-search was added at version 6.6.3-6

I have used successfully for quite some time now, the following syntax.

compare -metric rmse -subimage-search large_image.png sub-image.png result.png

That should produce two result.png images, -0 and -1. The second one will be the similarity image.

see
http://www.imagemagick.org/script/comma ... age-search
http://www.imagemagick.org/Usage/compare/
http://www.imagemagick.org/script/compare.php
viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076 (though current versions of IM now require the addition of -subimage-search)

Perhaps you should post links to your two images so others can test.
Thanks for replay.
I'm using:
Version: ImageMagick 6.7.7-10 2012-08-27 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC

The images:
Image
sub-image to search
Image
image to replace with
Image

results:
Image
Image

I can see the two results images, but i don't know how to move forward and replace Image with Image

Re: ImageMagick: How to Search for sub image in a bigger ima

Posted: 2012-10-12T17:43:12-07:00
by fmw42
There should be some output to the terminal that tells you the rmse error, its values scaled to the range 0 to 1 (in parenthesis) and the x,y coordinates of the best match, all in that order. Use the x,y coordinates to composite the new image at the same x,y location.


convert image newsmallimage -geometry +X+Y -compose over -composite result

see
http://www.imagemagick.org/Usage/layers/#convert

Re: ImageMagick: How to Search for sub image in a bigger ima

Posted: 2012-10-13T02:10:12-07:00
by Crazy_Bash
Worked! Thanks a lot you are the man :)

Re: ImageMagick: How to Search for sub image in a bigger ima

Posted: 2012-10-16T16:51:45-07:00
by anthony
This I don't think can be classed as a watermark. It is probbaly better classed as SPAM advertising, and you just wanted to replace that spam with your own spam. :-)

A true watermark would be very hard to locate and replace, as it is a distortion of the color values rather than a bold and obvious overlay. Direct sub-image searches of real watermarks would be very difficult.

And even in the frequency domain, it would probably be very hard to locate, though probably easier than for direct sub-image searches.