From PNG to TIFF with premultiplied alpha?

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
elmimmo
Posts: 28
Joined: 2011-02-02T05:42:42-07:00
Authentication code: 8675308

From PNG to TIFF with premultiplied alpha?

Post by elmimmo »

How do I output to TIFF with alpha premultiplied?

Code: Select all

convert in.png -define tiff:alpha=associated out.tif
That seems to tag the alpha as premultiplied but not do the premultiplication itself. Input and output look different.

Input is RGB+A with 8-bit channel depth. ImageMagick is version 7.0.9-20.

snibgo
Posts: 12932
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: From PNG to TIFF with premultiplied alpha?

Post by snibgo »

Your input and output should look the same. If they don't, please post links to them.

"Premultiplication" is a sub-operation within operations such as blur, image addition or subtraction, and so on. It means that alpha is used in the calculations.

So operations use premultiplication. Images are not tagged as having been premultiplied.
snibgo's IM pages: im.snibgo.com

elmimmo
Posts: 28
Joined: 2011-02-02T05:42:42-07:00
Authentication code: 8675308

Re: From PNG to TIFF with premultiplied alpha?

Post by elmimmo »

This is the input (enter in URL address and save as in.png)

Code: Select all

data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKAAAACQAgMAAADy24gTAAAADFBMVEX///8AAAAAAAAAAAD4jAJNAAAABHRSTlMAc3mA9mHxDAAAAEdJREFUWMPt1qERgDAQRcFTGERap45URQl0QBr44iaCQezTW8CrkiR93TFDV4DjDT0BngneIAiCIAiCIAhuwPaHt89ekvSTFu26DY5mdiViAAAAAElFTkSuQmCC
This is the output (save as out.tif)

Code: Select all

data:image/tiff;base64,SUkqAP4AAAB42u3csQkCURRE0Z+IDZmYbembmdiQmFjBh4WLvOScCoZbwKwFAAAAAAAAAAAAAEMe6zY94YLvek9P2DimB1x0Tg/YeK779IQLPus1PWFDv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv0a/Rr9Gv+aYHnDROT1gw/84AAAAAAAAAAAAAPBHP+7RlAERAAABAwABAAAAoAAAAAEBAwABAAAAkAAAAAIBAwACAAAACAAIAAMBAwABAAAACAAAAAYBAwABAAAAAQAAAAoBAwABAAAAAQAAABEBBAABAAAACAAAABIBAwABAAAAAQAAABUBAwABAAAAAgAAABYBAwABAAAAkAAAABcBBAABAAAA9gAAABwBAwABAAAAAQAAACkBAwACAAAAAAABAD0BAwABAAAAAgAAAD4BBQACAAAAAAIAAD8BBQAGAAAA0AEAAFIBAwABAAAAAQAAAAAAAAD/Cdej/////3/helT//////8zMTP//////mZmZ/////39mZib/////7yhcD/////9/Gw1Q//////9XOVT/////
snibgo wrote:
2020-02-03T10:09:46-07:00
Images are not tagged as having been premultiplied.
Identify does report the resulting alpha as associated, which AFAIK means image viewers should interpret RGB values as premultiplied by the associated alpha with a black matte.

Code: Select all

$ identify -verbose out.tif | grep "tiff:alpha"
    tiff:alpha: associated

snibgo
Posts: 12932
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: From PNG to TIFF with premultiplied alpha?

Post by snibgo »

Hmm, yes, "-define tiff:alpha=associated" does modify the image when it is written. I didn't know that. A simple example:

Code: Select all

f:\web\im>%IMG7%magick xc:rgba(10%,20%,30%,0.3) t.tiff
f:\web\im>%IMG7%magick t.tiff txt:
# ImageMagick pixel enumeration: 1,1,65535,srgba
0,0: (6554,13107,19661,19661)  #199A33334CCD4CCD  srgba(10.0008%,20%,30.0008%,0.300008)

f:\web\im>%IMG7%magick -define tiff:alpha=associated xc:rgba(10%,20%,30%,0.3) t.tiff
f:\web\im>%IMG7%magick t.tiff txt:
# ImageMagick pixel enumeration: 1,1,65535,srgba
0,0: (21845,43690,65535,5898)  #5555AAAAFFFF170A  srgba(33.3333%,66.6667%,100%,0.0899977)
Is this correct behaviour? I'm not sure. I'll have to read around the subject, eg https://en.wikipedia.org/wiki/Alpha_com ... multiplied
snibgo's IM pages: im.snibgo.com

Post Reply