Tuesday, May 6, 2008

Converting to 32bpc in Photoshop Without Altering Pixels

Many people have a problem with color management. They think that when they open a JPEG in Photoshop, the pixels in the file should be the pixels that are shown on screen, but this is often not the case! If you have an sRGB image being viewed on your Mac monitor, Photoshop will darken the display pixels to show what the file would look like on a true sRGB monitor. Even if you think there's no ICC profile for the image, Photoshop will use the working space designated in Color Settings (usually sRGB). In general, this is probably what you actually want, but some people find it unsettling.

In another attempt to force users to do the right thing, Photoshop insists that all 32 Bits/Channel (floating point) images use a linear profile. When you convert your 8-bit sRGB image to 32-bit, Photoshop will linearize the pixels while simultaneously assigning a linear profile. The net result is that the image looks the same, even though the pixel values have changed. Again, this is usually what you want.

Except what if you don't want the pixels to to change, other than get converted to a higher bit depth? It is possible to do this, but it involves tricking Photoshop a little. I'll explain below.

To start, we'll take the famous Marcie image. This is a 10-bit Cineon file in Log space. Photoshop will open it as a 16-bit file without a profile (which means it uses your RGB working space). Marcie is a useful example for us because many film users still paint on Log images.

If you set the Photoshop Info Palette eyedropper to 32-bit mode and sample the grey LAD patch, you'll see values of 0.435 for that area. Now convert this file to 32-bit mode and sample again. Even though the image does not appear to have changed, the LAD patch is now reading 0.159. As mentioned above, the pixels have been darkened while the profile was linearized.

To convert from 16- to 32-bit mode without the change, revert to the original file and follow these steps:

1) Assign a linear profile (Edit > Assign Profile…) that you've previously created. When you do this, the image will appear much brighter, but using the info palette you can verify that the LAD patch is still 0.435. The Assign Profile function doesn't alter pixel values, only how they are displayed.

2) Now convert to 32-bit mode. The image will appear unchanged, which is to say too bright. But when you sample the LAD patch, you'll see that it has retained its value of 0.435. Photoshop usually converts from whatever profile you're using to a linear profile, but because we told it we already had a linear profile, no change takes place.

3) Your pixels are now in floating point Log space. If you save this image to an OpenEXR file, most file readers will assume linear space and brighten the image as Photoshop is doing. It will be up to you to make sure the Log pixels are treated properly in whatever program you're sending them to.

While Photoshop always defaults to using color management, there is a way to turn it off. By going to View > Proof Setup > Monitor RGB (make sure View > Proof Colors is also on), Photoshop will treat the file like is has the same profile as your monitor, so no transform will take place. In the above example, this would show pixels in Log space. You can also use View > 32-bit Preview Options to view a file with Gain and Gamma in 32-bit mode.

This workflow is currently being used in production by film studios who want to paint in Log, but export an OpenEXR file using ProEXR.
The part of the equation that is really missing is a way to convert from Log to floating point linear in Photoshop so that the EXR can have its proper linear values. Hopefully one day there will be a way to do this.

Update: Now there's a way!

Monday, May 5, 2008

Making a Linear ICC Profile

ICC Profiles usually describe devices, and real devices are never linear. In other words, they generally have a gamma other than 1.0, and usually some sort of custom curve you might measure with a spectrophotometer.

But sometimes you want a linear ICC profile. Perhaps you want to set up a linear color space to use in After Effects 7. Or maybe you rendered a 16-bit file into a linear color space using a 3D program and need to tag it that way. Here I'll show you how to use Photoshop to create a linear color profile.

1) Go to the Color Settings dialog (Edit > Color Settings…)

2) If necessary, click on the "More Options" button.

3) Check the profile you have set for your RGB working space. It defaults to sRGB (in Adobe parlance "sRGB IEC61966-2.1"). Whatever profile you set here is the profile that we will be making a linear version of.

4) With your profile set, go to "Custom RGB…" in the same menu. A dialog will pop up.


5) The Custom RGB dialog will be filled in with settings from the profile you previously selected. In many cases the Gamma field will be an approximation, but it doesn't matter because you want to set it to 1.0, making this profile linear.

6) Make sure you edit the Name field. Call the new profile something like "Linear sRGB".

7) You can leave the rest of the fields as they are. Click OK.

8) Your custom profile is now selected in the menu, but it still lives only in Photoshop. We want to save it out by going to "Save RGB…" in the same menu. This will give you a Save As… dialog. You should drop the profile someplace it will be seen by other applications, such as:

Mac: /Library/Application Support/Adobe/Color/Profiles/
Win: C:\Program Files\Common Files\Adobe\Color\Profiles\

Give the profile a reasonable file name, although the name you used previously in #6 is what will appear in menus. You probably want to name the file the same.

9) With the profile saved, you probably would prefer to Cancel out of this dialog box, assuming you don't want to set a linear profile to your Photoshop working space.


And with that you've created a linear profile to be used in any profile menu. ICC profiles in general consist of a combination of color primaries and response curves. The color primaries describe the device-independent color sensation you get when the display shows pure red, green, blue, or white. The response curves (which could be a simple gamma curve) describes the transition from red/green/blue to black.

In the process described above, we adopt the color primaries from a profile and set the response curves to linear. If we convert an image from the original profile to the linearized profile, the result is a simple Gamma-style transformation that doesn't involve channel cross-talk and can easily be reversed.

Friday, November 16, 2007

HDR Tone Mapping Using Film Profiles

By definition, an HDR image contains more latitude in pixel brightness than can be displayed on a monitor. When you take a standard digital photo of something bright like the sky at sunrise, a short exposure may capture the sky properly, but the ground will be black. Re-expose to capture the ground and now the sky is blown out.


