-
Hi ! I have a few questions about how OIIO handles the alpha. Here is my code: import OpenImageIO as oiio
path = "D:/test_alpha_oiio.png"
output = "D:/test_alpha_oiio_02.tx"
Input = oiio.ImageBuf(path)
config = oiio.ImageSpec()
config.attribute("maketx:filtername", "lanczos3")
config.attribute("maketx:ignore_unassoc", 1)
config.attribute("maketx:v", 1)
result = oiio.ImageBufAlgo.make_texture(oiio.MakeTxTexture, Input,
output, config)
print(result)
if not result:
print("error:", oiio.geterror()) The result is an image TX premultiplied. I've tried The only way I successfully had an unpremultplied result was to load the image with a config So my questions are:
For information, I've tried the same image in exr format to tx, and it worked (without any ignore_unassoc flags). Thanks! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Loading an image with configuration hint I'm looking at the code for the "maketx:ignore_unassoc", and I think it's not doing everything it's advertised to do. I think some fixes are in order. |
Beta Was this translation helpful? Give feedback.
-
Extended background info that everybody should know... There are two ways to interpret color + alpha in an image:
You can convert from unassociated to associated alpha by multiplying the color channels by alpha. (That's why some people call associated images "pre-multiplied".) You can try to go from associated to unassociated by dividing by alpha, but this doesn't always work (divide by zero?), and you will lose any of those associated pixels where, like I described earlier, you have certain types of glowing or transparent pixels. It's not just pure emission or glows, this can also pop up in other unexpected places. For example, consider a piece of glass that is 99% transparent but catches a very bright specular highlight -- its associated value might be (0.8, 0.8, 0.8, 0.01), and it has no way to be represented as an unasociated pixel in a non-HDR format because normal integer 8-bit or 16-bit pixel could represent values > 1 and the theoretical way to represent this pixel as unassociated would be (80, 80, 80, .01). In fact, for an integer-based format, unassociated alpha cannot represent pixels where the light sensor values are greater than the opacity. So for these reasons -- easy to reason about, simple and uniform math, and the ability to represent pixels where the light amount is greater than the alpha value -- rendering and compositing software really, really, really want to think entirely in terms of associated alpha. OK, so now that brings us to OIIO. Most "professional quality" image formats only allow associated alpha, because that's the only way to think about the behavior of light that makes any sense at all. (Not all image formats are so enlightened, let's just leave it at that.) OIIO by default automatically translates any unassociated alpha it comes across into associated -- both because this is almost always what you want, and also to simplify the task of the software calling it. Otherwise, app software would EVERY TIME have to figure out if the image it was asking OIIO to read was associated or unassociated alpha, and have its own logic to handle both cases. So OIIO does all that for you and lets you assume any pixels you get from OIIO are by default associated alpha. PNG, in its infinite wisdom, by its own specification, insists that it always stores unassociated alpha. If you start with a PNG file, then the default behavior of maketx is to convert it to associated alpha. You can use the I don't recommend storing your textures unassociated. I mean, at the very least, that means your shaders need to specifically know which texture are associated and which are unassociated, and handle each case properly. |
Beta Was this translation helpful? Give feedback.
-
OK, so I looked into this more today. Here's what I found:
|
Beta Was this translation helpful? Give feedback.
-
Thank you so much for these explainations ! About the 2. of your answer, I was using at first the maketx.exe from Autodesk Arnold, wich has not the But indeed, I just tried with the Thank you Larry! |
Beta Was this translation helpful? Give feedback.
OK, so I looked into this more today. Here's what I found:
maketx
executable did some extra work that, as far as I can tell, did this correctly all along.