O'Reilly    
 Published on O'Reilly (http://oreilly.com/)
 See this if you're having trouble printing code examples


Content-Aware Scaling: Adobe Photoshop CS4 One-on-One

by Deke McClelland

This excerpt is from Adobe Photoshop CS4 One-on-One. How can you master the fundamentals of Photoshop CS4, with all of its incredible features? Deke McClelland's proven One-on-One learning system offers step-by-step tutorials, five hours of DVD-video demonstrations, and hands-on projects to improve your knowledge and hone your skills. Read about features such as Photoshop's new Adjustments panels in the book, and see how they're used first-hand in the video. The combination is uniquely effective.

buy button

Photoshop CS4 introduces a handful of "advanced compositing" features that apply a high degree of automation to the task of merging, blending, and transforming images. Far and away the sexiest and most practical of these is the new Content-Aware Scale command, which transforms areas of low contrast while protecting areas of high contrast. The upshot is that, in many cases, you can scale an image's background while leaving the foreground unharmed.

Content-aware scaling does not require elaborate multilayered compositions, nor does it work on multiple layers at a time. In fact, its only relationship to layers is that it happens to work best when applied to a image that you've first isolated to an independent layer. Here's how the command works, best approach and all.

missing image file

Example file: Jumper.jpg

  1. Open an image that you want to scale. Go to the Lesson 09 folder inside Lesson Files-PsCS4 1on1 and open the file called Jumper.jpg. Captured by Andrzej Burak of iStockphoto, this image features clearly distinguishable, high-contrast foreground objects--the leaping woman and the foreground grass--set against medium-contrast clouds and a low-contrast sky. Which makes it a perfect test project for content-aware scaling. Note that this is a small file, little more than a single megapixel, which means less work for Photoshop. (Larger images take more time to process and may overwhelm the command.) But the final result may look a bit stretched out of shape.
  2. Convert the image to a floating layer. Like any transformation function, the Content-Aware Scale command needs a selection or an independent layer to work. Give it the latter by double-clicking the Background item in the Layers palette. In the New Layer dialog box, name the layer "Jumper" and click OK.
  3. Add some height to the canvas. Let's be ambitious and convert the image from horizontal to vertical. We'll start by making the canvas square, which will give us more headroom. Choose ImageCanvas Size. Turn off the Relative check box, set the Height value to 1440 pixels (to match Width), and select the bottom Anchor option, as in Figure 9-64. Then click OK to add a healthy amount of empty space to the top of the image.
    PhCS4 1on1 fig09-64.tif

    Figure 9-64.

    missing image file

    Figure 9-63.

  4. Choose the new Content-Aware Scale command. Choose EditContent-Aware Scale, which is featured in Figure 9-65. If you did not load my dekeKeys shortcuts, you can invoke the command with Ctrl+Shift+Alt+C (-Shift-Option-C). Otherwise, I reassigned that shortcut to the more frequently used ImageCrop. In any event, Photoshop surrounds the image with eight scale handles, just as if you were working in the free transform mode.
  5. Scale the image as tall as it will go. Go ahead and scale the image window to give yourself some extra gray pasteboard so you have enough room to work. Then drag the top handle all the way to the top of the canvas. If you drag slowly, you'll see that Photoshop focuses most of its efforts on the background sky. But after a point, it can't help but engage the leaping woman to a lesser extent. Lesser or not, the command still manages to make an absolute mess of things, as witnessed in Figure 9-65.
    PhCS4 1on1 fig09-65.tif

    Figure 9-65.

  6. Protect the skin tones. Go up to the options bar and click the little icon. That little dude protects the skin tones by ruling all warms colors out of the scaling equation. That completely eliminates the stretching in the woman's skin, shirt, and brilliantly scarlet hair. But it leaves her white slacks scaled more disproportionately than ever, producing the tragic MC Hammer pants pictured in Figure 9-66.
    PhCS4 1on1 fig09-66.tif

    Figure 9-66.

  7. Make the image shorter and skinnier. Drag the top handle down until the thighs return to their original dimensions, which I found to be about midway between the fully stretched image and the original one. Then drag the left handle to the right as far as you can without reducing the length of the woman's arms or legs. Once the image looks more or less like the one in Figure 9-67, press Enter or Return to apply your edits.
    PhCS4 1on1 fig09-67.tif

    Figure 9-67.

  8. Choose Content-Aware Scaling again. Like all transformations, content-aware scaling rewrites pixels, so by definition it's a destructive modification. Were it a typical transformation, that would mean you shouldn't apply it multiple times in a row. But content-aware scaling actually produces better effects if you apply it in multiple passes. So choose EditContent-Aware Scale to do just that.
  9. Scale the image as desired. Make the image the full height of the canvas and skinnier still. Assuming that the icon remains on, you'll find it difficult to harm the woman. When you're finished, press Enter or Return to apply the change.
    missing image file

    further investigation

    For more details about this and other advanced compositing features, see my three-part video series, Photoshop CS4 One-on-One. Remarkable as it may sound, I devote Chapter 28 to content-aware scaling. To review it, go to www.lynda.com/dekeps and start up your 7-Day Free Trial Account. (I know, I just mentioned that URL a few pages ago, which makes me wonder: Why are you reading this text instead of checking out lynda.com?)

Figure 9-68 compares the content-aware scaling to an identical nonproportional stretch applied via the Free Transform command. The differences are so obvious as to render any description I might offer altogether redundant.

PhCS4 1on1 fig09-68a.tif

Figure 9-68. Content-aware scaling

PhCS4 1on1 fig09-68b.tif

The same dimensions achieved using Free Transform


If you enjoyed this excerpt, buy a copy of Adobe Photoshop CS4 One-on-One

Copyright © 2009 O'Reilly Media, Inc.