Page 1 of 1

Transparency — Straight vs. premultiplied alpha

Posted: Tue Apr 02, 2013 7:45 pm
by XnTriq
  • <!--// Moderator's note: This topic was split off from “Transparency”. //-->
Wikipedia ([url=http://en.wikipedia.org/wiki/Alpha_compositing#Description]Alpha compositing[/url]) wrote:If an alpha channel is used in an image, it is common to also multiply the color by the alpha value, to save on additional multiplications during compositing. This is usually referred to as premultiplied alpha.
Wikipedia ([url=http://en.wikipedia.org/wiki/Portable_Network_Graphics#Transparency_of_image]Portable Network Graphics[/url]) wrote:Alpha storage can be "associated" ("premultiplied") or "unassociated", but PNG standardized on "unassociated" ("non-premultiplied") alpha so that images with separate transparency masks can be stored losslessly.
W3C (PNG Specification v1.0 » [url=http://www.w3.org/TR/PNG-Rationale.html#R.Non-premultiplied-alpha]Non-premultiplied alpha[/url]) wrote:PNG uses "unassociated" or "non-premultiplied" alpha so that images with separate transparency masks can be stored losslessly. Another common technique, "premultiplied alpha", stores pixel values premultiplied by the alpha fraction; in effect, the image is already composited against a black background. Any image data hidden by the transparency mask is irretrievably lost by that method, since multiplying by a zero alpha value always produces zero.

Some image rendering techniques generate images with premultiplied alpha (the alpha value actually represents how much of the pixel is covered by the image). This representation can be converted to PNG by dividing the sample values by alpha, except where alpha is zero. The result will look good if displayed by a viewer that handles alpha properly, but will not look very good if the viewer ignores the alpha channel.

Although each form of alpha storage has its advantages, we did not want to require all PNG viewers to handle both forms. We standardized on non-premultiplied alpha as being the lossless and more general case.
mtPaint Handbook (Channels » [url=http://mtpaint.sourceforge.net/handbook/en_GB/chap_07.html#SEC12]Unassociate Alpha[/url]) wrote:RGB images with alpha transparency can be stored in two different ways. One way is to store raw RGB values and alpha values as separate and independent channels; this is called "unassociated alpha". Another way is to store RGB values not raw, but premultiplied by corresponding alpha value, which is then called "associated alpha". mtPaint, like most other image processing programs, stores images with unassociated alpha, to be able to manipulate RGB and alpha independently of one another, and not lose RGB data when zeroing out alpha. On the other hand, rendering software prefers associated alpha, because with RGB values already multiplied by alpha, less work remains to be done in real time when doing alpha blending. Some image formats, such as TIFF and TGA, support both types of alpha, but are frequently mislabelled; other formats such as PNG <!--//  ?¿?  //--> or BMP support just one type of alpha, and usually don't define which - in practice it means that it can be both types equally likely. mtPaint automatically converts images with definitely recognized associated alpha to unassociated - but type of alpha cannot be autodetected reliably, and when autodetection fails, "Unassociate Alpha" allows one to convert a misdetected image with associated alpha to unassociated.
There is/was a set of Photoshop-compatible plugins to “de-multiply” (d-multip.8bf) and “de-transparent” (d-xparen.8bf) images with alpha transparency.
XnTriq ([url=http://newsgroup.xnview.com/viewtopic.php?t=13031&p=50837#p50837]Free Adobe Photoshop Plug-Ins[/url]) wrote:
  • Solidify A / Solidify B / Solidify C Image
    Solidify turns an image layer entirely 100% opaque. It reveals partially transparent areas, and can even help repair the corrupted transparency channel that some paint programs occasionally produce. It's also good for quickly filling in missing regions of a panorama.
    Solidify A softly blurs the solid part into the transparent region. Solidify B smears only the outer edge for a harder look. Solidify C gives the smoothest, most uniform result.

Re: Transparency

Posted: Thu Apr 04, 2013 4:20 am
by DOS386
mtPaint Handbook wrote:other formats such as PNG or BMP support just one type of alpha, and usually don't define which - in practice it means that it can be both types equally likely
NO. PNG has only unpremultiplied alpha (see same post other sources).

Re: Transparency

Posted: Thu Apr 04, 2013 6:30 pm
by XnTriq
DOS386 wrote:
mtPaint Handbook wrote:other formats such as PNG or BMP support just one type of alpha, and usually don't define which - in practice it means that it can be both types equally likely
NO. PNG has only unpremultiplied alpha (see same post other sources).
:shock: :D Someone goes to the trouble of actually reading the stuff I post?!
PNG — The Definitive Guide ([url=http://www.libpng.org/pub/png/book/glossary.html]Glossary[/url] » alpha channel) wrote:A special channel that associates transparency (or opacity) with an image. An image without an alpha channel is considered to be completely opaque; an image with an alpha channel may be opaque in some areas, fully transparent in other areas, and partially transparent in still others. There are two types of alpha, associated and unassociated. Associated (or premultiplied) alpha replaces all of the nonalpha (color or grayscale) information in the image with the values it would have if the image were displayed against a black background; for example, in an RGB image with a premultiplied alpha channel, all RGB values in completely transparent regions are replaced by black pixels. This form can be rendered faster (especially against black backgrounds, where the alpha channel can be completely ignored), but it amounts to a lossy transformation of the image data. Unassociated alpha leaves the nonalpha values untouched; this is the kind supported by PNG.
PNG Specs v1.2 ([url=http://www.libpng.org/pub/png/spec/1.2/PNG-DataRep.html]Data Representation[/url] » Alpha channel) wrote:The color values stored for a pixel are not affected by the alpha value assigned to the pixel. This rule is sometimes called "unassociated" or "non-premultiplied" alpha. (Another common technique is to store sample values premultiplied by the alpha fraction; in effect, such an image is already composited against a black background. PNG does not use premultiplied alpha.)
Chris Cox (TIFF and LibTiff Mailing List Archive » [url=http://www.asmail.be/msg0054766026.html]Transparency ... associated or unassociated alpha is morecompatible?[/url]) wrote: PNG and SGI RGB support associated alpha (aka transparency), just not premultiplied.

TGA is supposed to support associated alpha (transparency), but most users of TGA don't seem to understand the difference and get transparency and general (unassociated) alpha channels confused. When Photoshop 7 shipped with transparency support in TGA format, the users got so confused that Adobe had to go back to using unassociated alpha. The TGA users still can't agree on what they want, much less what they understand.

Associated Alpha == transparency
Unassociated Alpha == using the extra channel(s) for something else
Premulitplication (black matte) / Matting can only apply to transparency, and varies with the file format or sometimes flags within the file format.

Chris



-----Original Message-----
From: ************@lists.maptools.org on behalf of Bob Friesenhahn
Sent: Mon 8/6/2007 3:27 PM
To: William Gallafent
Cc: ****@lists.maptools.org
Subject: Re: [Tiff] Transparency ... associated or unassociated alpha is morecompatible?

On Mon, 6 Aug 2007, William Gallafent wrote:

> I'm experimenting with TIFF export for RGBA images, bit depth
> eight and sixteen. I need to decide which style of alpha
> channel to use in order to maximise interoperability with other

As best I can tell, alpha is only meaningful in TIFF for the associated alpha case. It is the only case where the purpose/use of the alpha is defined. One is only left to assume the intention of the alpha channel for unassociated alpha.

PNG, SGI RGB, Targa, and many other formats supporting an alpha channel use unassociated alpha. In my own experience, unassociated alpha causes less headache (outside of TIFF) since so many other formats and algorithms work better with unassociated alpha. As an example of where associated alpha causes a headache, consider the algorithm necessary to save the image to a palette-based image format.

Bob
======================================
Bob Friesenhahn
********@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/

Re: Transparency — Straight vs. premultiplied alpha

Posted: Tue Jan 07, 2014 5:00 am
by XnTriq
fnord ([url=http://www.fnordware.com/superpng/index.html]SuperPNG[/url] » Manual » Input Options) wrote:
Unlike most Photoshop file format plug-ins, SuperPNG includes an input options dialog. But because it might get annoying to see it every time you open a PNG file, you have to force it open by holding down the shift key as you open a PNG (alt and option keys work too). Once you have it open, you can choose to have it pop open every time by checking the appropriate box. You can also set SuperPNG's default reading behavior by clicking the Set Defaults button.

Alpha Options

There are two ways that Photoshop plug-ins might use an alpha channel: create a floating layer with transparency, or hide it away in the channels palette. Without much rhyme or reason, most Photoshop formats pick one and use it exclusively. SuperPNG lets you choose.
It's worth mentioning that the PNG specification does call for alpha to function as a transparency mask, so that's the default. The spec also says that PNG is to use “straight” RGBA pixels, which is convenient because Photoshop does too. The ProEXR manual has a lot more information about straight vs. premultiplied alpha channels if you're curious.

Multiply RGB

When you choose to send the alpha to the channels palette, the RGB pixels you see will be exactly what is stored in the PNG, i.e. straight. This will often be OK, but in some cases may shock and horrify you. Multiplying the RGB by the Alpha will make those translucent edges appear more natural. You can also use the alpha channel in Photoshop to do the same manually. Or more likely, you really intended to use that Alpha as transparency.