Premultiplied Alpha Targas in batch process

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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

Try
  • convert input.tga +matte -resize 50% output.tga
to remove the alpha channel.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

It seems your alpha channel is inverted. Try displaying the image with Gimp it produces the same results as ImageMagick. You could try -channel A -negate to correct the problem.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

We're using ImageMagick 6.3.0 and this command seems to produce what you're looking for:
  • convert \( Asimov.tga +matte -resize 50% \) \( Asimov.tga -fx a -resize 50% \) -compose CopyOpacity -composite image.tga
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

ImageMagick resizing uses unassociated alpha when the matte channel is active. In your case your alpha channel is not really alpha values so we inactivate the alpha channel with the +matte option and deal with the alpha channel separately.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

An alturnative that may be easier is to use the new multi-image -separate option. This will separate an image into a list of gray scale images on per channel. This makes it useful to disconnect any color-alpha relationship that may be involved. Remember more options with IM are applied to ALL images in a image sequence.

Code: Select all

  convert Asimov.tga -channel RGBA -separate -resize 50% -combine image.tga
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Hmmm after trying this myself I found that using -separate on your image produces four images, but each still contained the alpha channel!!!!! I think that may have been an unexpected feature, and in this case unwanted.

Adding a +matte after the -separate fixed the problem.

Code: Select all

  convert Asimov.tga -channel RGBA -separate +matte -resize 50% -combine image.tga
I'll update the IM Examples page about -separate to make note of this.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Should be much faster on larger images. -fx has to interpriate the mathematical argument it is given once for every pixel and color channel involved. -separate just does the job directly.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply