convert -resize BUG?

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
xmovie

convert -resize BUG?

Post by xmovie »

I have used the -resize option to resize a .tga picture, but got a "bad" output result, is this a bug?

command:

Code: Select all

convert -resize 500x300 a.tga b.tga
http://liyizhuang.cn/a.tga
http://liyizhuang.cn/b.tga

any one who can tell me why or how ? thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert -resize BUG?

Post by fmw42 »

try

convert a.tga -resize ... b.tga

that is the input image comes before the -resize option (although probably won't matter)

see http://www.imagemagick.org/Usage/basics/#cmdline
Last edited by fmw42 on 2009-10-30T10:16:45-07:00, edited 1 time in total.
martinw17
Posts: 39
Joined: 2006-09-07T02:10:27-07:00
Location: Brighton, UK

Re: convert -resize BUG?

Post by martinw17 »

This is happening because your image (a.tga) contains an alpha channel - IM seems to merge this into the channels of the resulting image (not sure what it's doing exactly, or why - anyone?)
You can tell IM to ignore the alpha channel using -alpha option, for example:
convert a.tga -alpha Off -resize 500x500 b.tga
The +matte option (available in older IM versions) has the same effect:
convert a.tga +matte -resize 500x500 b.tga

Regards,
Martin
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert -resize BUG?

Post by fmw42 »

I have no trouble with

convert a.tga -resize 500x300 b.tga

using IM 6.5.7-3 Q16

but since your image has an alpha channel try this.

convert a.tga -channel rgba -alpha on -resize 500x300 b.tga

otherwise you may need an upgrade
Last edited by fmw42 on 2009-11-03T11:15:45-07:00, edited 1 time in total.
xmovie

Re: convert -resize BUG?

Post by xmovie »

I downloaded latest version ImageMagick-6.5.7-Q16,
test result below:

convert -resize 500x300 a.tga b.tga --> NOT OK
convert a.tga b.tga -resize 500x300--> NOT OK
convert -alpha off -resize 500x300 a.tga b.tga -->OK
convert +matte -resize 500x300 a.tga b.tga -->OK

problem soloved, million thanks. :D
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert -resize BUG?

Post by anthony »

You should always read images BEFORE processing them. Otherwise it may not work in the next major release of IM (v7).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
martinw17
Posts: 39
Joined: 2006-09-07T02:10:27-07:00
Location: Brighton, UK

Re: convert -resize BUG?

Post by martinw17 »

Although removing the alpha channel solves xmovie's problem, shouldn't convert be able to resize an image that contains an alpha channel without changing the other 3 channels (it seems to merge in the alpha channel, in most cases making the 'opaque' parts black)? Is this a bug?
I have noticed that the same thing happens using TIFFs that have an alpha channel (and perhaps other formats too).

Regards,
Martin
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert -resize BUG?

Post by fmw42 »

I have no trouble with

convert a.tga -resize 500x300 b.tga

using IM 6.5.7-3 Q16 Mac OSX Tiger and your image.

But you can try enabling the alpha channel explicitly and see if that helps.

convert a.tga -channel rgba -alpha on -resize 500x300 b.tga

Same with Tiff
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert -resize BUG?

Post by anthony »

Resize resizes ALL channels that are enabled in an image (that is the image NOT the -channel setting). It has to deal with all channels as all channels must be the same size in the final image.

Alpha channel is handled is a special way simply because it can make colors transparent. transparent colors have no 'color' and as such should not be part of the merged of colors during the resize. As fully-transparent colors are black, not handling alpha in this way will cause the dreaded 'resize halo bug'

See the old resize halo bug report page at..
http://www.imagemagick.org/Usage/bugs/resize_halo/

That is resize handles alpha channel correctly!!!!

As for what is happening in the TGA images. I am not certian. It looks to me like the alpha channel of the TGA image is NOT an alpha channel, but just a masking channel of some sort. That is it probably should be treated as a separate 'mask' image rather than as a an alpha (transparency) channel.

You can separate the alpha form the image, resize and merge the channels again using..

Code: Select all

   convert a.tga \( +clone -channel A -separate +channel \) -alpha off \
               -resize 500x300 \
               -compose CopyOpacity -composite  b.tga
That treats the alpha as a completely separate grayscale mask image, rather than as transparency.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
martinw17
Posts: 39
Joined: 2006-09-07T02:10:27-07:00
Location: Brighton, UK

Re: convert -resize BUG?

Post by martinw17 »

Thanks Anthony - this is helpful.

> It looks to me like the alpha channel of the TGA image is NOT an alpha channel, but just a masking channel of some sort.

That's probably right - for example, I think Photoshop uses an alpha channel to 'store' selections.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert -resize BUG?

Post by fmw42 »

I have no trouble with

convert a.tga -resize 500x300 b.tga

using IM 6.5.7-3 Q16

Image

What is "bad" with this?
User avatar
bydersjoint
Posts: 6
Joined: 2010-11-16T23:27:28-07:00
Authentication code: 8675308

Re: convert -resize BUG?

Post by bydersjoint »

Hi Everyone,

I am trying to resize a TGA to exactly half of its original resolution using the code:

Code: Select all

convert image_a.tga ( +clone -channel A -separate +channel ) -alpha off -resize 50%% -compose CopyOpacity -composite image_b.tga
However my results constantly invert my alpha channel! Has anyone else experienced this or is there a simple solution to inverting the alpha channel within this same command?!

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

Re: convert -resize BUG?

Post by anthony »

It may be that the TGA has the 'selection' channel saved as a inverted 'clipping mask' rather than as a alpha channel.

Alpha channels are seen as White shapes on a black (meaning zero or transparent) background.

Just add a -negate somewhere in the parenthesis to fix it.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
bydersjoint
Posts: 6
Joined: 2010-11-16T23:27:28-07:00
Authentication code: 8675308

Re: convert -resize BUG?

Post by bydersjoint »

Hi Anthony,

Aaah that's annoying, yesterday I was looking everywhere for a command similar to -negate... clearly was looking in all the wrong places!

Thanks so much, that worked perfectly!!

Chris :D
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert -resize BUG?

Post by anthony »

Top section of IM examples, Color Modification
which is where all general global color modifications are exampled.
http://www.imagemagick.org/Usage/color_mods/

While this does have some mathematical color modifications, DIY mathematical modifications to individual images is at the bottom of "Transformations" (-fx, -evaluate, -function).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply