Generate a bokeh effect resembling lens blur in a single photo (large circular highlights, creamy soft out-of-focus areas) while preserving foreground details.
Last week my KSampler re-rendered the subject=body, which wasn't what I intended, so I experimented with the new inpaint controller component. I compared manual pixel blurring with local AI re-rendering (KSampler) techniques and explored which parameters control this effect.
• Mask prep: Canny → convert→ morphology (erode) → Feather to get a smooth foreground mask (white = rewrite region).
• Conditioning: Load SDXL (checkpoint + VAE). Two CLIP prompts:
• Positive: soft out-of-focus background, creamy circular bokeh, photographic shallow depth of field
• Negative: no change to subject, preserve subject details, keep original color and texture
• Local rewrite: InpaintModelConditioning with noise_mask = true → outputs latent conditioning that feeds KSampler (ksampler.latent_image = inpaint-latent).
• Parameter sweep: XY Plot controlled CFG × denoise (seed fixed). Export grid for visual comparison.
• Baseline: ImageBlur + mask compositing (manual pixel blur) for direct side-by-side comparison.
Key node: noise_mask = true — injects noise only inside mask so KSampler rewrites background while leaving foreground latent unchanged.
• Main finding: denoise is the dominant controller of bokeh strength. In this dataset, ~0.55–0.8 produced the most convincing large-spot bokeh; lower values (≈0.3) produced weak/near-original background.
• CFG effect: Within the tested range, CFG has minor impact on bokeh strength; it mainly changes how strongly the prompt is followed (color/tonal shifts) but not the scale of blur driven by denoise.
• KSampler + noise_mask — produces realistic, lens-like highlights and depth; foreground detail preserved.
• Risks: at higher denoise you can get color drift, occasional structural artifacts near mask edges, or unnatural light blobs.
• Pixel-blur baseline — perfect texture fidelity but lacks realistic highlight shape and lens physics.
• Mitigations: increase erode or VAEEncode.grow_mask_by if halos appear; lower denoise or blend generated background with pixel-blur baseline (e.g., 0.7 gen + 0.3 baseline) to reduce color/structure artifacts.
• Mask: erode 3–7, feather 8–16 (for 2k image).
• InpaintModelConditioning: noise_mask = true.
• KSampler: sampler = dpmpp_2m, scheduler = karras, steps = 18–22, cfg = 6–7, denoise sweep = 0.3, 0.55, 0.8, seed fixed.
• Export grid and run simple metrics (foreground SSIM, Laplacian variance) if quantitative evidence is needed.
Code: Select all
{
"id": "e590f171-d23e-4c33-adac-2fb614c4784a",
"revision": 0,
"last_node_id": 122,
"last_link_id": 154,
"nodes": [
{
"id": 27,
"type": "CLIPTextEncode",
"pos": [
3106.934814453125,
2144.408447265625
],
"size": [
400,
200
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": null
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
""
]
},
{
"id": 70,
"type": "MaskToImage",
"pos": [
155.68614196777344,
773.5596313476562
],
"size": [
264.5999755859375,
26
],
"flags": {},
"order": 11,
"mode": 0,
"inputs": [
{
"name": "mask",
"type": "MASK",
"link": 54
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
57
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "MaskToImage"
},
"widgets_values": []
},
{
"id": 12,
"type": "Morphology",
"pos": [
512.0804443359375,
678.2466430664062
],
"size": [
315,
82
],
"flags": {},
"order": 12,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 57
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
86
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "Morphology"
},
"widgets_values": [
"dilate",
20
]
},
{
"id": 64,
"type": "PyraCannyPreprocessor",
"pos": [
332.6476135253906,
213.030029296875
],
"size": [
315,
106
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 48
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
52
]
}
],
"properties": {
"cnr_id": "comfyui_controlnet_aux",
"ver": "1.0.7",
"Node name for S&R": "PyraCannyPreprocessor"
},
"widgets_values": [
200,
11,
512
]
},
{
"id": 69,
"type": "ImageToMask",
"pos": [
324.47308349609375,
405.0953369140625
],
"size": [
315,
58
],
"flags": {},
"order": 9,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 52
}
],
"outputs": [
{
"name": "MASK",
"type": "MASK",
"links": [
53
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "ImageToMask"
},
"widgets_values": [
"blue"
]
},
{
"id": 89,
"type": "Morphology",
"pos": [
304.2228698730469,
852.0550537109375
],
"size": [
315,
82
],
"flags": {},
"order": 13,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 86
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
88
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "Morphology"
},
"widgets_values": [
"erode",
40
]
},
{
"id": 92,
"type": "ImageInvert",
"pos": [
663.406005859375,
1083.1741943359375
],
"size": [
140,
65.3625717163086
],
"flags": {},
"order": 14,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 88
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
136
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "ImageInvert"
},
"widgets_values": []
},
{
"id": 98,
"type": "CLIPTextEncode",
"pos": [
978.55419921875,
106.55122375488281
],
"size": [
400,
200
],
"flags": {},
"order": 8,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 109
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"links": [
141
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
"soft out-of-focus background, creamy circular bokeh, soft specular highlights, photographic shallow depth of field, natural colors"
]
},
{
"id": 97,
"type": "CLIPTextEncode",
"pos": [
1436.2205810546875,
108.20538330078125
],
"size": [
400,
200
],
"flags": {},
"order": 7,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 108
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"links": [
142
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
"no change to subject, preserve subject details, keep original color and texture, no stylization, no distortions, no added objects"
]
},
{
"id": 108,
"type": "ImageToMask",
"pos": [
854.4579467773438,
1153.505615234375
],
"size": [
315,
58
],
"flags": {},
"order": 15,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 136
}
],
"outputs": [
{
"name": "MASK",
"type": "MASK",
"links": [
145
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "ImageToMask"
},
"widgets_values": [
"green"
]
},
{
"id": 68,
"type": "FeatherMask",
"pos": [
175.675537109375,
564.7435302734375
],
"size": [
315,
130
],
"flags": {},
"order": 10,
"mode": 0,
"inputs": [
{
"name": "mask",
"type": "MASK",
"link": 53
}
],
"outputs": [
{
"name": "MASK",
"type": "MASK",
"links": [
54
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "FeatherMask"
},
"widgets_values": [
100,
2000,
500,
5
]
},
{
"id": 2,
"type": "LoadImage",
"pos": [
-363.26641845703125,
236.5191650390625
],
"size": [
248.3976287841797,
326
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
48,
146
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"DSC4093-Edit2-Edit.jpg",
"image"
]
},
{
"id": 118,
"type": "InpaintModelConditioning",
"pos": [
1256.1368408203125,
554.21240234375
],
"size": [
315,
138
],
"flags": {},
"order": 16,
"mode": 0,
"inputs": [
{
"name": "positive",
"type": "CONDITIONING",
"link": 141
},
{
"name": "negative",
"type": "CONDITIONING",
"link": 142
},
{
"name": "vae",
"type": "VAE",
"link": 140
},
{
"name": "pixels",
"type": "IMAGE",
"link": 146
},
{
"name": "mask",
"type": "MASK",
"link": 145
}
],
"outputs": [
{
"name": "positive",
"type": "CONDITIONING",
"links": [
147
]
},
{
"name": "negative",
"type": "CONDITIONING",
"links": [
148
]
},
{
"name": "latent",
"type": "LATENT",
"links": [
149
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "InpaintModelConditioning"
},
"widgets_values": [
true
]
},
{
"id": 120,
"type": "XY Input: CFG Scale",
"pos": [
1358.856689453125,
949.4103393554688
],
"size": [
315,
106
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "X or Y",
"type": "XY",
"links": [
151
]
}
],
"properties": {
"cnr_id": "efficiency-nodes-comfyui",
"ver": "9e3c5aa4976ad457065ef06a0dfdfc66e17c59ee",
"Node name for S&R": "XY Input: CFG Scale"
},
"widgets_values": [
3,
7,
9
],
"color": "#223333",
"bgcolor": "#335555",
"shape": 1
},
{
"id": 121,
"type": "XY Input: Denoise",
"pos": [
1343.4197998046875,
1143.7952880859375
],
"size": [
315,
106
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "X or Y",
"type": "XY",
"links": [
152
]
}
],
"properties": {
"cnr_id": "efficiency-nodes-comfyui",
"ver": "9e3c5aa4976ad457065ef06a0dfdfc66e17c59ee",
"Node name for S&R": "XY Input: Denoise"
},
"widgets_values": [
3,
0,
0.7000000000000002
],
"color": "#223333",
"bgcolor": "#335555",
"shape": 1
},
{
"id": 122,
"type": "XY Plot",
"pos": [
1764.690185546875,
970.8652954101562
],
"size": [
355.20001220703125,
194
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "dependencies",
"shape": 7,
"type": "DEPENDENCIES",
"link": null
},
{
"name": "X",
"shape": 7,
"type": "XY",
"link": 151
},
{
"name": "Y",
"shape": 7,
"type": "XY",
"link": 152
}
],
"outputs": [
{
"name": "SCRIPT",
"type": "SCRIPT",
"links": [
153
]
}
],
"properties": {
"cnr_id": "efficiency-nodes-comfyui",
"ver": "9e3c5aa4976ad457065ef06a0dfdfc66e17c59ee",
"Node name for S&R": "XY Plot"
},
"widgets_values": [
0,
"False",
"Horizontal",
"True",
"Images"
],
"color": "#332233",
"bgcolor": "#553355",
"shape": 1
},
{
"id": 96,
"type": "CheckpointLoaderSimple",
"pos": [
711.5999145507812,
367.3253479003906
],
"size": [
315,
98
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "MODEL",
"type": "MODEL",
"links": [
154
]
},
{
"name": "CLIP",
"type": "CLIP",
"links": [
108,
109
]
},
{
"name": "VAE",
"type": "VAE",
"links": [
140
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "CheckpointLoaderSimple"
},
"widgets_values": [
"SDXL/sd_xl_base_1.0.safetensors"
]
},
{
"id": 105,
"type": "PreviewImage",
"pos": [
2176.60009765625,
439.0733642578125
],
"size": [
210,
246
],
"flags": {},
"order": 18,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 150
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.29",
"Node name for S&R": "PreviewImage"
},
"widgets_values": []
},
{
"id": 119,
"type": "KSampler (Efficient)",
"pos": [
1751.01513671875,
462.8314208984375
],
"size": [
325,
350
],
"flags": {},
"order": 17,
"mode": 0,
"inputs": [
{
"name": "model",
"type": "MODEL",
"link": 154
},
{
"name": "positive",
"type": "CONDITIONING",
"link": 147
},
{
"name": "negative",
"type": "CONDITIONING",
"link": 148
},
{
"name": "latent_image",
"type": "LATENT",
"link": 149
},
{
"name": "optional_vae",
"shape": 7,
"type": "VAE",
"link": null
},
{
"name": "script",
"shape": 7,
"type": "SCRIPT",
"link": 153
}
],
"outputs": [
{
"name": "MODEL",
"type": "MODEL",
"links": null
},
{
"name": "CONDITIONING+",
"type": "CONDITIONING",
"links": null
},
{
"name": "CONDITIONING-",
"type": "CONDITIONING",
"links": null
},
{
"name": "LATENT",
"type": "LATENT",
"links": null
},
{
"name": "VAE",
"type": "VAE",
"links": null
},
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
150
]
}
],
"properties": {
"cnr_id": "efficiency-nodes-comfyui",
"ver": "9e3c5aa4976ad457065ef06a0dfdfc66e17c59ee",
"Node name for S&R": "KSampler (Efficient)"
},
"widgets_values": [
42,
null,
20,
7,
"dpmpp_2m",
"normal",
1,
"auto",
"true"
],
"color": "#443322",
"bgcolor": "#665533",
"shape": 1
}
],
"links": [
[
48,
2,
0,
64,
0,
"IMAGE"
],
[
52,
64,
0,
69,
0,
"IMAGE"
],
[
53,
69,
0,
68,
0,
"MASK"
],
[
54,
68,
0,
70,
0,
"MASK"
],
[
57,
70,
0,
12,
0,
"IMAGE"
],
[
86,
12,
0,
89,
0,
"IMAGE"
],
[
88,
89,
0,
92,
0,
"IMAGE"
],
[
108,
96,
1,
97,
0,
"CLIP"
],
[
109,
96,
1,
98,
0,
"CLIP"
],
[
136,
92,
0,
108,
0,
"IMAGE"
],
[
140,
96,
2,
118,
2,
"VAE"
],
[
141,
98,
0,
118,
0,
"CONDITIONING"
],
[
142,
97,
0,
118,
1,
"CONDITIONING"
],
[
145,
108,
0,
118,
4,
"MASK"
],
[
146,
2,
0,
118,
3,
"IMAGE"
],
[
147,
118,
0,
119,
1,
"CONDITIONING"
],
[
148,
118,
1,
119,
2,
"CONDITIONING"
],
[
149,
118,
2,
119,
3,
"LATENT"
],
[
150,
119,
5,
105,
0,
"IMAGE"
],
[
151,
120,
0,
122,
1,
"XY"
],
[
152,
121,
0,
122,
2,
"XY"
],
[
153,
122,
0,
119,
5,
"SCRIPT"
],
[
154,
96,
0,
119,
0,
"MODEL"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.6303940863128529,
"offset": [
-373.9236867182337,
89.60021626388557
]
},
"frontendVersion": "1.16.9"
},
"version": 0.4
}