Rectangular shapes coordinates detection

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?".
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Rectangular shapes coordinates detection

Post by snibgo »

(I've removed your duplicate post.)

Perhaps I don't understand your question.

"compare" returns the coordinates of the position of the top-left corner of the subimage within the larger image.

If you want the coordinates of the bottom-right, you need to do the arithmetic yourself.
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: Rectangular shapes coordinates detection

Post by fmw42 »

As user snibgo said, you need to compute the other coordinates yourself. You can do that by scripting in a terminal or your code. In Unix, i would first find the width and height of the subimage and put them in variables. Then I would do the compare search and put the coordinates of the top left corner in a variable. Then I would compute the other 3 coordinates and put them in variables and finally return all the variables.

Code: Select all

ww=`convert -ping wizard.jpg -format "%w" info:`
hh=`convert -ping wizard.jpg -format "%h" info:`
coords=`compare -metric RMSE -subimage-search logo.png wizard.jpg null: 2>&1 |\
tr -cs ",0-9" " " | cut -d\  -f3`
x0=`echo "$coords" | cut -d, -f1`
y0=`echo "$coords" | cut -d, -f2`
x1=`convert xc: -format "%[fx:$x0+$ww-1]" info:`
y1=0
x2=$x1
y2=`convert xc: -format "%[fx:$y0+$hh-1]" info:`
x3=0
y3=$y2
echo "ww=$ww; hh=$hh; x0=$x0; y0=$y0; x1=$x1; y1=$y1; x2=$x2; y2=$y2; x3=$x3; y3=$y3;"
ww=169; hh=160; x0=0; y0=0; x1=168; y1=0; x2=168; y2=159; x3=0; y3=159;

Sorry I do not know Windows bat scripting, so one of the Windows scripters would have to provide the equivalent code. Or see http://www.imagemagick.org/Usage/windows/
Post Reply