Replace pattern in image with other one

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
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Replace pattern in image with other one

Post by Rye »

Well, to make it simple,

I want to replace theyellow pattern that have a line over them in this image:
Image => Pattern to replace: Image

with this one:
Image

I'm not quite sure IF this is possible, however as no other tools exist to do this I'm betting my hope on ImageMagick so it will help me (once again).

Thanks in advance for awesome answers.
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replace pattern in image with other one

Post by snibgo »

A compare with subimage-search will find the two locations, expressed as a "match score" image with brightest points (probably pure white in this case). The location of these brightest points are the coordinates to put the replacement image.
snibgo's IM pages: im.snibgo.com
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Replace pattern in image with other one

Post by Rye »

since I don't actually get the usage of those "bright points".

Mind posting an example ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replace pattern in image with other one

Post by snibgo »

Windows script:

Code: Select all

set SRC="22 HP+200.png"
set SUB=test.png
set REP="03 (yellow) +-Part.png"

"%IMG%compare" -metric RMSE %SRC% %SUB% -subimage-search found.png
This outputs:

Code: Select all

0 (0) @ 39,37
It has found a match at coords (39,37). In your script, paste the replacement at that position. Then repeat until the number in brackets is no longer (0).
snibgo's IM pages: im.snibgo.com
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Replace pattern in image with other one

Post by Rye »

what would have to be added to this script so it will automatically repeat a paste till a match is no longer found ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Replace pattern in image with other one

Post by Rye »

How can I modify the script to actually use these coordinates right now and paste the other images in ?
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Post Reply