Depth Map Blur (UTK)
Fake shallow depth of field with a depth map and a blur
- image
- depth_map
- IMAGE
- MASK
A portrait with everything in focus reads as flat; a real shallow depth-of-field shot reads as "camera." You don't need to re-render to fake it. Depth Map Blur (UTK) takes an image and its depth map and blurs regions by how far they are from your focal plane - a lens-simulation effect, pure image processing, no generation pass. It's the thing to reach for when you want a bokeh-ish look on an already-generated image or a photo.
How it works
You give it an image and a depth_map (a grayscale image where near = bright, far = dark - any depth-estimation model's output works; the KB's depth-estimation docs cover getting one). Then four numbers control the "lens":
- blur_strength (default 64) - the overall blur intensity. The higher, the mushier the background.
- focal_depth (default 1.0, range 0–1) - which depth level stays sharp. This is your focus plane: 1.0 is "farthest," 0.0 is "nearest." The author's own description says it directly: this determines which depth level remains sharp.
- focus_spread (default 1) - how wide the transition band around the focal plane is. Wider = smoother, more gradual blur falloff.
- focal_range (default 0) - how much of the region around the focal depth stays sharp. Raise it to keep a wider band in focus.
- steps (default 5) - the number of blur layers / calculation precision. More steps = finer result, slower.
- mask_blur (default 1) - blurs the depth map itself as preprocessing, softening the mask edges so the transition looks natural instead of banded.
So the mental model: pick where the camera focuses (focal_depth), decide how abruptly focus falls off (focus_spread), and how strong the blur is (blur_strength).
Outputs
Two: an IMAGE (the blurred result) and a MASK (the focus/defocus regions it computed - useful if you want to inspect or composite with it).
Installing it
Standard pack install - ComfyUI Manager → search ComfyUI-UniversalToolkit, or:
cd ComfyUI/custom_nodes
git clone https://github.com/whmc76/ComfyUI-UniversalToolkit
cd ComfyUI-UniversalToolkit && pip install -r requirements.txt
Then restart. Needs OpenCV (cv2) for the blur work - in the pack's requirements.
Gotchas
- Focal plane 0–1 is the thing people misread first. A depth map normalized 0–1 where 0 is near and 1 is far means focal_depth 0.5 focuses mid-scene. If your background comes out sharp and your subject blurred, you've got the mapping backwards - flip the depth map or the focal depth.
- No depth map = no blur at all. This node does not estimate depth; it only consumes it. You need a depth estimator upstream (Depth Anything or similar), and the quality of the effect is capped by the quality of that map.
- banding around the focal plane - if you see hard-edged blur steps, raise mask_blur (softens the depth map) or steps. Usually the easiest fix for the telltale "layered" look.
- Everything sharp vs. subtle is one dial - strength 64 is aggressive. For a realistic shallow-depth look, most people end up below 40 with a wide focus_spread.
It's a great "finish the shot" node: generate or shoot, estimate depth, and sell the camera. Not a replacement for a real DoF simulation, but for most casual work it's indistinguishable at a glance - and it costs a fraction of a second.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| depth_map | IMAGE | — | |
| blur_strength | FLOAT | 640–256 | — |
| focal_depth | FLOAT | 1.000–1 | — |
| focus_spread | FLOAT | 1.01–8 | — |
| steps | INT | 51–32 | — |
| focal_range | FLOAT | 0.000–1 | — |
| mask_blur | INT | 11–127 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |