Page 1 of 1

convert -resize BUG?

Posted: 2009-10-30T04:32:52-07:00
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.

Re: convert -resize BUG?

Posted: 2009-10-30T09:51:29-07:00
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

Re: convert -resize BUG?

Posted: 2009-10-30T10:10:14-07:00
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

Re: convert -resize BUG?

Posted: 2009-10-30T10:19:03-07:00
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

Re: convert -resize BUG?

Posted: 2009-10-31T01:26:55-07:00
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

Re: convert -resize BUG?

Posted: 2009-11-01T19:22:01-07:00
by anthony
You should always read images BEFORE processing them. Otherwise it may not work in the next major release of IM (v7).

Re: convert -resize BUG?

Posted: 2009-11-02T04:00:14-07:00
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

Re: convert -resize BUG?

Posted: 2009-11-02T13:32:15-07:00
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

Re: convert -resize BUG?

Posted: 2009-11-02T16:43:34-07:00
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.

Re: convert -resize BUG?

Posted: 2009-11-03T02:20:38-07:00
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.

Re: convert -resize BUG?

Posted: 2009-11-03T11:16:18-07:00
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?

Re: convert -resize BUG?

Posted: 2011-02-28T07:14:22-07:00
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

Re: convert -resize BUG?

Posted: 2011-03-01T00:10:52-07:00
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.

Re: convert -resize BUG?

Posted: 2011-03-01T05:42:33-07:00
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

Re: convert -resize BUG?

Posted: 2011-03-01T16:52:31-07:00
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).