Page 1 of 1

Alternative to -alpha Shape

Posted: 2009-10-04T19:48:26-07:00
by gbsmith71
Hi,

I had a website running that relied on the -alpha shape operator to do basically the same thing as the crescent moon example:

Code: Select all

convert alpha_extract.png -background Yellow -alpha shape   alpha_shape.png
My hosting company claim that there are security issues with IM v6.4 and have downgraded me to 6.2.8 ( without any notice )

Do I have any alternative to do the same thing in that version?

Thanks in advance,

Gavin

Re: Alternative to -alpha Shape

Posted: 2009-10-04T21:35:31-07:00
by fmw42
try

convert alpha_extract.png -channel rgba -matte -fill yellow -opaque white -transparent black alpha_extract2.png

You may want to threshold the alpha_extract.png first or use -fuzz to control what gets color and what gets transparent as it appears that alpha_extract.png may not be binary (b/w) and may have some gray in it.

For example, this looks a bit better.

convert alpha_extract.png -channel rgba -matte -threshold 50% -fill yellow -opaque white -transparent black alpha_extract3.png

Re: Alternative to -alpha Shape

Posted: 2009-10-04T23:14:35-07:00
by gbsmith71
Thanks for that.

It kind of works, but is not sharp enough for what I need.

Does anyone know what version -alpha shape came in?

Thanks

Gavin

Re: Alternative to -alpha Shape

Posted: 2009-10-05T12:35:16-07:00
by fmw42
best quess from http://www.imagemagick.org/script/changelog.php is 6.4.3.7

if you threshold as in my example, why is it not sharp enough. The alpha shape must be doing something like that when the alpha channel is not binary. Did you try adding -threshold?

Perhaps a better approach would be

convert alpha_extract.png \
\( -clone 0 -threshold -1 -fill yellow -opaque white \) \
+swap -compose copy_opacity -composite alpha_extract5.png

Second line creates yellow image same size as original
third line overlays the original as an alpha mask over the yellow image

This avoids the jaggies (from the thresholding) and leave the alpha channel as non-binary with its antialiased boundary

Re: Alternative to -alpha Shape

Posted: 2009-10-05T22:51:37-07:00
by anthony
Alpha Shape basically takes a greyscale image, copies it to the alpha channel, then sets the color of all non-transparent pixels to background.

That is it does a -compose Copy_Opacity with itself (a -alpha copy) and colorizes it.

Code: Select all

   convert shape_mask_image \( +clone \) \
               -alpha Off  -compose Copy_Opacity   -composite \
               -fill  color     -colorize 100%    alpha_shape.png