Page 1 of 1
detect transparency get X&Y
Posted: 2011-07-23T10:43:10-07:00
by lberezinski
hello,
i'm looking for a way to mimc Photoshoop magicwand selection and get the X&Y height and width of the magicwand selection. is this possible with ImageMagick?
thanks in advance
Re: detect transparency get X&Y
Posted: 2011-07-23T11:16:51-07:00
by fmw42
use -floodfill or -draw "matte ... floodfill", binarize, -trim (without +repage) and save as png. Then one can get the page geometry and offset from the verbose info or from string formats.
see
http://www.imagemagick.org/script/comma ... #floodfill
http://www.imagemagick.org/Usage/draw/#matte
http://www.imagemagick.org/Usage/crop/#trim
http://www.imagemagick.org/script/escape.php (see %O and %P)
if on unix, I have a magicwand script that will do everything but trim and get the coordinates. see scripts below.
Re: detect transparency get X&Y
Posted: 2011-07-23T12:29:51-07:00
by lberezinski
Thank you for the detailed answer but unfortunately for me i'm a newbie im working on windows with command line. i would really appreciate if you can point me to an example code from there i think i'll be good to go. (i uploaded a png that im testing with)
thanks in advance.
Re: detect transparency get X&Y
Posted: 2011-07-23T13:28:58-07:00
by fmw42
Your image already has an alpha channel that identifies the two white areas. I assume those are the ones of interest. So I extract the alpha channel, invert it so that the areas of interest are white and the rest black, threshold it to make sure it is binary (full white and black). That gets the first image. Then I flood fill the second area with black so that the only white area is the first one (on the left) and then use -trim to get the minimum bounding area. Then I use identify -verbose to look at the information and have extracted the Page geometry which tells you the offset relative to the original image size and the Geometry which is the trimmed size.
convert front.png -alpha extract -negate -threshold 50% front_alpha.gif
convert front_alpha.png -fill black -draw "color 700,350 floodfill" -alpha off -trim front_alpha1.png
identify -verbose front_alpha1.png
...
Geometry: 336x315+0+0
...
Page geometry: 960x640+65+101
...
all these commands should work in both unix and windows on a relatively current version of IM. If not let me know and I will tell you some older commands to use in stead. Look at each image to see what I am doing.
If you need to do the same for an image that does not have an alpha channel to help, then I can flatten this image and give you a similar but slightly different set of commands.
Re: detect transparency get X&Y
Posted: 2011-07-25T17:04:13-07:00
by anthony
Once you get a mask image of the area wanted (in this case a alpha channel extract and negate) I would use something like fred's "separate" script to
- determine number of 'holes'
- and allow you to loop through each hole to generate a separate mask
- get the 'trim bounds' of those masks.
Fred don't under estimate the power of 'labling' that your "separate" script can do. I really need to get the morphology image labeling method finished, so that this type of thing is a lot faster.
WARNING: the mask may not be binary, but have anti-aliased edges.
Also note that finding the corners of the quadrangular areas, would I think be much more important than the bounds. Fred you have a script for that too!