Page 1 of 1

Retrieve the coordinates corresponding to a certain color

Posted: 2011-11-04T05:05:13-07:00
by badabou
Hello,

Is it possible to retrieve the coordinates x,y (and width,height) of a shape in an image with imagemagick ?

Let me explain :

There is a function in flash which recovers an area corresponding to a certain color (getColorBoundsRect) :

Image

With this picture, the function will return the coordinates of the area filled with the red circle.

I would do the same with imagemagick but I do not know if this is possible.

Thank you

Re: Retrieve the coordinates corresponding to a certain colo

Posted: 2011-11-04T10:40:13-07:00
by fmw42
Use -trim without a following +repage, then get the geometry size and offset


convert 92246458.png +repage -fuzz 10% -trim 92246458_trim.png
size=`convert 92246458_trim.png -format "%P" info:`
offsets=`convert 92246458_trim.png -format "%O" info:`
echo "size=$size"
echo "offsets=$offsets"

choose an appropriate fuzz value to separate the background from the circle (presumably without the white square).

see
http://www.imagemagick.org/script/escape.php
http://www.imagemagick.org/Usage/crop/#trim

The above is for unix variables. For windows, see http://www.imagemagick.org/Usage/windows/

Re: Retrieve the coordinates corresponding to a certain colo

Posted: 2011-11-04T23:26:09-07:00
by anthony
Or are you trying to get the locations of all red pixels? Just the bounding box indicated in white? Or just the 'best guess' at the center and diameter of a circle? Perhaps you just one a single coordinate anywhere within the circle? Or maybe the mask of the circle?

There are lots of possibilities as to your meaning of 'coordinates of the shape'.