Friday, February 12, 2010

log2lin and lin2log in Photoshop

Some time ago I wrote a couple blog posts about working with Log images in Photoshop and how you can convert them to 32-bit linear for saving out as OpenEXR. It involves a little bit of Photoshop trickery unfortunately, but it works and you can set up actions and scripts to do it in one step, which I'd recommend.

One oversight on my part, however, was not describing how to go from 32-bit linear back to 16-bit Log. It's similar to doing the log2lin steps in reverse, but not quite. So, starting with a good looking 32-bit linear image...

1) Use the Cineon Converter to apply a lin2log operation to each layer. Typically you'll use the default settings, but switch the conversion to lin2log. After you do this, your image will look bright and washed out because it's been converted to Log space but is still getting the gamma correction Photoshop does to all 32-bit images. Don't worry.

2) Here's the tricky part. We have to convert back to 16-bit without Photoshop changing any pixels. During this mode switch, Photoshop converts your linear 32-bit image into whatever color space is set as your default RGB working space. So you have to go into the Color Settings dialog and temporarily change that to the linear color profile you've previously created.



3) Now change the image mode from 32-bit to 16-bit. Thanks to the previous steps, your pixels will now be in 16-bit Log space. When asked about Exposure and Gamma, leave those values untouched (0.0 exposure and 1.0 gamma). The image will not look any different (which is always the preferred behavior for switching image modes) and the pixels will not change values because of that linear profile.

3.5) You probably don't want a linear profile as the default working space, so change your Color Settings back to their original values, usually with sRGB as the default RGB working space. You probably notice this is kind of a pain - all the more reason to script it via JavaScript and Actions.

4) Open the Assign Profile dialog and assign a better profile to this image. If you apply sRGB (or tell Photoshop not the manage the document), you will see the image in Log space. You may also choose another profile to do some sort of film preview, such as the Theater Preview profiles that ship with After Effects.

And that's it. You should be able to start with a 16-bit Log file, use the various steps to convert it to 32-bit linear, use these steps to convert it back to 16-bit log and arrive at exactly the same image you started with, which is always an important test for any color pipeline.


For the record, you're not crazy if your have a 32-bit linear workflow but want to paint in log space. For one thing, many of Photoshop's tools aren't available in 32-bit (hello, Curves?!?). And some of the tools that are in 32-bit have not been appropriately tweaked for linear (I'm looking at you, Levels). Finally, if you have some film preview profiles, Photoshop can't use them in 32-bit mode like After Effects can.

So by painting in Log, you 1) reclaim some of your favorite tools, 2) can use film preview profiles, and 3) can still paint overbrights because 100% white in log space maps to 13.52 in linear. But be careful! Realize that layers will composite in Log space differently than in linear space, especially if you have soft feathered edges or use transfer modes such as Screen. If you flatten your layers before converting to 32-bit this won't be a problem, but if you need the layers to be separate, make sure you test everything first.

12 comments:

the-arioch said...

hello!

could you make Jpeg2000 free plugin for IrfanView - fast and free picture viewer for Win32 ?

currently it is bundled with ira's shareware, that allows viewing for free, but requires money for writing files.

IV aready have some support for Photoshop plugins, though i think native plugin would be better

Since you already made bridge frm your ib to Photosho API, maybe it sould not be too hard to do same for IV API ?

http://irfanview.com/plugins.htm

Just user, not IV author

Cutter22 said...

Hi Brendan,

I'm trying to convert dpx log to lin. Thank you so much for all your help on this. I've tried opening your plug in Cineon convertor, but I get this message: "Could not complete your request because Photoshop does not recognize this type of file."

Am I doing something wrong?

Thanks in advance!

Brendan said...

You don't actually open the plug-in in Photoshop, you install it by copying it to the plug-ins folder. Then re-launch and it should be in the Filter meun under "fnord".

Anonymous said...

Hey Brendan, thanks for sharing your fantastic work. Would this pipeline also work for Log-C images? Would I just need a different ICC profile?

Thanks in advance!

-Nick

Brendan said...

You could use the Cineon Converter to convert Log-C to linear if you could come up with the proper alternative Cineon settings, which may or may not be possible. I haven't found any settings, but many standard LUTs are just different permutations of Cineon Converter settings.

OpenColorIO includes a Log-C conversion LUT in the nuke-default configuration. Don't have a Photoshop version of OCIO, but you could use the After Effects plug-in. Could also use the AE plug-in to try to export a LUT that maybe Photoshop CS6 could use in its new apply LUT feature.

Anonymous said...

Thanks for your help, I will try all this out.
Any plans for an OpenColorIO plugin for Photoshop? :)

-Nick

Brendan said...

No immediate plans for a Photoshop version, but I'm thinking about it. You know, it is possible to pay people to work on open-source software. ;)

Anonymous said...

If you put up a donation link, I'm sure a lot of us will be more than willing to pitch in. :)

-Nick

Anonymous said...

Are there any solution for log-C images ? It would be great if it would be integrated into cineon converter...

Daniel

Brendan said...

OpenColorIO for After Effects has a Log-C color space in the nuke-default config. You can use AE for the conversion or make a LUT for Photoshop.

Or you could try messing with the Cineon Converter settings. For many log-like curves, you can tweak the Cineon values to mimic them. I just experimented a little and 95, 585, 0.85 look like pretty good settings for LogC.

Daniel said...

Hi Brendan,
Could it be possible to have the same log2lin operations per channels. So we could have different settings for R G and B. To be able to match nuke log2lin.
Is that planned in the future ? Is there another way to do it already ?

Daniel

Anonymous said...

Any plans in the future for OpenColorIO in photoshop ?