VF - The Mechanics

04 September 2010

First of all, a note for everyone who's been following so closely - your support means a lot. Further, I apologize for the delay in posting this. Unlike more established bloggers, I'm not just posting up pre-written material. I'm writing this as we go and attempting to respond to what I hear back from you in the process. As such, when life throw's me a curve ball, posting gets delayed. You have my apologies.

Now, before we get into how we do lots of fancy things in Photoshop, this is going to be one of the most intensive days we spend on technical discussion, so let's start by spending a few moments reviewing where we've been so far. First, we demonstrated that (just like sounds) images can be seen (Ha! I kill me!) as being composed of many different frequencies which interact in order to create a whole image. We discussed the definitions for all of the processing tools which we're going to employ - lowpass, highpass, bandpass, and bandstop filters. And we looked at how adding the low frequencies and the high frequencies from an image together gives us the whole:

DC United's Chris Pontius

Then we expanded upon this to realize that, like the simpler kinds of math (the good kinds), the order in which we do things is commutative - that is, that subtracting the low frequencies from a whole image is the same as directly extracting its high frequencies through a highpass filter:

Image subtraction demo

Most recently, we discussed how the bandpass and bandstop processes can be thought of as being similarly inverse processes.

So - how do we do it in PS. Do we just use the High Pass (HP) and Gaussian Blur (GB) filters? Unfortunately, no, and the reason why is going to involve some more... math (sorry guys!), and one of those little white lies which I've been telling you up until now.

To make our first pass at explaining what goes on, let's go back to our audio examples. When we were adding two audio tones together, each of those component sounds had amplitudes between -1.0 and 1.0. Or we might say that each had a range of 2. Because when we add them together we could get extremes of: 1 + 1 or (-1) + (-1), our result could have amplitudes from -2.0 to 2.0, or a range of 4. In theory, each time we add a sound in, we expand the range of the data which we're trying to handle. In real life, though, we have to keep those values scaled to a range which we can actually work with.

What does that mean for images?

For the purposes of discussion, we'll refer to PS images being able to have levels (the equivalent of amplitudes) from 0 - 255 (a range of 256). In truth, many of you know that with 16 or 32 bit processing you have different ranges, but we'll only use one set of numbers for now.

Anyway, there are a number of differences between performing operations on sounds and on images in PS. The most significant of these is the fact that images don't (naturally) have negative values. Photoshop doesn't store brightness values of -255, or even of -1 (at least not for our purposes), and the images we work with aren't -255 to 255, -128 to 128, etc. This has some significant implications for how we handle our operations.

As an example, let's pretend we don't know about that difference and I'll separate an image rather naively. I'm going to use the picture of Santino which we've used a few times so far:

Tino

Now, I'll blur a copy of that image in a separate layer:

Tino Blurred

And subtract that from a third copy with the Apply Image command:

Tino Blurred

Not very much like what I've been showing you so far, is it? Sorry about that.

Here's the problem - do you remember how when we were mixing low and high sounds together, sometimes the high frequency brought the low frequency signal 'up', but at other times it brought it 'down' (and vice-versa)? [go back to review the time-correlated tracks to see what I mean] Now look closely at the result I've shown you above. You'll notice that the result only shows those areas which are brighter than the low frequency version. And this is because we don't have negative values. All of the areas which were darker in the high frequency than in the low frequency have been clipped to 0.

Take a minute to digest that, because it's as important as it is difficult to understand. The high frequency data doesn't "know" that we need it to occupy a finite space, and it wants to have both positive and negative values, just like it would in real life. Not having negative values means that we need to find another way to record those areas which are darker in the other frequency set. One way of dealing with this is to just take the darker areas of the high frequency data and combine those back into our mix above - we would use three layers to accomplish one separation, demonstrated in the image below. To do this, I created the 'Lighter High Frequency' layer as above, and the 'Darker High Frequency' layer with the Apply Image command (more details later). Take a look:

Tino Separation

