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) :
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
Retrieve the coordinates corresponding to a certain color
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Retrieve the coordinates corresponding to a certain colo
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/
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/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Retrieve the coordinates corresponding to a certain colo
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'.
There are lots of possibilities as to your meaning of 'coordinates of the shape'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/