possible bug or docs unclear re: -alpha on/set in IM 6.4.3-6

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

possible bug or docs unclear re: -alpha on/set in IM 6.4.3-6

Post by fmw42 »

IM 6.4.3-6 Q16 Mac OSX Tiger

The -alpha documentation says:
Set copies the gray-scale intensity of the image into the alpha channel, converting a gray-scale mask, into a transparent shaped image ready to be colored appropriately.

The -matte operation is equivelent to doing a "-alpha on", followed by a "-alpha reset" if the image did not have a matte/alpha channel before hand. The +matte operation is however exactly the same as a "-alpha off", the alpha channel is left in place, just disabled.
However, I see no difference in the following images nor their identify -verbose (information). They are all alpha enabled but all opaque.

convert -size 100x100 gradient: -matte grad_matte.png
identify -verbose grad_matte.png
Channel depth:
gray: 16-bit
alpha: 1-bit
Channel statistics:
gray:
min: 0 (0)
max: 65535 (1)
mean: 32767.5 (0.5)
standard deviation: 19108.4 (0.291576)
alpha:
min: 65535 (1)
max: 65535 (1)
mean: 65535 (1)
standard deviation: -0 (-0)


convert -size 100x100 gradient: -alpha on grad_alpha_on.png
identify -verbose grad_alpha_on.png
Channel depth:
gray: 16-bit
alpha: 1-bit
Channel statistics:
gray:
min: 0 (0)
max: 65535 (1)
mean: 32767.5 (0.5)
standard deviation: 19108.4 (0.291576)
alpha:
min: 65535 (1)
max: 65535 (1)
mean: 65535 (1)
standard deviation: -0 (-0)

convert -size 100x100 gradient: -alpha on -alpha reset grad_alpha_on_reset.png
identify -verbose grad_alpha_on_reset.png
Channel statistics:
gray:
min: 0 (0)
max: 65535 (1)
mean: 32767.5 (0.5)
standard deviation: 19108.4 (0.291576)
alpha:
min: 65535 (1)
max: 65535 (1)
mean: 65535 (1)
standard deviation: -0 (-0)


convert -size 100x100 gradient: -alpha set grad_alpha_set.png
identify -verbose grad_alpha_set.png

Depth: 16-bit
Channel depth:
gray: 16-bit
alpha: 1-bit
Channel statistics:
gray:
min: 0 (0)
max: 65535 (1)
mean: 32767.5 (0.5)
standard deviation: 19108.4 (0.291576)
alpha:
min: 65535 (1)
max: 65535 (1)
mean: 65535 (1)
standard deviation: -0 (-0)


The above documentation seems to indicate that:
-alpha set will take the gray-scale intensity and put it into the alpha channel. Thus I would expect to find a gradient alpha channel when used with my gradient example. This does not seem to happen . All I get is a fully opaque alpha channel.

The above also seems to indicate that -alpha on is different from -matte in that one needs to also apply -alpha reset. Thus one might construe this to mean that -alpha on enables the alpha channel as transparent. But this is not the case. When using simply -apha on, one gets an opaque alpha channel just like -matte.

So is there some bug or is the documentation either in error or not clear?

Also from Anthony's page at http://www.imagemagick.org/Usage/basics/#alpha
it says:
Set, Reset
make alpha channel fully-opaque, or fully-transparent resp.
Although this is backwards (Anthony needs to reverse the usage of set and reset in the above), I assume it really implies that -alpha set will make the alpha channel fully transparent and -alpha reset will make it fully opaque.

So I am confused about 1) what -alpha set is suppose to do and 2) why -alpha reset is needed after -alpha on?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug or docs unclear re: -alpha on/set in IM 6.4.3-6

Post by magick »

We have applied a patch to -alpha set so that the alpha channel is properly set to the grayscale value of each pixel. Reviewing the code we get this behavior:

Code: Select all

  -matte            if the alpha channel is deactivated, set the alpha channel to opaque and activate

  +matte            deactivate the alpha channel

  -alpha on         activate the alpha channel

  -alpha off        deactivate the alpha channel

  -alpha reset      if the alpha channel is deactivated, set the alpha channel to opaque and activate

  -alpha set        set the alpha channel to the grayscale value of each pixel and activate
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug or docs unclear re: -alpha on/set in IM 6.4.3-6

Post by fmw42 »

Thanks for the reply. That clears up -alpha set. But I am still puzzled about -alpha on vs -alpha reset.

Can someone clarify how -alpha on is different from -alpha reset. I get the same results from both from my examples posted above. If my examples are correct, but do not distinguish adequately, then can you suggest some example where they will give different results.

The previous post just said that -alpha reset is the equivalent to -matte and -alpha off is equivalent to +matte.

But the options doc says -alpha on followed by -alpha reset is the equivalent of -matte, but this seems redundant to me.

What am I missing and why is -alpha on not the same as -matte? When you do -alpha on and it activates the alpha channel, does it not need to assign the alpha channel a value? It seems that it is making it 1 (for opaque) and this then would be no different from -alpha reset. I would have expected -alpha on (in order to be different from alpha reset) to assign a value of 0 to make it fully transparent; otherwise -alpha on is redundant with -alpha reset.

Again, what am I misunderstanding about -alpha on vs -alpha reset

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

Re: possible bug or docs unclear re: -alpha on/set in IM 6.4.3-6

Post by anthony »

I have returned my view to Cristy.

However the docs were never clear, which was my I have never expanded my usage of -alpha in IM examples.

Especially some special usage methods.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug or docs unclear re: -alpha on/set in IM 6.4.3-6

Post by fmw42 »