In the first high-frequency set, our blend mode (which we'll discuss after bit) is ignoring the black areas while adding the light areas into the final image (adding black to a pixel is like adding zero to a number). In the second high-frequency piece, the dark areas are lowering the final values while the white areas are ignored.

This is technically great because it gives us a 100% accurate de/reconstruction of our image (that is, summing those three layers back together is pixel-for-pixel identical to the original). On the other hand, it's really inconvenient for our high-frequency data to be on two separate layers. How might we get it onto a single layer?

That leads us to our second technique. In this one, we pretend that we can have both 'positive' and 'negative' numbers in the same layer. To do so, though, we need an arbitrary value which will serve as the '0' point around which positive and negative values will appear. In Photoshop, this is 50% gray - that neutral value which many of you already use as a starting point with Soft Light, Overlay, etc. layers. Photoshop will ignore that middle gray value (it won't change the pixels when we blend with it), but when other values are brighter than 50%, it will lighten the final image while when values are darker than 50%, it will darken the final image. This option is what most retouchers I know do in practice, and what I hope you will settle upon at the conclusion of this discussion.

Like most things in life, though, this isn't going to come free. In order to put two layers into one as we're discussing, a compromise has to be made. Remember that each separation we make can have the full range of values in it - the sounds could go from -1.0 to 1.0, and our images can go from 0 to 255. In the same way, the high frequency image data can be as much as 255 levels above or below the low frequency values (these also ranging 0-255). In effect, our high-frequency data has a range of 512; not just 256. To compress this down into a single layer, then, we have to sacrifice some level of precision in getting there - we need to compress 512 levels down into 256.

My preferred method of doing this is to 'scale down' the data - to map the darkest possible dark of the high frequency data to 0, and the lightest possible light of the high frequency data to 255 (128 still being neutral). This preserves all of the finest details in the image, but sacrifices a small amount of its 'smoothness' (numbers later).

The PS High Pass filter, on the other hand, seems to have been designed for creating lots of rough contrast, and so simply 'lops off' those light lights and the dark darks within the high-frequency data (much the way many of you may be familiar with a color channel 'clipping' when it's over or underexposed). This makes for a more contrasty layer (part of why some people like it so much), but it sacrifices a lot of fine detail in order to get there. To give you a side-by-side comparison of best-possible reconstruction using the default workflow, take a look at a closeup from Tino's uniform (the four stars represent the four MLS Cups which DC United has won):

Highpass comparisons

You can see quickly that the High Pass filter's version is far more contrasty right out of the box. Unfortunately, you'll also notice that its reconstruction (ironically) loses high-frequency contrast when blended back in to restore the original image. This isn't to say all is lost for the filter, though. Like adding and subtracting the frequencies from one another, contrast mapping is commutative - we can do things in a different order and still get the same result. In this case, we'll be able to use the HP filter so as to avoid having to mess with (what for many is a terrifying experience) the Apply Image tool. If we go to Image->Adjustments->Brightness / Contrast and choose to lower image contrast by (-50) with the Legacy option enabled, we can then use the included highpass filter to get that single-layer high-frequency data, while retaining all of that wonderful fine detail contrast.

Highpass comparisons

Notice how the results are identical - this is great, both for image quality (obviously) as well for automation implications which some of you are undoubtedly already thinking about.

For now, let's finally go through the step-by-step PS instructions.

To perform Highpass filtration into three layers:
  1. Make three copies of your image (two new copies if working on a single-layered document).
  2. Label the bottom layer "Low Frequency". Label the middle layer "High Frequency Light". Label the top layer "High Frequency Dark".
  3. Select the Low Frequency layer.
  4. Run the Gaussian Blur filter at your separation radius.
  5. Select the "High Frequency Light" layer. Set its blend mode to "Linear Dodge (Add)".
  6. Open the Image->Apply Image dialog box.
  7. In the Source box, select "Low Frequency" as the Layer, "RGB" as the Channel. Make sure the "Invert" box is unchecked.
  8. In the Blending box, choose "Subtract". Opacity should be 100%, Scale 1, Offset 0, Preserve Transparency and Mask.. should be unchecked.
  9. Click OK.
  10. Select the "High Frequency Dark" layer. Set its blend mode to "Linear Burn".
  11. Open the Image->Apply Image dialog box.
  12. In the Source box, select "Low Frequency" as the Layer, "RGB" as the Channel. Make sure the "Invert" box is checked.
  13. In the Blending box, choose "Linear Dodge (Add)". Opacity should be 100%, Scale 1, Offset 0, Preserve Transparency and Mask.. should be unchecked.
  14. Click OK.

This method works in all bit depths and results in a reconstruction with a mean error of 0 (StDev & median also 0). That is, it is mathematically (and technically) perfect.

To perform Highpass filtration into two layers using the Apply Image command:
  1. In 16bit mode:
    1. Make two copies of the current image (one copy if working on a single-layered document).
    2. Label the bottom layer "Low Frequency". Label the upper layer "High Frequency".
    3. Select the Low Frequency layer.
    4. Run the Gaussian Blur filter at your separation radius.
    5. Select the High Frequency layer. Set its blend mode to "Linear Light".
    6. Open the Image->Apply Image command.
    7. In the Source box, select "Low Frequency" as the Layer, "RGB" as the Channel. Make sure the "Invert" box is checked.
    8. In the Blending box, choose "Add". Opacity should be 100%, Scale 2, Offset 0, Preserve Transparency and Mask.. should be unchecked.
    9. Click OK.

  2. In 8bit mode:
    1. Make two copies of the current image (one copy if working on a single-layered document).
    2. Label the bottom layer "Low Frequency". Label the upper layer "High Frequency".
    3. Select the Low Frequency layer.
    4. Run the Gaussian Blur filter at your separation radius.
    5. Select the High Frequency layer. Set its blend mode to "Linear Light".
    6. Open the Image->Apply Image command.
    7. In the Source box, select "Low Frequency" as the Layer, "RGB" as the Channel. Make sure the "Invert" box is not checked.
    8. In the blending box, choose "Subtract". Opacity should be 100%, Scale 2, Offset 128. Preserve Transparency and Mask.. should be unchecked.
    9. Click OK.

These methods result in a reconstruction with a maximal error of 1 level difference in each channel (that is, a 1/256 maximum shift in 8bit; a 1/32769 shift in 16bit). The average shift is 0.49 with a StDev of 0.50 and Median 0. In less mathematical terms, it is functionally lossless in 16bit.

To perform Highpass filtration into two layers using the High Pass Filter:
  1. Make two copies of the current image (one copy if working on a single-layered document).
  2. Label the bottom layer "Low Frequency". Label the upper layer "High Frequency".
  3. Select the Low Frequency layer.
  4. Run the Gaussian Blur filter at your separation radius.
  5. Select the High Frequency layer. Set its blend mode to "Linear Light".
  6. Choose Image->Adjustments->Brightness Contrast.
  7. Check the "Legacy" option.
  8. Enter a value of -50 in the Contrast box. Leave Brightness at 0.
  9. Click OK.
  10. Run the High Pass filter at the same radius which you used in step (4).
This method works in all bit depths, and results in a reconstruction with a maximal error of 1 level difference in each channel (that is, a 1/256 maximum shift in 8bit; a 1/32769 shift in 16bit). The average shift is 0.54 with a StDev of 0.59 and Median 0. In less mathematical terms, it is functionally lossless in 16bit. In 8bit, it is just slightly (yet probably meaninglessly) inferior to the 8bit Apply Image technique.

To perform Bandpass filtration with a single layer:
  1. Make a single copy of your image.
  2. Label this layer "Bandpass".
  3. Choose Image->Adjustments->Brightness Contrast.
  4. Check the "Legacy" option.
  5. Enter a value of -50 in the Contrast box. Leave Brightness at 0.
  6. Click OK.
  7. Run the High Pass filter at the radius for the lowest frequency which you want to be visible (remember, highpass filters keep frequencies above a threshold value).
  8. Run the Gaussian Blur filter at the radius for the highest frequency which you want to be visible.
  9. The Bandpass layer is your bandpass'd result.
This method results in a bandpass which is within 1 level of an 'ideal' Gaussian separation in any bit depth. Again, functionally perfect in 16bit, and almost always close enough in 8bit. It will be rather low contrast by default (a necessary by-product of allowing fine detail retention) which you may want to augment with another B/C adjustment or with normal curves [16bit has a huge advantage here of course]. It is also worth remembering that high frequencies are low radii, and that low frequencies are high radii in the Photoshop context. This is a white lie which I'd hoped to only begin discussing that tomorrow, but as it's confusing a few folks today, we'll get it out there now. The discussion of why that is will still remain for later.

To perform Bandstop filtration with a single layer:
  1. Make a single copy of your image.
  2. Label this layer "Bandstop".
  3. Set the layer's blend mode to "Linear Light".
  4. Invert the layer (Image->Adjustments->Invert).
  5. Choose Image->Adjustments->Brightness Contrast.
  6. Check the "Legacy" option.
  7. Enter a value of -50 in the Contrast box. Leave Brightness at 0.
  8. Click OK.
  9. Run the High Pass filter at the radius for the lowest frequency which you want to block.
  10. Run the Gaussian Blur filter at the radius for the highest frequency which you want to block.
  11. The Bandstop layer is now acting as the bandstop for your image.
This method results in a bandstop which is within 1 level of an 'ideal' Gaussian separation in any bit depth. Again, functionally perfect in 16bit, and almost always close enough in 8bit.

...

Wow. We just covered an awful lot.

I'm going to stop here for today to give you time to digest what you're just read, to allow you time to ask more questions either directly or in the forums, so that you can point out what I'm sure are a plethora of typos in the above, and so that I can get to another soccer game :). We'll resume tomorrow with a discussion of what all of this can be used for in practice (including determination of separation radii!), discussion of advanced application (multiple-radius separation, etc.), and some examples of how you can automate many of these processes. Monday will still be the day when I answer as many questions as I receive, and when I will also reveal what white lies remain in this text.

Thank you for your patience, and thank you for reading.

And a second thanks to mistermonday for pointing out a gross and oft-overlooked typo in the bandstop instructions above - my apologies for the oversight!

No comments:

-