We are reader supported. External links may earn us a commission.


How to fix your phone’s shitty portrait mode (as explained by a professional photographer)

By Adam Z. Lein July 24, 2019, 8:00 am

Ever since Apple introduced their depth map generated fake background blur filter known as Portrait mode, practically all other phone makes have also added that feature.  In all cases it’s terrible at making your photos look good because the filters never get the edge details right.  They’re always either over masked or under masked and it always looks like a it was made by a high school Photoshop student who only took the class because they thought it was an easy A and didn’t really care about quality.  I had always wished that I could get that actual depth map out of these phone cameras and fix it up in Photoshop in order to make an actually good image.

Here’s what the image from the phone looks like.

In this tutorial, we’re going to look at a technique for fixing the depth map generated by a Nokia 9 Pureview phone using Adobe Photoshop. You can probably translate these techniques to other phone cameras and photo editing programs like GIMP, Krita, Affinity Photo, etc.

Extract the depth map

The logical method of saving the depth map with the photo would have been to include it either as an Alpha channel or as a separate file. In the early days of video compositing with transparency masks, that’s what we always did.  That’s not how any of these cameras work though.  Instead we have to use a special tool to extract the depth map.

There’s a free web-based tool at https://www.omnivirt.com/3d-photo/ which will do it. Now, the depth map information is usually saved within the JPG on many Android devices… not the DNG file like one would hope.

We’re going to use a photo from the Nokia 9 Pureview since its 5 cameras should give us a pretty good starting point for the depth map.

First, upload your photo to the Omnivirt 3D photo creator tool.

Then download the ZIP file and extract it to a folder.

The file called “image_depth.jpg” is the one that includes the extracted depth map. It will look something like the above.  The lighter shades of grey indicate pixels that are closer to the camera while the darker shades specify pixel areas that are further away. And as you can see… this depth map is an awful mess.

Bring everything into Photoshop

Now, instead of applying that depth map to the phone-processed JPG, I’m going to open the RAW DNG file in Photoshop.  Yes, the Nokia 9 Pureview RAW files are also already hardware-processed to merge the 5 camera photos into one, but it’s still better than using the JPG and we’ll be able to make a much more flexible non-destructive layered image file. The Nokia 9 Pureview is able to save both a processed JPG along with the RAW DNG file, so that feature helps a lot here as well. Don’t forget to hold down “Shift” in the Adobe Camera Raw dialog in order to open the DNG file as a Smart Object.

Next I’m going to create a new Alpha channel in that DNG file and Copy/Paste the image_depth.jpg into that Alpha channel. Then we should probably do File > Save As > and make a new PSD file to preserve everything.

Next I’m going to make a copy of the image layer by dragging it to the new layer icon in the Layers palette, then I’ll load that Alpha channel as a selection by Ctrl + clicking on it. Then select the image layer copy and choose Layer > Layer Mask > Reveal selection to create a layer mask.  This top layer will be our in-focus layer.

Next, Alt/Opt click on the layer mask that we just created in the Layers palette. This will let you see the greyscale levels of the layer mask.  The white areas are the things closest to the camera while the black areas are the furthest away.  I’m going to use this to make my subject remain sharp and unmodified while letting the far away areas be blurred by a filter.  Now, you’ll notice that my model’s face is 87% black in this depth map.  That’s way too much!

So I’m going to hit Ctrl + M and use the white eye dropper to click on her forehead in order to make the model’s mask area white and therefore opaque. You can see this causes a lot of banding between the depth levels because our depth map does not have much range or resolution.

Now I’m going to apply a Gaussian Blur filter to the bottom image layer and we’ve got almost the same thing that the phone’s background blur filter would have done.  It’s a terrible mess!!

Now you can control it

All of that work to get something that looks just as bad as what the camera phone did automatically may seem like a wast of time, but NOW we have that Photoshop file set up so that we can actually control things with a lot more flexibility.  So next you’ll want to get your painting tools ready because we’re going to fix that depth map manually.

This is where you need a bit of skill and you’ll probably need to change your technique depending on what kind of image you’re working with.  Basically, you need to use painting tools with varying levels of black, white, and grey to edit the layer mask until it looks right. There are tons of different techniques you could use here as well. You can use a pressure sensitive pen to simply paint away the ugly areas, or you can use some of the color channels from the original image to create selections or sub-masks and use those to paint away the ugly areas… the possibilities are endless. It’s difficult to tell you exactly what to do here since there are so many options.

For this image, I mainly used the pressure-sensitive pen method.  Use the [ ] bracket keys to change the brush’s diameter as you go.  Use the X key to switch between black and white paint colors as you modify the mask.  Use the number keys to quickly change the flow of an airbrush or opacity of a paintbrush.

How much effort you put into fixing the depth map mask again depends on you and what kind of image you’re using.  Above is what I ended up with.  It’s not perfect, but it should do fine. Note that I added a gradient blend on the floor area so that the ground level closest to the model would evenly stay sharp. A lot of depth maps generated in phone cameras don’t get that right.

Using the good depth map

The above technique for using a sharp masked copy of the image on top of a blurred copy of the image was mainly meant for editing the mask in order to get a decent depth map.  That technique isn’t quite right for the final image because the transparency masking on top blends with the blurred image on the bottom and blurred edges bleed out around the sides.  Really, we want to use the new depth map to apply a Lens blur gradually in different areas.

Copy the grey-scale final layer mask into a new Alpha channel.  You can do this by loading it as a selection and then making a new Alpha channel from the selection.  Mine is called “Alpha 4”.

Adobe Photoshop

What I did next was create a copy of the original DNG Smart object layer, then right click it and choose “Rasterize”.  This removes the non-destructive properties for that layer and this is necessary for the “Lens blur” filter to work.  Next, I chose Filter > Blur > Lens blur which brings up the above filter dialog.  The important part here is that you choose your final edited depth map alpha channel in the Depth Map > “Source” drop down menu.  It may be that the filter applies to the subject instead of the background if you used whites to reveal the subject in your alpha channel.  If this is the case, click the “invert” checkbox in the Lens Blur filter to apply the filter to the opposite areas.  Adjust the other sliders, especially the “radius” one, as you see fit and click OK to apply.

That’s it!  Now you have a much better fake background blur filter!

Here’s what the final image looks like.


Guest appearance by Dasha Mudrova.


Latest Articles


How to skip CAPTCHAs with iOS 16?

In this article, we will explore how Apple aims to avoid CAPTCHAs and the settings you must have configured on your iPhone to ensure you're ready to breeze past any puzzles.

By Aryan Suren June 26, 2022, 4:00 pm

iPad Pro 2022: Everything we know so far!

It is expected that before the end of 2022, we may have the chance to see the next generation of iPad Pro, and in this article, we've compiled all the information that's currently available about these upcoming tablets.

By Aryan Suren June 26, 2022, 10:30 am