Unlock Seamless Background Replacement and Lighting Control with This AI-Powered Workflow

CN
ComfyUI.org
2025-05-09 08:48:56

1. Workflow Overview

magk047s08xv8fbp5zu7bcc7d6db65292de8387f085dc362c87e0802ab82535b71bf22c5e54dd647fda.gif

This workflow specializes in background replacement and light adjustment, with key features:

  1. Remove original background (e.g., portrait segmentation).

  2. Replace with custom background (e.g., snowy scene).

  3. Add controllable light sources (e.g., top white light) for scene blending.

  4. Optimize lighting consistency via ICLight model.

Use Cases: Portrait retouching, e-commerce product editing, virtual scene compositing.


2. Core Models

Model/Component

Function

Source File

RealisticVision V6.0

Base text-to-image model

realisticVision V6.0 B1.safetensors

ICLight Model

Light condition control

iclight_sd15_fc.safetensors

RMBG-2.0

Auto background removal

Built-in easy imageRemBg node


3. Key Nodes

Node Name

Function

Installation

easy imageRemBg

Auto background removal

Install ComfyUI-EasyImage

BackgroundScaler

Resize background to match foreground

Same as above

LightSource

Add custom light (position/color)

Install ComfyUI-LightTool

ICLightConditioning

Adjust latent space lighting

Install ComfyUI-ICLight

DetailTransfer

Blend details (e.g., soft light)

Built-in


4. Workflow Groups

  1. Input Group

    • Input: Source image (e.g., image.png, 976x1424).

    • Key Nodes: LoadImageeasy imageRemBg for mask generation.

  2. Preprocessing Group

    • Background Handling:

      • Scale background via BackgroundScaler.

    • Light Addition:

      • Configure LightSource (e.g., Top Light, color #FFFFFF).

  3. Light Optimization Group

    • ICLight Processing:

      • Load model via LoadAndApplyICLightUnet.

      • Inject light data into latent space with ICLightConditioning.

  4. Generation & Output Group

    • Sampling & Decoding:

      • KSampler with dpmpp_2m_sde (25 steps, CFG=0.9).

      • VAEDecode for final image.

    • Detail Fusion:

      • Blend foreground/background via DetailTransfer (soft_light mode).


5. Inputs & Outputs

  • Required Inputs:

    • Foreground image: Clear subject (e.g., portrait), simple background preferred.

    • Prompts:

      • Positive: Target background (e.g., In the snow).

      • Negative: Exclude artifacts (e.g., nsfw).

    • Light parameters: Position, color, intensity (e.g., top light, intensity=2).

  • Output:

    • Composited image with lighting, preview via PreviewImage.


6. Notes

  1. Hardware:

    • ≥8GB VRAM (RTX 3060+ recommended) due to ICLight and RealisticVision models.

  2. Troubleshooting:

    • Incomplete masking: Adjust easy imageRemBg threshold or manually edit mask.

    • Unnatural lighting: Tweak ICLightConditioning weight (default=0.18215).

  3. Extensibility:

    • Replace RealisticVision with other models (e.g., JuggernautXL) for style variation.