Aha, I steered you wrong.

If you are using the ImageCache, the attribute name is "unassociatedalpha".  
The "oiio:UnassociatedAlpha" is the configuration attribute to use if you are 
using ImageBuf or directly with ImageInput.

Here is a Python example with the usual auto-association:

#!/usr/bin/env python
import OpenImageIO as oiio
buf = oiio.ImageBuf("yang.png")
p = buf.getpixel (9,43)
print ("pixel @9.43: ", p)

$ ./testpng.py
('pixel @9.43: ', (0.19607844948768616, 0.3137255012989044, 0.5490196347236633, 
0.5568627715110779))


And when we set the ImageCache attribute to NOT auto-associate (give us the raw 
values):

#!/usr/bin/env python
import OpenImageIO as oiio
cache = oiio.ImageCache.create (shared=True)
cache.attribute ("unassociatedalpha", 1)
buf = oiio.ImageBuf("yang.png")
p = buf.getpixel (9,43)
print ("pixel @9.43: ", p)

$ ./testpng.py
('pixel @9.43: ', (0.3529411852359772, 0.5647059082984924, 0.988235354423523, 
0.5568627715110779))


As far as I know, these are all correct. I assume that the 
non-auto-premultiplied value, having B > A, means it's a properly 
unpremultiplied file after all.


> On Apr 14, 2016, at 11:03 AM, Yang Yang <[email protected]> wrote:
> 
> Indeed, different packages handles png in different way. 
> I have sent an example png to you.
> 
> Thanks
> 
> 2016-04-14 11:09 GMT-05:00 Larry Gritz <[email protected] 
> <mailto:[email protected]>>:
> All we really know is that several packages do not agree among them what the 
> values are. It's hard to tell which, if any, are correct.
> 
> Can you email me the file?
> 
> 
> 
>> On Apr 14, 2016, at 8:59 AM, Yang Yang <[email protected] 
>> <mailto:[email protected]>> wrote:
>> 
>> Thanks for quickly reply. :-)
>> 
>> I load an png in imageview in IrfanView or Photoshop SE. And both show the 
>> image is 24bpp. So I assume the image itself is premultiplied or there is no 
>> alpha channel info.
>> However, when I use imagecache to open the png and then load it into opencv. 
>> It gives me 4 channel, which alpha channel seems contain transparency info. 
>> But at the same time, I load it using Qt's QImage, it gives me 4 channel, 
>> but the alpha channel is simply a binary mask. 
>> So I am wondering what I can do to let OpenImageIO give me the same result 
>> like QImage.
>> For my purpose, the QImage gives me correct result, while OpenImageIO seems 
>> not correct. I use eariler version of 1.6. I am not sure it is known issue 
>> or just I use it wrong.
>> 
>> Larry, If I use  imagecache->attribute ("oiio::UnassociatedAlpha", 1), the 
>> rgb chanel will not premultiplied, and 0 means it will premultiplied. 
>> Is this correct? 
>>  I set it both before and after call get_imagespec (I don't know it should 
>> happen before or after it), and then call get_pixels.
>> I tried both ways, seems no impact on end result.
>> 
>> Thanks.
>> 
>> Yang
>> 
>> 2016-04-13 19:09 GMT-05:00 Larry Gritz <[email protected] 
>> <mailto:[email protected]>>:
>> Yes, though there are some subtleties.
>> 
>> PNG spec is clear that PNG files store alpha as unassociated. (Bad.)
>> 
>> OIIO is clear that the values delivered to the app should be associated 
>> alpha, and so file format readers that encounter unassociated alpha are 
>> expected to multiply the color channels by alpha in the process of copying 
>> the values to the app's buffer.
>> 
>> Every once in a while, you want to bypass this conversion (usually to 
>> prevent loss of precision), and the way you can do that for an ImageCache is:
>> 
>>    imagecache->attribute ("unassociatedalpha", 1);
>> 
>> (You must do this BEFORE reading anything from the file.)
>> 
>> That will help you get the unassociated alpha when you want it. But Yang 
>> didn't describe that -- he said he wanted premultiplied, and that should be 
>> what OIIO is giving him. Maybe he described it backwards, and he wanted the 
>> original unassociated? If so, see the above advice. The other possibility is 
>> that the data is stored in the file already associated (in violation of the 
>> PNG spec), and he's complaining about the fact that it's being 
>> double-corrected, and in that case the answer also is to set the above 
>> attribute, and just know that the value you're getting is the (unchanged) 
>> associated alpha.
>> 
>> The one thing we can't do is distinguish between unassociated alpha 
>> correctly stored in the PNG, and associated alpha incorrectly stored in the 
>> PNG. Because PNG stipulates that alpha is always unassociated (i.e. colors 
>> not "premultiplied"), there is no PNG header field that indicates whether 
>> the alpha is associated or not, because the spec says it always must be.
>> 
>> 
>> 
>>> On Apr 13, 2016, at 4:36 PM, Troy Sobotka <[email protected] 
>>> <mailto:[email protected]>> wrote:
>>> 
>>> PNG, by specification,  can only use unassociated alpha.
>>> 
>>> With respect,
>>> TJS
>>> 
>>> 
>>> On Wed, Apr 13, 2016, 3:17 PM Yang Yang <[email protected] 
>>> <mailto:[email protected]>> wrote:
>>> HI All,
>>> 
>>> I am trying to read a bunch of png images supposed to have premultiplied 
>>> alpha.
>>> However, it always give me unpremultiplied alpha.
>>> 
>>> I don't know how can i configure Image cache to give me correct result.
>>> 
>>> Could anyone give me suggestion?
>>> 
>>> Thanks,
>>> 
>>> Yang
>>> _______________________________________________
>>> Oiio-dev mailing list
>>> [email protected] <mailto:[email protected]>
>>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org 
>>> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
>>> _______________________________________________
>>> Oiio-dev mailing list
>>> [email protected] <mailto:[email protected]>
>>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org 
>>> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
>> 
>> --
>> Larry Gritz
>> [email protected] <mailto:[email protected]>
>> 
>> 
>> 
>> _______________________________________________
>> Oiio-dev mailing list
>> [email protected] <mailto:[email protected]>
>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org 
>> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
>> 
>> 
>> _______________________________________________
>> Oiio-dev mailing list
>> [email protected] <mailto:[email protected]>
>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org 
>> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
> 
> --
> Larry Gritz
> [email protected] <mailto:[email protected]>
> 
> 
> 
> _______________________________________________
> Oiio-dev mailing list
> [email protected] <mailto:[email protected]>
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org 
> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
> 
> 
> _______________________________________________
> Oiio-dev mailing list
> [email protected]
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

--
Larry Gritz
[email protected]


_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to