Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 2 min read

How to Add Depth of Field to a Photo With an Edge-Safe Focus Map

Adding synthetic depth of field is a segmentation problem before it is a blur problem. Define what must stay sharp, add a protected edge band around it, and reject any result that blurs across the subject boundary.

How to Add Depth of Field to a Photo With an Edge-Safe Focus Map

Edge-safe depth of field cover

Adding synthetic depth of field is a segmentation problem before it is a blur problem. Define what must stay sharp, add a protected edge band around it, and reject any result that blurs across the subject boundary.

Model the focus map

Assume a portrait with a person in front of a cafΓ©. Split the image into three regions:

type Region = "sharp" | "transition" | "blur";

interface FocusMap {
  subject: string[];
  protectedEdges: string[];
  background: string[];
  blurIntent: "ultra-shallow" | "shallow" | "moderate";
}

const map: FocusMap = {
  subject: ["eyes", "face", "hair", "jacket", "hands"],
  protectedEdges: ["hair silhouette", "fingers", "jacket shoulders"],
  background: ["menu board", "tables", "street lights"],
  blurIntent: "ultra-shallow"
};

The transition region matters most. A uniform blur mask will either leave the background too sharp or cut into hair and fingers.

Use the direct Depth Of Field app

Current Voor Depth Of Field workspace

Open the current Depth Of Field workspace. The live page describes FLUX.1 Kontext [pro], requires an Input Image, currently defaults Blur Effect to ultra shallow depth of field, offers Match Input Image and PNG, exposes Seed under Advanced Settings, and shows Public plus Generate.

Use a source with a clear foreground subject and enough background distance to make the requested optics plausible. Keep Match Input Image so edge comparisons remain aligned.

Translate the map into a narrow instruction

Avoid merely saying β€œcinematic bokeh.” Name the plane, protected boundary and background behavior:

Keep the person, both hands, hair silhouette and jacket completely sharp. Add ultra-shallow depth of field only behind the outer hair and shoulder edges. Use a soft graduated transition; blur the cafΓ© tables and lights into natural optical bokeh. Preserve face, pose, crop, lighting, text placement and foreground edges. No halo, cutout edge or radial blur.

If the app's Blur Effect control already expresses the strength, use the prompt to describe placement and exclusions rather than repeating decorative adjectives.

Run an edge validator

Review at 200% zoom. Sample pixels on both sides of difficult boundaries:

interface EdgeSample {
  name: string;
  subjectDetailRetained: boolean;
  backgroundSoftened: boolean;
  haloVisible: boolean;
}

const validEdge = (e: EdgeSample) =>
  e.subjectDetailRetained && e.backgroundSoftened && !e.haloVisible;

Test flyaway hair, glasses, fingers, translucent fabric and reflective edges. Then zoom back to 100% and check whether the blur direction and intensity feel like one lens rather than a painted mask.

Separate optical errors from content errors

  • Halo: widen the transition band and ask for gradual optical falloff.
  • Blurred hair: name the full hair silhouette as sharp.
  • Sharp holes in the background: enumerate visible background objects.
  • Radial smear: request lens-like bokeh, not motion blur.
  • Changed face or clothes: reduce the change set to background defocus only.

Execution constraints

The live credit estimate can depend on account state and completed inputs. Inspect it immediately before Generate rather than hard-coding a number. Keep Public only if the uploaded image may be publicly visible. Use photos you own or are authorized to edit.

Physical limitations

An AI blur is not a recovered depth map or a substitute for optical capture. Fine transparent edges, reflections and overlapping objects may be inferred incorrectly. Keep the original and disclose synthetic editing when documentary context matters.

Once every protected boundary is listed, run the edit in the exact Voor depth-of-field app and make the edge validatorβ€”not aesthetic excitementβ€”the release gate.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.