Creating Alpha from non Alpha image

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
Jenkins

Creating Alpha from non Alpha image

Post by Jenkins »

Howdy all

I registered here because i'm having some rather annoying issues with trying to create an alpha channel from an image without one (WITHOUT touching the colour channel on either images)

The results i'm getting are not what i need, I need

This image
http://i228.photobucket.com/albums/ee24 ... _alpha.jpg

As the ALPHA channel on this image;
http://i228.photobucket.com/albums/ee24 ... normal.png

Forget about the size difference too, the alpha has been scaled down to save bandwidth however the normal map is full size. I just need to Copy the RGB Black and White Mask image into the Alpha Channel of the Normal map... I've tried several combinations of command line options and none of them are what i need, and i DO NOT want the colour channel of the normal map touched at all, when i am able to copy the alpha into the normal map it does not save the alpha channel and deletes any colour information from the input mask alpha...

This is the closest i can get but it Destroys the alpha channel which i dont want to happen;

Code: Select all

composite.exe -compose CopyOpacity alpha.png input.png output.png
Alpha.png = B/W Mask with NO Alpha
Input.png = colour input with NO Alpha
What i need for Output.png = Colour output with Alpha.png as the Alpha Channel of Input.png

Any help is appreciated;

EDIT: I must stress i need the Input.png colour image to stay untouched
This is critical to all images that i want to use this for.

-Jenkins
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Creating Alpha from non Alpha image

Post by el_supremo »

Your command should do exactly what you want. I used the convert program:

Code: Select all

convert input.png -alpha off alpha.jpg -compose copyopacity -composite output.png
and it adds the alpha layer correctly. (For the test, I resized the input.png to be the same size as alpha.jpg)
If you are getting unexpected output, attach an example so we can see what you mean.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating Alpha from non Alpha image

Post by fmw42 »

what IM version and platform are you using? if it is old, you should upgrade. the current version is IM 6.5.2-4
Jenkins

Re: Creating Alpha from non Alpha image

Post by Jenkins »

el_supremo wrote:Your command should do exactly what you want. I used the convert program:

Code: Select all

convert input.png -alpha off alpha.jpg -compose copyopacity -composite output.png
and it adds the alpha layer correctly. (For the test, I resized the input.png to be the same size as alpha.jpg)
If you are getting unexpected output, attach an example so we can see what you mean.

Pete
Thanks!!!!
fmw42 wrote:what IM version and platform are you using? if it is old, you should upgrade. the current version is IM 6.5.2-4
6.5.1-Q16 :/

Looks like an update is needed then! :D

Thanks again.
-Jenkins
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Creating Alpha from non Alpha image

Post by anthony »

As both images as an alpha channel, you are better of using a Duff-Poster alpha composition function..

For example DstIn to get what parts of the destination are 'In' the shape of the source image. If any parts of the destination image are transparent they will remain transparent! Which is a good thing.

See IM examples, Compose
http://www.imagemagick.org/Usage/compose/#dstin

the CopyOpacity is really only used with greyscale masks and images that have no transparency at all.

See CopyOpacity
http://www.imagemagick.org/Usage/compose/#copyopacity

If you use CopyOpacity, on images with alpha channels, the alpha channel is just copied from one image to the other, which means parts of the destination image that was transparent, may become opaque (or visible!). This is not good, as a transparent area has a undefined color (usually it is just black).

For an example of this see..
Editing a Image Mask
http://www.imagemagick.org/Usage/channels/#erase
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply