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

Re: Paste image on coordinates outputted previously [SOLVED]

Post by Rye »

I you use the two 22x22 pics I provided in my post then it should produce a garbled image (like the one above).
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 »

So it should produce a garbled image, and is doing so. Do you have a question?
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 »

yes:

Why doesn't it stop after it found all possible (correct) matches and continues placing new ones on places they don't belong.

I wanted to know if there is a way to avoid this (beside only executing the code the exact number needed).
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 »

My crystal ball is on the blink. I can't see your script, so I don't know why it doesn't stop.
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 »

Code: Select all

@echo off
DEL found-0.png
DEL found-1.png
DEL co.txt 
SET /P SOURCE=Drag and drop the image to be altered (SOURCE):
SET /P toreplace=Drag and drop the image that will be replaced:
SET /P replacingpattern=Drag and drop the image that will pasted (new):
SET toreplace="02blnkCMD.gif"
set SRC="%SOURCE%"
set SUB="%toreplace%"
set REP="%replacingpattern%"

:start

"%IMG%compare" -metric RMSE %SRC% %SUB% -subimage-search found.png 2>co.txt
set /p xycos= <co.txt
set str=%xycos%
echo.%str%
set str=%str:,=+%
ECHO %str% > co.TXT
set /p xycos= <co.txt
set str=%xycos%
echo."%str%"
set str=%str: =%
ECHO %str% > co.TXT
set /p xycos= <co.txt
set str=%xycos%
echo.%str%
set str=%str:@=      +%
ECHO %str% > co.TXT
set /p xycos= <co.txt
set str=%xycos%
echo.%str%
set str=%str:~-8%
ECHO %str% > co.TXT
set /p xcoyco= <co.txt
"%IMG%convert" ^
  %SRC% ^
  ( %REP% -geometry %xcoyco% ) ^
  -composite ^
  %SOURCE%
DEL found-0.png
DEL found-1.png

set /p choice= Repeat script ? (1=Yes  2=No)
   if %choice%==1 goto start
   if %choice%==2 goto exit

:exit
just enter a 1 after each run and it will continue endlessly. (Though it should be sufficent if you just let it run around 8 times)
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 »

I can't figure out all those "set" and "echo" statements. You could parse co.txt in a single "for" statement, without intermediate files. But they put the correct offsets into xcoyco.

As far as I can see, for as long as the user presses "1", the script will loop. You seem to be ignoring the output from compare that gives the RMSE metric, which gives zero for exact matches; larger number otherwise.
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 »

Code: Select all

"%IMG%compare" -metric RMSE %SRC% %SUB% -subimage-search found.png 2>co.txt

"%IMG%convert" ^
  %SRC% ^
  ( %REP% -geometry %xcoyco% ) ^
  -composite ^
  %SOURCE%
This should be important for you.

It contains what you think "stops the script once no matches are found. The problem I see however is:
It won't stop because it still "finds" matches... That the matches that are found suck is another story.
What kind of script would you suggest to stop after it found any "right" matches ?

BTW: those set and echos are possible with for aswell, but I kinda don't want to use it anymore as it spits only weird error messages.
This gets the job done aswell. Its only for automatically entering the coordinates anyways.
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 »

You need to decide what RMSE number you consider to be close enough. When "compare" returns a larger value, exit the loop.
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 »

is there an introduction to RSME ? I would prefer a 100% match. (if that can be achieved
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 »

http://en.wikipedia.org/wiki/RMSE

As I have said, zero means exact match.
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 [SOLVED]

Post by fmw42 »

Other metrics are available. See http://www.imagemagick.org/Usage/compare/#statistics

RMSE for a single pixel in two images is sqrt((diffR^2+diffG^2+diffB^2)/3)

Get the color channel differences or error between two images at a given pixel (E). Then sum or add them up (S). Then divide by 3 to get the mean or average (M). Then take the square root (R). Now reverse the letters from ESMR to get RMSE.

A perfect match would be when each difference is zero, so that the RMSE value is zero.
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 »

Code: Select all

"%IMG%compare" -metric RMSE ((diffR^2+diffG^2+diffB^2)/3) %SRC% %SUB% -subimage-search found.png
Perfect :)

However even if I use this one it seems the program still has its difficulty distinguishing this Image from this: Image

I can use either as source (to be replaced) and it will work with both (:weird:)..
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
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 [SOLVED]

Post by fmw42 »

Sorry you misunderstand
-metric RMSE ((diffR^2+diffG^2+diffB^2)/3)
The named RMSE metric uses that formula. You do not include the formula in the command. RMSE means that it uses that formula already (though you forgot the sqrt). So remove the part in RED

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

You have to decide what value is a good threshold for the error value returned. Then substitute or do not substitute your new image based upon your threshold for the error value, i.e. how close a match is appropriate.
Last edited by fmw42 on 2013-03-10T11:53:38-07:00, edited 1 time in total.
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 [SOLVED]

Post by fmw42 »

Rye wrote: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
Neither of these images match any pattern but the background in your image. Perhaps you are using the wrong images.
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 »

You are right ! I updated the two 22x22 images.
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Post Reply