Take your photography to the next level and beyond...

  • NEWS
  • REVIEWS
  • INSPIRATION
  • COMMUNITY
  • COMPETITIONS

Why not join for free today?

Join for Free

Your total photography experience starts here


Using PhotoShop's Lens Blur filter to create depth of field

Using PhotoShop's Lens Blur filter to create depth of field - The effect of blurring the non-critical parts of an image helps separate the main subject from the rest of the foreground and background that might otherwise be found as distracting. Anthony Moringello shows us how to digitally create depth-of-field.

 Add Comment

Category : Other Software
Share :

lens blurIn these two images the first is a shot taken with a 50mm lens at f/1.4 so depth-of-field is minimal. Your eyes are easily lead to the main subject - the bottles of oil and vinegar.
The second image is the same set-up but with an aperture of f/22 ensuring maximum depth-of-field. Your eye tends to be drawn to the detail in the front handle of serving tray, the back handle, and even back to the leaves seen through the window. It would be nice to keep the person's interest on the main subject.

If the first image is so much better, why use would you ever bother using settings on the camera which would not give you the results you want? Well there may be several reasons. One could be that you captured a a once in a lifetime event, but your camera was set to less than optimal settings.

Another reason could simply be that the lens you are using does not have the capability to give the effect you are looking for.

Many zoom lenses, for example, do not have the ability to open up far enough to give the depth of field you might want achieve. Or perhaps you decided at some later time that a stronger DOF would be best for your image.

So, it is here that we turn to post processing the image to give it the look we desire.

The most obvious tool of choice for most applications of a blur effect is the Gaussian blur filter. Most all photo processing tools have some form of tool for adding Gaussian blur to your image. This gives a nice soft blurred effect useable in most cases. But we'll take a look at Adobe Photoshop's Lens Blur filter and see how it stacks up to the original photo and to Gaussian blur. Although not new, Adobe Photoshop included Lens Blur with CS2, I think many have probably never given it a try. Here is your chance. ;-)

An important thing to note before we start is that the blur that results from a good DOF is gradual. The blurring gets stronger as the distance from the focal plane increases. So to get a realistic final image you cannot simply apply a blur and cut out the part you want to be sharp. Your image would simply look that way... as if you cookie cut the subject from a smoothly blurred background. i.e. yuck!

We will address this important idea as well.

OK, so to recap, we're going to assume that we have an image that suffers from a large DOF and try to bring that down to a more narrow DOF so that the main subject will stand out from the foreground and background.

I will state up front that several techniques are used in the process outlined below. Although I believe I give enough information to get through the process, to explain in full detail how to perform every action would be unwieldy and detract from the point of this tutorial. If you have questions how to perform certain actions I would highly encourage you to look up the relevant procedures in the vast library of techniques found on this site.

In short we're going to:

  • Compare DOF from various methods.
  • Apply gaussian blur to a copy of the original image.
  • Apply Lens blur to another copy of the original image.
  • Compare the two and see how they differ and hopefully find a reasonable method of emulating a lens blur effect.


Step 1 Create a mask of the bottles
We want the full bottle to be in focus, so we're going to create a mask that we'll use later to cut a hole in our blur effect.

lens blurDuplicate the layer, add a layer mask, and fill in the area over the bottles in black.
Creating a mask can be accomplished in many ways. You may wish to use the Pen tool, but I found that Adobe Photoshop CS3's new "Quick Selection" tool allowed me to get most of the shape in about five seconds. Just amazing!
In the end, we get the following mask.


Step 2 Save the mask for later use.
From the Selection menu, choose to Save Selection... Save it to a new channel.

lens blur

lens blurlens blurStep 3 Prepare the blur mask
Remember that blurring due to DOF is a gradual change from sharp to unsharp. So we need to create a gradient mask that will generate that effect. Select the gradient tool, and choose the gradient that flows from black to white. Use normal drawing mode. (This is usually the default)

 

lens blurStep 4 From a point considered the focal plane, (the area in focus)
Generate the first half of the gradient (keeping in mind that the blur increases in front and behind the focal plane).

After selecting the gradient tool, draw a line from the bottom of the bottle's label to about half way through the serving tray's handle.


This will create a smooth gradient where everything prior to the starting point is black, and everything after your stopping point is white. This section will be used to define which area will contain blur. Remember when using masks that black blocks the effect, white allows the effect.
We now have this.

