OCIO sRGB Alpha conversion problem

Hello all, I’ve been having a problem when trying to export both jpeg and PNG images and having them match up correctly.

The PNG has an alpha channel with a shadow and that shadow always comes out darker, it seems that when the color space changes from Linear to sRGB it doesn’t change the color space of the alpha area and keeps the shadow at a gamma of 1 instead of 2.2

I’ve tried correcting the alpha channel with a gamma correction and that does brighten up the shadow, but it doesn’t maintain the correct falloff as the Jpg export.

Attached you can see the difference in shadows once the png has been
re-composited on a white background.

Does anyone know of a solution to this?
Thanks very much

The alpha channel conveys transparency as a mask over the RGB channels, so I’m pretty sure the sRGB conversion isn’t doing anything to or with it.

I don’t really know anything about Natron, but I think you need to find a way to scrape that alpha channel off the PNG and just render the RGB channels.

Can you share your graph and raw picture(s)?
Remember that, to be rendered correctly, an object with transparency has to be first rendered on black background (check the equations), and then it can be composited on white background.

If your PNG, before recompositing, has anything else than a black background, it won’t be correct.

Then, when recompositing, the background must be solid (alpha=1) and you must use the OVER operator. The output image should have NO transparency. There shouldn’t be anything with alpha over 1 in the image.

Remember that PNG is stored with alpha un-premultiplied, but Natron uses premultiplied alpha internally, so before writing to PNG, RGB is divided by alpha, and then linear->sRGB conversion is applied. Alpha is stored linear in the PNG file.

Hi Frédéric, thanks for the quick reply.

The Raw Images are .EXR images from Vray they go through a colour correction pipeline and then get exported to both a Jpg and a PNG.

I can share the Natron file and the Raw File if you want, but I’d prefer to send it directly as the files are confidential hence why the image ontop has a black fill :slight_smile:

Thanks very much.

Does the result of your “PNG export” above have alpha=1 everywhere? It should. If not, then you composited over a non-solid background.
Click on the checkerboard icon in the viewer. If you see the checkerboard, something is wrong.
This is most certainly a premultiplication issue in you graph. You can convince yourself by removing the alpha channel: before the writer, add an “unpremult” node, followed by a shuffle node that sets alpha to 1. These are the raw RGB values that will be written to the JPG, so it should look like your JPG output

It does not have alpha = 1 everywhere which is what I thought I’d want in order to have a transparent background for the PNG.

What I’m trying to achieve is export the png with the shadow above but without the white background so that I can re-composite it on white or another color later, but when I do that, as seen above it doesn’t have the same shadow.


I’m not a professional compositor, but it seems to me that the shadow is not the same thing as the object itself.
What you need to do is render a separate shadow pass in VRay (or Blender). The shadow cannot be composited the same way as the object itself: object is composited “over”, whereas the shadow is composited with a “multiply” operation.

1 Like

What you need to do is render a separate shadow pass in VRay (or Blender). The shadow cannot be composited the same way as the object itself: object is composited “over”, whereas the shadow is composited with a “multiply” operation.

@Chad_Stevens +1 to this advice, this seems like the answer you’re actually looking for. Shadows cannot be added overtop other objects because when we fake them accurately with CG we want to remove light from the scene. Doing it in a two step approach will yield better results and allow you more control over the look of the shot.

If you need more control you can also shuffle the shadow pass and used it as an alpha channel to drive a grade node multiplying and darkening the plate.

Thanks, guys.

Attached is the effect I was looking for, but I need to export it as a linear image and apply the gamma afterwards in photoshop.

Alternatively, I have to Apply the gamma 2.2 to the alpha in Natron, but the problem is it doesn’t maintain the same falloff.

I do not understand what you are trying to do.

The Alpha channel in PNG is linear, as written in the spec (section 2.7 of the spec).

If what you are trying to do is write the alpha channel in a single-channel grayscale file, using the RGB channels to store alpha (libpng will recognize that all channels are equal and write a grayscale PNG) then all you have to do is:

  • copy alpha to R, G and B, and set A to 1 using a Shuffle node
  • in the Write node, set Output components to RGB, and change the “file colorspace” to Linear

I’m sorry if I’m not explaining myself correctly, I’ll try and explain it more clearly.

  1. I have a scene rendered in 3ds max with Vray that has a Tool on a matte shadow floor. when rendered this has the tool at Alpha 1 and the shadow at a gradient going from between Alpha 1 and 0 the further the shadow gets away from the Tool. See Below.

  1. I take this render into Natron, I split the Tool and the Floor (Shadow) So I can grade them separately.

  2. I then have 2 Output nodes
    one goes to. JPG which will export the tool and the shadow on a white backplate with NO Alpha Channel
    The other exports a .PNG with just the tool and the shadow and no white backplate so it has an Alpha Channel similar to the one I attached above.

  3. In the end I have 2 images, one with a tool, shadow and white background and one without a background but still contains the shadow and tool. The latter is used for when I want to merge the tool onto a new colour/background at a later date.

The problem I have is that the shadows do not match when re-composited onto a white background. the Jpg looks great, but when I take the PNG with the alpha channel into photoshop and merge it onto a white backplate the shadow is darker as seen in my first post.

I believe this is because as you said the Alpha Channel is kept at a gamma of 1 or linear when exported to a .PNG whereas I need it to be a gamma of 2.2 or converted to sRGB to match the jpg.

I hope this makes more sense.


1 Like

For me, everything is working as expected, and I get exactly the same image when compositing under Natron or Gimp (sorry, I don’t have PS).

I attached a Natron 2.3.16 project and a GIMP file, as well as the various render steps.
It is using a linear ramp with a pure black color, so R,G,B=0 and alpha is a linear function of y.

You can check that alpha is exactly 0.5 at the center of the image. This is written in ramp.png.

When compositing over solid white (R=G=B=A=1, written in white.png), you get R=G=B=0.5 at the center, and alpha=1 of course (since the background is opaque). This is what is written in the JPEG file rampoverwhite.jpg

Now if I re-read ramp.png and composite it over the solid white background, I get rampoverwhitenatron.png, which is identical to rampoverwhite.jpg

If I do the same in GIMP, compositing ramp.png over white.png, I get exactly the same thing, see rampoverwhitegimp.xcf and rampoverwhitegimp.png.

See the attached archive.

I think there is some misunderstanding, but I do not understand where.

jpgvspng.zip (30.9 KB)

No, alpha is definitely linear and has always been, as per the PNG specifications.

Alright, So I’ve just composited your images over in Photoshop and this is what I get, same problem so I’m guessing it’s a PS problem or maybe just my version of PS.

Photoshop is known for having had erroneous handling of Gamma in the past (http://www.ericbrasseur.org/gamma.html) but I thought it would have been fixed.

Can you try with the GIMP and see if you have a different result than photoshop? GIMP works for me.

Do you have the “Blend RGB Colors Using Gamma 1.” option in photoshop that’s discussed here: https://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/

If yes, you may want to consider enabling it.

1 Like

Thanks very much, that does indeed solve the issue. :slight_smile:

Thanks again for all the help. I really appreciate it.