The really maddening thing about digital cameras if that you get to see the photo right after you take it. So you see your black ground on the screen but then look up to find that the ground isn't black at all. In fact, it may look about as bright to you as the much lighter exposure where the sky is completely gone. There you stand with your eyes easily able to see everything, a little annoyed with your camera's poor showing.

In a nutshell, the problem is dynamic range. You eyes can capture a wide dynamic range, but the camera is capturing a narrow one. HDR photography lets you combine different exposures to create a floating point image that represents the real world scene being photographed, sans your camera's limitations. But then when you want to show these scene-referred pixels on your monitor, you have to do some tone mapping.

Here are examples of tone mapping available in Adobe Photoshop and After Effects. The first four are the standard ones that ship with Photoshop, while the last two are made using a technique I'll show you.


Legend:
1. sRGB / Gamma 2.2 curve
2. Highlight Compression
3. Equalize Histogram
4. Local Adaptation
5. Film Profile Tone Mapping
6. Film Profiles + color correction and film grain

The sRGB curve in #1 is what is typically displayed by default. A gamma curve is applied to the 0.0-1.0 range and the rest is clipped. This is what you'd get from just taking a regular photo.

Options 2-4 try to bring bright values down into visible range without crunching the other pixels too badly. You can see in each example that more detail has been brought out around the sun and the coarse clipping has been reduced. However, each technique has trade-offs. You'll notice that detail is lost in areas where a bright object comes close to a darker one such as the disappearance of a clear horizon line near the sun. Local Adaptation can sometimes produce halos in these circumstances as it fights to maintain contrast while bringing pixel values together. Sometimes the image comes out looking more like a painting than a photo.

Don't get me wrong, each image is different and these algorithms can produce some good results. But a tone mapping technique I have grown to like involves simulating the way film would capture that same scene. For one reason or another, people have always had a fondness for the look of film, and many movies are still shot on film for this reason. But what is it about the look of film that people like so much?

One explanation is that film is the original high dynamic range capture format. Even under long exposures a film negative is never absolutely 100% exposed, so the bright areas of highlights can retain detail that would be lost by a CCD.

After Effects CS3 ships with a series of ICC profiles that describe the response of different film stocks to light. Since an HDR image describes the actual light in a scene, converting from the linear HDR color space profile to a film stock profile using the Color Profile Converter creates a simulated negative in Log space (make sure you use the Absolute Colorimetric intent). From there, you can apply a Theatre Preview Profile, which simulates that negative getting printed on a film positive and the projected. So if you trust the color science involved, you're looking at your scene as if you had shot it for a Hollywood movie.


Looking at example #5, you can see that the results are pretty impressive. There is a good tradeoff between detail around the sun and detail in the rest of the scene. And the sun has a very nice film-style glow around it with no hard clipping at all. Since the film profile response is a simple curve, you don't get any of the artifacts of the other tone mapping methods. Finally, there is probably something about the simulated printed film that will remind you of all the movies you ever saw before the dawn of the digital age.

In this case I'm doing everything manually—I've disabled all color management by using no working space profile and checking "Preserve RGB" in the HDR files. The same process can be set up as a display LUT so that your project lives in linear, but gets viewed through the film preview. To do so, set a linear project working space, turn on Display Color Management in the View menu, and then turn use View > Simulate Output > Kodak 5218 to Kodak 2383, which uses the same settings I am. However, to actually output an 8-bit JPEG or TIFF with the film look, you'll have to set up the Color Profile Converter as I have.

In example #6, I have done a little more processing. By applying a Levels call to the original linear HDR pixels, I can do a realistic color correction where light is brought down in the scene as it would in nature, making it cooler in this case.

Then I add a little film grain while the pixels are in simulated Log space, in between the two Color Profile Converter applications. Add grain is a 16-bit effect, but this matters little because log space does not need floating point values over 1.0. In fact, Log is usually stored in 10-bit Cineon files, so you have more bits than a typical film scan would.

By switching the simulated film stocks, you can also see how your same scene—accurately stored as an HDR image—would appear using different stocks. Much cheaper than experimenting with the real thing.

Tuesday, November 13, 2007

Power Picker 1.1

At long last Power Picker has been updated to work with modern operating systems and the latest version of After Effects. That means Universal Binary for you Mac users.
BTW, does anyone else dig the Power Picker logo?


Thank you PP users (especially Ruth Dial) for your patience!

Monday, November 12, 2007

ProEXR is a CS3 Essential

In the November issue of DV, Ned Soltz lists ProEXR as one of the "Ten Essential Photoshop CS3 Plug-Ins." Got that right…I mean…thanks!

Writing in the Instant Expert column, he calls it an "important acquisition for those who regularly go between PS and AE." How nice of him! If you're not a DV subscriber, you can currently view a PDF version of the article here.

Friday, November 2, 2007

ProEXR 1.2 released

I've posted an update to ProEXR. There are a number of small improvements in this version, mostly based on user requests and bug reports.

One feature I'll mention is that ProEXR is now saving more of the standard EXR metadata in files it creates. Information such as the user and computer name is being stored, which can be particularly useful for people with render farms trying to track down the source of a bad frame. In After Effects, the project and comp used to create the file are stored too, along with anything written in the seldom-seen Render Queue Comments field.

To see all the attributes being stored, open an EXR in Photoshop and view the File Description.

Thursday, October 25, 2007

Free Übercolor

When After Effects 7 was released a few years ago, the new color management features made our Übercolor plug-in obsolete, so it was quietly discontinued. (In fact, one might say that Adobe's Color Profile Converter bares a remarkable resemblance to Übercolor.) No big deal—this is all part of life as a plug-in developer.

But today I got an email from an AE 6.5 holdout looking to use it. So I thought what the heck, and uploaded a free version to the old product page.