lens blur

Those who are keeping up so far will realize that this means only a small sliver of the image in front of the bottles will be blurred. You are correct!
Now we need to send the blur in the opposite direction as well.

Step 5 Create the top half of the gradient.
Those trying to go ahead of us, may find that the gradient tool will fill in the whole image area and you cannot simply create the top half of the gradient. If you try this, you simply wipe out the prior gradient. This can be frustrating and non-intuitive, even thought it really makes a lot of sense once you get used to it.

lens blurlens blurSo, to add to the gradient mask we'll again use the gradient tool, but this time make sure you set the Blending Mode to "Screen"!


What does Screen do? Well, essentially it says that anything in black will not affect the image. Well, great, but what does that mean to us? Watch....
We'll next draw our gradient again starting from the bottle label, but this time we'll draw upwards to some point above the top of the serving tray handle.
Again, due to screen mode, anything drawn in black (our starting point and below) will not affect our image. Only the white is ADDED to our existing mask. Pretty neat trick, I think!
lens blur
You now have this mask

lens blurIf you take a look at the rubylith (use the '\' key to turn this on and off) you'll see red where the mask exists.
If the red does not cover the right areas, clear the whole mask and start again. Trying to adjust the bottom or top using screen mode will not have the additive effect you might expect.

Notice how the mask transitions smoothly from the bottom of the bottle in both directions (forwards and backwards from the central focal plane). DOF extends for some distance around the plane of focus. Generally, the area considered to be in focus extends about 1/3 of its distance in front of the focal plane and about 2/3 of its distance behind. You can look up all sorts of information about this if you want to learn more, but try to keep that in mind when creating masks for DOF.

Step 6 Add the bottle to the mask
Now we have a nice area defining our DOF. If you were to apply the blur now, you would end up with something like the following.

lens blur

Wait a minute! That is certainly not going to convince any one that the bottles are separate from the background! We need to cut a hole in the blur so that the bottles stay in focus.

Go to the Channels pallet and find the mask that you saved earlier. It should be at or near the bottom.
You're simply going to CTRL-Click on this mask. Doing so actually selects the area defined by the mask.
Now go back to the Layers pallet and select the gradient mask. Be sure to select the mask and not the actual image of the bottles.

Set the background drawing color to black. With the gradient mask selected, and the selection obtained from the bottle's mask in the channel pallet, we will press CTRL-Backspace. This results in the selection area being filled with the background color. In this case, black.
What have we done? We've added the bottle mask to our gradient mask. We have now defined all the areas that need to be blurred and those that need to be in focus.
The resulting mask looks like this

lens blur

Step 7 Now the fun... blur the thing, already.

Step 8 Gausian blur

First lets make a copy of our original image with its mask. Right click on the layer in the layers pallet and choose to Duplicate Layer. Name the new layer "gaussian blur".

Now simply select the image (careful not to select the mask by mistake).
You need to do something special before we continue. If you simply choose to blur now, everything in the image will be blurred. So what? you may ask. Well, the transparency mask of the bottles will blur into the background and you will get a bright halo around the bottles that is not as blurred as it should be.
lens blurSo we first need to Lock Transparency. (click the little checkerboard icon at the top of the layers pallet.

Now choose Filter>Blur>Gaussian Blur... from the menus. I used a blur of about 43 pixels. Obviously your mileage will vary on the effect you are trying to achieve.

Step 9 Lens blur
Finally, we get to the whole point of this exercise. Lens blur is a much more sophisticated blurring tool. For example, it takes into account the number blades in the lens to affect bokeh and specular highlights. These are things that one cannot emulate directly with Guassian blur. Lets see what happens.

Again, select your original image with its mask and Duplicate the layer. Name this one "Lens Blur".
Note that we will not be locking the transparency for this layer.
Choose Filter>Blur>Lens Blur... form the menus.
This opens a rather large dialog box to work in. First thing, make sure you have the button at the top labeled "Faster" selected. More Accurate is just that, but certain functions cause the response to plummet to an unusable pace. I recommend using the More Accurate setting only if necessary.

Generally the lens blur will blur the entire image just like Gaussian blur and most other filters. But as we have seen, our mask, helps to diminished the effect via our gradient to give a smooth transition and totally eliminate the blur on the bottles themselves.

But, lens blur takes this a step further and allows you to use your layer mask to actually affect exactly to what degree the lens blur emulation occurs. In other words, the bokeh and specular highlights are rendered based upon the distance from the central focal plane. This focal plane is defined by the gradients in your layer mask. Black has no effect (totally in focus), white is full effect (totally our of focus).
In order for this to occur, you need to set the Depth Map Source to use "Layer Mask".
The Blur Focal Distance slider will adjust the focal plane to a location between black and white. Useful if your gradient was misplaced or needs slight adjustment. Play with it and see how this works.
It does not work too well with our bi-directional gradient, but I'm sure you'll see how this may be useful in some cases with a consistent single direction gradient mask.
In fact you may want to experiment using only a single gradient and using this shifting of the Blur Focal distance instead. The effect is still quite nice. Although, I find that I have better control of exactly what is and is not in focus using the method outlined here.

My lens has 8 blades, so I set the Iris Shape to "Octagon (8)".
The Radius is basically the blur amount. I set his to 100% to try as best as I could to match the blur form a f/1.4 aperture. The tool doesn't quite get there with 100%, but not too bad. I left Blade Curvature and Rotation as-is.

Specular Highlights will cause those balls of light to appear over highlights. Your iris shape will affect the appearance of these shapes just as they would form the lens on your camera. Slight adjustments of these settings can make a huge difference.
I used settings of Brightness set to 2 and Threshold set to 180.
Note: turning this on by setting Brightness above 0 and Threshold below 255 will cause the feature to turn on and slow down the rendering significantly! If your image has a lot of highlights or areas that are virtually white, the processing time increases even more.
I found this out the hard way by accidentally performing the Lens Blur on the mask instead of the image. Being almost all white, the specular highlight rendering added 30 minutes to the execution time!!!

Anyway, now click OK. Rendering may take about two minutes on a reasonably fast machine (dual core 2600MHz with 4G RAM).


Step 10 Lets check out the results....

lens blur
lens blur
On the left - Gaussian blur. On the right, Lens blur.


There are some significant differences. First, remember when we locked the transparency when performing the Gaussian blur? Well, although this avoided the transparency from blending in, it allowed the bottles themselves to blur. So we end up with a dark halo now. This could probably been avoided by cutting out the area defined by the bottles before locking the transparency and blurring. I am not sure and haven't tried that yet, perhaps you can try that on your own.
I guess the point is that it seems that you do not have to worry about such things with the Lens blur filter.

The edges are seen up close below

lens blurlens blur

Another significant difference is the quality of the blur itself.
Gaussian gives a good consistent blur throughout. What you end up with is more of the look you might get through a heavy fog.
Lens blur on the other hand tries to better emulate the look that an actual lens might produce.
Notice the three versions below.

lens blur

Left - Original from 50mm f/1.4 lens,
Middle - 50mm f/22 run through Lens blur
Right - 50mm f/22 run through Gaussian blur

lens blur

Here again are all three versions (original, Lens blur and Gaussian blur).
I would not say that Lens blur is the be-all, end-all to processing a blur effect, but it gives a pretty good result. Once you play with the workflow a bit, I think Lens blur actually ends up being a decent alternative.

Conclusion
As you'll notice the specular highlights in the Lens blur image resulted in horribly blown highlights in the background. Gaussian blur is also guilty, but not quite so much.
Looking at the full sized images, one may find that the background generally looks more pleasing and realistic using Lens blur compared to Gaussian blur. Gaussian blur in my opinion, tends to make the image appear more as if it is sitting in a heavy fog.
Due to the distance based rendering and the specular highlights, the Lens blur gives some nicer blur effects on fields, grass and other detailed/textured background that I cannot get with Gaussian blur.

Well, hopefully that gives you a taste of what this filter can do. Maybe next time instead of pulling out the Gaussian blur filter, you may give the Lens blur a try.

About the Author
Anthony Moringello has been interested in photography on and off for 30+ years but only started taking it seriously over the past few years. He tends to specialize in pet photography but enjoys taking photos of all types. Photography gives Anthony a great escape allowing him to relax from full time job in the software industry. Anthony's web site

Would you like to write an article for ePHOTOzine? Pease feel free to get in touch via the suggestions link at the base of this page

Explore More

Join ePHOTOzine and remove these ads.

There are no comments here! Be the first!


Sign In

You must be a member to leave a comment.

ePHOTOzine, the web's friendliest photography community.

Join For Free

Upload photos, chat with photographers, win prizes and much more.