Portrait Background Blur
Operator: Abdulla Al Fahad. How tools are built and checked
A portrait taken against a kitchen shelf or an open-plan office shows everything behind the face as sharply as the face. A wide-open 85 mm lens would have melted that background into soft color, and a phone's portrait mode imitates the same thing with a depth map. This page does the imitation on a photo you already have: a neural network outlines the person, and only what lies outside the outline is blurred.
Two details decide whether the result looks believable. Color from the subject must not bleed into the blurred area, which is what puts a bright halo around hair in quick edits, and the blur should grow with distance from the subject instead of lying over the background as one flat layer of fog. Both are handled in the render step described below.
If you want the background gone rather than softened, the AI Background Remover on this site runs the same model and cuts it out.
Key features
- Automatic subject outline from a portrait matting model, with no brush or selection work
- Depth falloff, where the blur grows with distance from the subject, or an even blur of the whole background
- Blur computed from background pixels only, so subject color cannot bleed into the backdrop
- Grading that touches only the background: remove color, brighten or darken, add a color wash
- Edge position and feather controls, and a before-and-after slider on the result
Subject matte, depth falloff and clean edges
Open a PNG, JPG, WEBP, GIF (first frame) or BMP, or paste one with Ctrl+V. The photo is worked on at up to 2048 pixels on its longest side. A larger photo is scaled down first, with a note about it, and the saved file has the working dimensions, as a JPG at quality 0.93 or as a PNG, so a 4032 x 3024 phone photo is saved at 2048 x 1536.
Blur amount runs from 0 to 100 percent, where 100 percent is a radius of 3 percent of the longest side. In depth mode, Distance to full blur (2 to 80 percent of the longest side) sets how far from the subject the blur reaches that radius. Remove color goes from 0 to 100 percent, brightness from -60 to +60, and the color wash up to 80 percent. Edge position moves the matte cut-off by up to 30 points either way, and feather runs from 0 to 20.
The first run fetches the matting model, about 26 MB, from huggingface.co; the ONNX runtime's WebAssembly helper is served from this site. The browser caches both, so later photos start straight away. Your photo is not part of either request.
How it works
The subject finder is MODNet, a portrait matting network, in the ONNX conversion published as Xenova/modnet under the Apache-2.0 license. Matting differs from a plain cut-out mask: instead of a yes or no for each pixel it returns an opacity from 0 to 1, which is what lets hair and soft clothing edges keep partial transparency. The same model drives the AI Background Remover, the WhatsApp sticker maker and the text-behind-image tool on this site, so those pages only describe what they add on top.
Before the model sees the photo, the photo is shrunk so its shortest side is about 512 pixels and its longest at most 1024, with both sides rounded to a multiple of 32. A 2048 x 1536 photo goes in as 672 x 512. The colors are scaled to the range -1 to 1, the network answers with one plane of opacity values, and that plane is stretched back up to the photo's size. It runs on the graphics chip through WebGPU when the browser has it and on the processor through WebAssembly otherwise, and a WebGPU failure is retried once on the processor before an error is shown.
Because the matte comes from a 672 x 512 image, it is soft at pixel level: single strands of hair are estimated, not traced. Edge position then re-centers the matte's ramp and sharpens it with a gain of 1.6, and feather blurs it with three box passes in each direction, with a radius of feather x longest side / 2000 pixels, so feather 2 on a 2048 px photo is a 2 px radius. Both steps run after the model, so moving a slider does not run it again.
The blur is a weighted average. Each pixel's weight is how little of the subject it holds, the weighted colors and the weights are blurred together, and the colors are divided by the blurred weights afterwards. Subject pixels contribute nothing, so no halo forms. In depth mode a two-pass chamfer transform measures every pixel's distance to the nearest subject pixel, a smooth S-curve turns that distance into a value from 0 to 1, and the value picks between six pre-blurred levels, blending neighboring levels so the radius changes smoothly.
Common use cases
- A 4032 x 3024 phone headshot taken against a kitchen shelf. It is saved at 2048 x 1536, and amount 55 with a 25 percent distance keeps the face and shoulders sharp while the shelf turns to soft color.
- A 1600 x 1067 product shot on a cluttered desk. Even blur at amount 35 gives a radius of about 17 px (35% x 3% x 1600), enough to erase the pen holders without smearing the product's edge.
- A 1080 x 1350 social portrait with a bright window behind the sitter. Brightness -25 and Remove color 40 percent act on the background only, darkening the window without dimming the face.
How to use this tool
- Drop a portrait, or paste one. On the first run, wait for the 26 MB model; the progress bar shows megabytes received.
- Choose Depth falloff or Even blur and set the amount, then drag the slider to compare with the original.
- Look at the hair and shoulders. Move Edge position and Feather until the border between sharp and blurred looks natural.
- Optionally dim or desaturate the background, pick JPG or PNG, and download.
Example
A 2048 x 1536 photo, depth falloff, amount 55, distance to full blur 25
maximum radius 55% x 3% x 2048 = 33.8 px
six levels 0, 7, 14, 20, 27 and 34 px
full blur at 25% x 2048 = 512 px from the subjectBlur radius at a distance from a straight subject edge (measured on a test matte)
32 px away about 0.4 px
128 px away about 5.5 px
256 px away about 17 px
384 px away about 29 px
512 px or more 34 pxTips for best results
- Set the distance to full blur from the subject's size. A person filling a third of the frame looks natural at the default 25 percent, while 8 percent makes the blur reach full strength within about 160 px of a 2048 px photo and tends to read as a cut-out pasted on a blurred card.
- Use Edge position to fix hair. On a pixel the model scores 160 out of 255, an edge of -20 makes it fully subject (255) and +20 pulls it down to 98, so negative values rescue strands that are being blurred and positive values trim a pale halo of old background.
- Choose Even blur when a plain wall sits behind the subject. Depth falloff on a flat wall only draws a gradient where there is nothing to see.
Common pitfalls
The model finds one dominant subject. In group shots or scenes with several unrelated objects it may keep some and drop others, so check the whole frame against the original.
Flyaway hair, glass and smoke are hard cases for any matting model, and the matte is computed at about 512 pixels on its short side. Check those areas at full size before saving.
This is a simulation of lens blur. Real optical blur depends on distance and aperture, so bright points and reflections do not turn into round highlights.
Photos over 2048 pixels are saved at 2048 pixels on the long side, not at their original size.
Common errors and how to fix them
- The model files could not be downloaded
- The model comes from huggingface.co. Check the connection, turn off a blocker that stops that host, and press Try again.
- Finding the subject failed
- Close other heavy tabs or try a smaller picture. Reloading clears a stuck graphics backend, and the page then falls back to the processor.
What the blur amount means in pixels
Blur amount is a share of the longest side, so the same setting gives a larger radius on a larger photo. These are the maximum radii the formula gives, reached only at the full distance in depth mode and everywhere on the background in even mode:
- Amount 25: 7.7 px on a 1024 px photo, 15.4 px on a 2048 px photo
- Amount 55 (the default): 16.9 px and 33.8 px
- Amount 100: 30.7 px and 61.4 px
Frequently asked questions
Why is the first photo slow?
The first run downloads a model of about 26 MB and sets up WebGPU or WebAssembly. After that the model comes from the browser cache and only the processing time remains.
What is the difference between even and depth blur?
Even blur uses one radius for the whole background. Depth blur starts sharp at the subject's edge and reaches full strength at the distance you set, which is closer to how a real lens falls out of focus.