Alternative to -alpha Shape

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?".
Post Reply
gbsmith71

Alternative to -alpha Shape

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alternative to -alpha Shape

Post 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
gbsmith71

Re: Alternative to -alpha Shape

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alternative to -alpha Shape

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Alternative to -alpha Shape

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply