Adjust Depth of Field using Depth Map- Photoshop

In this tutorial I am going to explain to dynamically control depth of field using Depth Map. Also at the end of this tutorial I will explore a cool Facebook trick.

Links for keyshot file, images are available at end of this tutorial.

  1. Step 1: What is Depth Map

    Depth Map is a monochromatic picture that tells the position of the image. They are often represented by black and white transitions.

    Far pixels away from camera is shown in Black and near pixels is represented in White. An example of Depth Map is shown as,

    Here the background is black meaning to be far and white pixels meaning near to camera.

    Also one can generate using photo editing softwares like Photoshop etc.,.

    The value of color may change from software to software but the concept remains constant

  2. Step 2: Automatically Generate Depth Map

    If you are using Keyshot then you can create depth map very easily. The depth maps are automatically generated while rendering.

    The way of generating goes like:

    -Keyshot and adjust material, light, and camera as per requirements.

    -Now press Render or Ctrl+P to open render dialog box and choose Depth from Render Passes

    -Then hit render and wait while till it renders. Rendered image and depth map are below:

    Depth Map will have extension .exr which can be opened in photoshop.

  3. Step 3: Depth of Field in Photoshop

    Open the rendered image in Photoshop

    Now open .exr file in new tab as transparency

    This is how you see depth map but needs to be modified:

    Go to Image > Adjustments > HDR Toning > Press Yes > Change the method to Equalize Histogram

    No matter how the color is chosen for far and near objects.

    Copy the image by pressing Ctrl+A, Ctrl+C. Move to rendered image, move to channels tab. Create new alpha and to paste in place press Ctrl+Shift+V.

    Again move to Layers Tab, choose the image (click on lock button to unlock) and go to Filters > Blur > Lens Blur.

    Make sure from Depth Map your depth map (default name: Alpha) is selected. Play with radius of blur.

    With the desired radius of blur, click on image to get in focus. Sample images are:

    < Focus on last glass>

    <Focus on front glass>

    <Focus on middle glass>

    With the help of depth map depth of field can be controlled so preciously.

  4. Step 4: Bonus- Post 3D Image in Facebook

    Save the render file with a name say Glass.jpg

    According to facebook, to create 3D image near pixels must be white and far pixels in black, but in our case it's opposite. To invert image press Ctrl+I

    Hide Rendered Image and save as jpg with Glass_depth.jpg (General format is <file name>_depth.jpg). This step is important. Save renedered image if any adjustments were done as glass.jpg

    Open Facebook and create a post. Click on Upload photo and choose both file. Wait and Facebook converts 2D to 3D photo automatically.

    Hurray, you got 3D photo. Enjoy. Feel Free to ask question regarding this tutorial.

  5. Step 5: Links for Files


    - Keyshot File: Here

    -Image: Here

    -Depth Map: Here

    -3D Model: Here

    -Facebook Post: Here