Paste image on coordinates outputted previously [SOLVED]

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

Paste image on coordinates outputted previously [SOLVED]

Post by Rye »

Well in a previous thread of mine it was possible to get ImageMagic to output these coordinates (viewtopic.php?f=1&t=22925).

Code: Select all

0 (0) @ 39,37
The question now however is:

How do I have to proceed from here in order to paste a new image (say new_image.png for example) onto that coordinate ?
Last edited by Rye on 2013-03-09T11:36:00-07:00, edited 1 time in total.
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: Paste image on coordinates outputted previously

Post by snibgo »

Code: Select all

set SRC="22 HP+200.png"
set REP="newImage.png"

"%IMG%convert" ^
  %SRC% ^
  ( %REP% -geometry +39+37 ) ^
  -composite ^
  x.png
snibgo's IM pages: im.snibgo.com
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Paste image on coordinates outputted previously

Post by Rye »

Is there a way to automatically reuse the previous coordinate output instead of having to type it manually each time?
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: Paste image on coordinates outputted previously

Post by snibgo »

Yes. For example, redirect the compare output stderr to a file ...

Code: Select all

"%IMG%compare" -metric RMSE %SRC% %SUB% -dissimilarity-threshold 1 -subimage-search found.png 2>y.txt
... then read that file with "for".
snibgo's IM pages: im.snibgo.com
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Paste image on coordinates outputted previously

Post by Rye »

Alright...

That is good so far, except for one thing I don't understand... (refering to the other topic):

I have this image:
Image

and replaced all Image with those: Image


(3 were replaced).

Now however, Imagmagick just finds one that doesn't actually fit my search:

Code: Select all

2010.26 (0.0306746) @ 59,19
Image Image

Is there a way to make the search more "pixel perfect" ?

It seems weird that it finds stuff that isn't even matching 100%...
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: Paste image on coordinates outputted previously

Post by snibgo »

As I said in the other topic:
snibgo wrote: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: Paste image on coordinates outputted previously

Post by Rye »

Ok you are right.

Last question:

Is it possible to get ImageMagick to output this

Code: Select all

59,19
instead of this:

Code: Select all

2010.26 (0.0306746) @ 59,19
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: Paste image on coordinates outputted previously

Post by snibgo »

Not as far as I know.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Paste image on coordinates outputted previously

Post by fmw42 »

You can pipe the output to sed (unix) and filter it to show only the part you want. I do not know the equivalent for Windows.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Paste image on coordinates outputted previously

Post by fmw42 »

For reference, though not useful in Windows without Cygwin, see my bash shell script, maxima, at the link below.

You would only need one pass of compare, then get the coordinates from maxima, then use -flatten to composite your template at each coordinate in one command (or use multiple -compose over commands for each location).
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Paste image on coordinates outputted previously

Post by snibgo »

sed is available on Windows, eg in the Cygwin package.

For something this simple, the "for" command works fine.
snibgo's IM pages: im.snibgo.com
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Paste image on coordinates outputted previously [SOLVED]

Post by Rye »

Thats funny...

Source image:
Image

pattern to replace: Image

replacing pattern(new one): Image

RESULT:

Image

^ What is this ?
Last edited by Rye on 2013-03-09T12:59:49-07:00, edited 3 times in total.
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: Paste image on coordinates outputted previously [SOLVED]

Post by snibgo »

It works fine for me: compare finds the best location. The RMSE isn't zero, because the "pattern to replace" doesn't occur in the source.
snibgo's IM pages: im.snibgo.com
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

Re: Paste image on coordinates outputted previously [SOLVED]

Post by Rye »

Try it yourself with these two and see for yourself (I had posted the wrong ones):
(try it as often as possible... lets say 8 times)

Image Image
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: Paste image on coordinates outputted previously [SOLVED]

Post by snibgo »

What are you saying? What do you think it should do after, say, 8 times?
snibgo's IM pages: im.snibgo.com
Post Reply