Page 2 of 3
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-09T14:04:39-07:00
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).
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-09T14:06:34-07:00
by snibgo
So it should produce a garbled image, and is doing so. Do you have a question?
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-09T14:11:43-07:00
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).
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-09T14:33:17-07:00
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.
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-09T14:52:52-07:00
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)
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-09T15:21:24-07:00
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.
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-09T15:30:02-07:00
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.
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-09T15:48:28-07:00
by snibgo
You need to decide what RMSE number you consider to be close enough. When "compare" returns a larger value, exit the loop.
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-09T16:06:43-07:00
by Rye
is there an introduction to RSME ? I would prefer a 100% match. (if that can be achieved
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-09T16:26:58-07:00
by snibgo
http://en.wikipedia.org/wiki/RMSE
As I have said, zero means exact match.
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-09T19:40:15-07:00
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.
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-10T03:02:29-07:00
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
from this:
I can use either as source (to be replaced) and it will work with both (:weird:)..
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-10T11:18:23-07:00
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.
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-10T11:51:55-07:00
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)
Neither of these images match any pattern but the background in your image. Perhaps you are using the wrong images.
Re: Paste image on coordinates outputted previously [SOLVED]
Posted: 2013-03-10T13:26:45-07:00
by Rye
You are right ! I updated the two 22x22 images.