Do I assume therefore that this is still an open issue about what -alpha on and -alpha reset should do?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: possible bug or docs unclear re: -alpha on/set in IM 6.4.3-6

Post by anthony »

My suggestion was to implement

-alpha opaque
turn on alpha and force to be opaque (equivalent to +matte -matte)

-alpha transparent
turn on alpha and force to be transparent

-alpha copy
turn on alpha and set to grayscale of the image
(converts a gray-scale mask into a shape-mask)

-alpha extract
extract the alpha as a grayscale mask (alpha turned off)
The reverse of 'copy'. Makes a gray-scale mask from a shape mask.

-alpha set
would be the same as -matte. Turns alpha on, but forces opaque if it was not 'on'

-alpha reset
legacy removal (make same as set but hidden).

hmmm.... See even I am confused! and why I continued to use +/-matte
instead.

NOTE: Activate (default) and Deactivate are still not being handled by most operators (-blur, -resize, -scale, -distort, -rotate, the interpolate call, etc etc etc)
Anywhere two pixel colors could be merged, and needs to ensure transparent colors are NOT used as a component in the result (typically producing a balck 'halo' or edge effect.

PS: That was the problem with Arc Distortion when I first implemented distortions! You need to use transparency as part of the weighted average of the pixels being merged together!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug or docs unclear re: -alpha on/set in IM 6.4.3-6

Post by fmw42 »

anthony wrote:My suggestion was to implement

-alpha opaque
turn on alpha and force to be opaque (equivalent to +matte -matte)

-alpha transparent
turn on alpha and force to be transparent

-alpha copy
turn on alpha and set to grayscale of the image
(converts a gray-scale mask into a shape-mask)

-alpha extract
extract the alpha as a grayscale mask (alpha turned off)
The reverse of 'copy'. Makes a gray-scale mask from a shape mask.

-alpha set
would be the same as -matte. Turns alpha on, but forces opaque if it was not 'on'

-alpha reset
legacy removal (make same as set but hidden).

hmmm.... See even I am confused! and why I continued to use +/-matte
instead.
Seems like -alpha opaque, transparent, copy and extract are all that are distinct, but -alpha set and reset seems redundant to opaque. What is missing is an alpha off.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: possible bug or docs unclear re: -alpha on/set in IM 6.4.3-6

Post by anthony »

-alpha off and -alpha on are present and do not expect to change.

-alpha reset is special. It only makes the alpha opaque if alpha was turned off!
Just as -matte does.

HOWEVER -matte is broken at this time, and is acting as -alpha on.
That is it just turns it on, and only make alpha opaque if it did not exist before.

That is +matte -matte should ensure the image has an alpha and it is opaque (like -alpha opaque would). This is a requirement for backward compatibility!!!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug or docs unclear re: -alpha on/set in IM 6.4.3-6

Post by fmw42 »

anthony wrote:-alpha off and -alpha on are present and do not expect to change.

-alpha reset is special. It only makes the alpha opaque if alpha was turned off!
Just as -matte does.

HOWEVER -matte is broken at this time, and is acting as -alpha on.
That is it just turns it on, and only make alpha opaque if it did not exist before.

That is +matte -matte should ensure the image has an alpha and it is opaque (like -alpha opaque would). This is a requirement for backward compatibility!!!
But -alpha on seems to be the same as -alpha opaque (one is redundant with the other)

How should -matte be different from -alpha on if it was working? That is what is confusing me.

Also why do you need to +matte before -matte. Just -matte turns on alpha opaque if it does not exist. Do you need +matte to turn an existing (potentially not opaque) alpha off before turning it back on and setting it to opaque. Perhaps this is what I am missing in understanding in how some of these different options are different; namely what happens if there is already an alpha and it is not totally opaque. But this does not explain the difference between -alpha on and -alpha opaque. Seems they both do the same thing.

Seems like +matte -matte is the same as -alpha off -alpha on, which seems to me to be the same as -alpha off -alpha opaque.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: possible bug or docs unclear re: -alpha on/set in IM 6.4.3-6

Post by anthony »

fmw42 wrote:But -alpha on seems to be the same as -alpha opaque (one is redundant with the other)
-alpha on will turn alpha on. It will create a opaque alpha only if the image did not have one always present.

-alpha off -alpha on
will take an image that has transparency, make it temporarilly opaque (no alpha), then re-enable that same transparency channel without changes, restoring the transparency it had.

-alpha off -matte
however will always (or should always) reset the alpha channel, as it was turned off. It doesn't not matter that the image always has a 'turned-off' alpha channel with old alpha data, it will make that data opaque, as the alpha channel was turned off when -matte was run.

How should -matte be different from -alpha on if it was working? That is what is confusing me.
-alpha on just urned it on. only creating the alpha channel data if it did not exist.
-matte will set alpha data to opaque BUT only if it had been turned off.

-alpha opaque (when created) will turn on the alpha channel (if off) and ALWAYS set it opaque.

Also why do you need to +matte before -matte.
It ensure alpha was truned off and -matte only clears alpah to opaque if it was turned off!
as such the OLD operator sequence "+matte -matte" would be equivelent to just "-alpha opaque"
which did not always exist (and indeed hasn't been added YET).

Just -matte turns on alpha opaque if it does not exist.
But it is supposed to set it to opaque if it did exist and was turned off -- this is the current BUG
that is "xc:none +matte -matte" currently produces a 'none' pixel, rather than a 'opaque black with alpha enabled'

Seems like +matte -matte is the same as -alpha off -alpha on, which seems to me to be the same as -alpha off -alpha opaque.
It is only like the -alpha opaque. It predates the -alpha addition all the way back into IM v3!

Yes -alpha will obsolete -matte BUT it still should do what it is supposed to do!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply