ComfyUI Node
Klein Edit Composite
A ComfyUI node in image/Klein with 18 inputs and 4 outputs.
Klein Edit Composite
- generated_image
- original_image
- custom_mask
- composited_image
- change_mask
- report
- debug_gallery
◄delta_e_threshold-1►
◄flow_qualitymedium►
◄use_occlusionfalse►
◄occlusion_threshold-1.0►
◄noise_removal_pct0.00►
◄close_radius_pct0.5►
◄fill_holesfalse►
◄fill_borderstrue►
◄max_islands0►
◄grow_mask_pct0.0►
◄feather_pct2.00►
◄color_match_blend1.00►
◄poisson_blend_edgesfalse►
◄custom_mask_modereplace►
◄enable_debugfalse►
Categoryimage/Klein
Inputs (18)
| Name | Type | Default | Description |
|---|---|---|---|
| generated_image | IMAGE | — | |
| original_image | IMAGE | — | |
| delta_e_threshold | FLOAT | -1-1–100 | Controls how different a pixel must be (in perceptual color distance) to be considered 'changed' and included in the composite mask. Lower values = more sensitive, picking up subtle edits but risking false positives in unchanged areas. Higher values = less sensitive, only catching obvious changes but potentially missing fine details. Set to -1 to let the node auto-tune this threshold using Median Absolute Deviation (MAD) — recommended for most cases. |
| flow_quality | COMBO | medium | Sets the precision of the optical flow calculation used to detect motion and structural changes between the original and generated images. 'medium' gives the best accuracy and is recommended for most edits. 'fast' reduces computation time at a slight accuracy cost — useful for quick previews or large images. 'ultrafast' is the lowest quality but quickest — suitable for rough drafts or iterating on settings before a final render. |
| use_occlusion | BOOLEAN | false | When enabled, adds occlusion detection to the change mask — areas where one image occludes content visible in the other (e.g. an object moves and reveals background behind it). Turn ON when the edit involves camera movement or objects shifting position, as it ensures those newly revealed regions are included in the mask. Leave OFF for color, texture, or style edits — occlusion detection can bleed the mask into unchanged areas when there is no real motion. |
| occlusion_threshold | FLOAT | -1.0-1–50 | Only active when 'use_occlusion' is enabled. Controls how large the forward-backward optical flow error must be before a pixel is classified as occluded. Lower values flag more pixels as occluded (wider mask, more bleed risk). Higher values only flag clearly inconsistent flow (tighter mask, may miss subtle occlusions). Set to -1 to auto-tune using Median Absolute Deviation — recommended. |
| noise_removal_pct | FLOAT | 0.000–3 | Removes speckle noise from the raw change mask using morphological opening (erode then dilate). Value is the radius as a percentage of the image diagonal, so it scales automatically with resolution. Increase this when the mask has many tiny isolated dots or grains in areas that should be clean background — higher values eliminate larger speckles. Keep at 0 (disabled) if the edit has fine detail at the edges, as too high a value will erode legitimate thin features like hair or text. |
| close_radius_pct | FLOAT | 0.50–5 | Fills small gaps and connects nearby mask regions using morphological closing (dilate then erode). Value is the radius as a percentage of the image diagonal. Increase this to bridge gaps between nearby changed regions so they merge into one solid area — useful when the mask has broken edges or thin holes cutting through the middle of an edited object. Lower values preserve tight separation between distinct changed regions. Too high a value can merge separate objects that should remain independent. |
| fill_holes | BOOLEAN | false | Flood-fills enclosed interior holes inside the mask. Turn ON when the detected mask has gaps or voids inside an edited region — for example, a changed object whose interior was not fully detected. This ensures the entire interior is composited rather than leaving patches of the original showing through. Leave OFF if you intentionally need transparency or cut-outs inside the mask, or if interior regions are genuinely unchanged background. |
| fill_borders | BOOLEAN | true | When alignment warps or shifts the generated image, it can leave void border regions where no generated pixel exists. Turn ON (default) to extrapolate the mask into those borders and fill them with mirrored pixels from the generated image, hiding the void seamlessly. Turn OFF to instead fall back to the original image in those border areas — useful if the mirrored fill looks wrong or if the warp is large enough that mirroring produces visible artifacts. |
| max_islands | INT | 00–32 | Limits the mask to only the N largest connected regions, discarding all smaller isolated patches. Set to 1 to keep only the single largest changed area. Increase to allow a small number of distinct regions (e.g. 2 for a foreground object and a shadow). Set to 0 (default) to keep all regions regardless of size — best when the edit spans many small areas like texture or pattern changes. Use in combination with noise_removal to first eliminate tiny speckles before this filter acts on the remaining islands. |
| grow_mask_pct | FLOAT | 0.0-3–3 | Expands or contracts the final mask boundary as a percentage of the image diagonal. Positive values grow the mask outward — use this to ensure the composite fully covers the edited region when detection falls slightly short of the true edges. Negative values shrink the mask inward — useful for tightening a mask that bleeds into unchanged background. 0 leaves the mask exactly as detected. Feathering is applied after this step, so growth and feather work together to produce a clean edge. |
| feather_pct | FLOAT | 2.000–10 | Controls the width of the soft blend transition at mask edges, as a percentage of the image diagonal. Applies a smooth distance-based falloff from the mask boundary, producing a clean gradual transition between the composited and original regions. Higher values create a wider, softer blend — good for smooth subjects like skin or fabric where a hard edge would look artificial. Lower values produce a tighter, harder edge — useful for geometric subjects or when you need precise control and the edges are already well-detected. 0 disables feathering entirely. |
| color_match_blend | FLOAT | 1.000–1 | Corrects lighting and color tone differences between the original and generated images before compositing, using Reinhard color transfer on the background region. 1.0 (default) fully matches the generated image's colors to the original — recommended when the AI model has shifted the overall brightness, white balance, or saturation compared to the source. Lower values partially blend the correction, preserving some of the generated image's own color grading. Set to 0.0 to disable color matching entirely — use this if the generated image's color shift is intentional (e.g. a day-to-night conversion). |
| poisson_blend_edges | BOOLEAN | false | Uses Poisson Blending (cv2.seamlessClone) to mathematically eliminate lighting and color seams introduced by the AI model. If disabled, uses alpha blending. |
| custom_maskopt | MASK | An optional mask to modify or replace the auto-detected composite boundary. Behaviour is controlled by the custom_mask_mode setting below. Feathering, grow, and fill_borders always apply after the mask is combined. Leave disconnected to use the node's built-in detection pipeline. | |
| custom_mask_modeopt | COMBO | replace | Controls how the custom_mask is combined with the auto-detected mask. replace: skips internal detection entirely and uses only the custom mask (original behaviour — fastest, use when auto-detection is unreliable). add: runs the full detection pipeline, then unions the custom mask on top — useful for forcing extra regions into the composite that detection missed. subtract: runs the full detection pipeline, then removes the custom mask area from the result — useful for protecting specific regions (e.g. background objects that are incorrectly flagged as changed) from being composited. |
| enable_debugopt | BOOLEAN | false | Outputs a debug gallery image showing internal intermediate states: SIFT feature matches, alignment results, difference maps, flow visualization, and the detected change mask overlay. Turn ON to diagnose alignment failures, unexpected mask shapes, or blending artifacts — the gallery makes it easy to see exactly where the pipeline is succeeding or going wrong. Leave OFF during normal use to save memory and processing time. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| composited_image | IMAGE | — |
| change_mask | MASK | — |
| report | STRING | — |
| debug_gallery | IMAGE | — |