MCPcopy
hub / github.com/huchenlei/ComfyUI-layerdiffuse

github.com/huchenlei/ComfyUI-layerdiffuse @v0.1.0 sqlite

repository ↗ · DeepWiki ↗ · release v0.1.0 ↗
80 symbols 193 edges 7 files 18 documented · 22%
README

ComfyUI-layerdiffuse

ComfyUI implementation of https://github.com/layerdiffusion/LayerDiffuse.

Installation

Download the repository and unpack into the custom_nodes folder in the ComfyUI installation directory.

Or clone via GIT, starting from ComfyUI installation directory:

cd custom_nodes
git clone git@github.com:huchenlei/ComfyUI-layerdiffuse.git

Run pip install -r requirements.txt to install python dependencies. You might experience version conflict on diffusers if you have other extensions that depends on other versions of diffusers. In this case, it is recommended to setup separate Python venvs.

Workflows

Generate foreground

rgba

Generate foreground (RGB + alpha)

If you want more control of getting RGB image and alpha channel mask separately, you can use this workflow. readme1

Blending (FG/BG)

Blending given FG fg_cond

Blending given BG bg_cond

Extract FG from Blended + BG

diff_bg

Extract BG from Blended + FG

Forge impl's sanity check sets Stop at to 0.5 to get better quality BG. This workflow might be inferior comparing to other object removal workflows. diff_fg

Extract BG from Blended + FG (Stop at 0.5)

In SD Forge impl, there is a stop at param that determines when layer diffuse should stop in the denosing process. In the background, what this param does is unapply the LoRA and c_concat cond after a certain step threshold. This is hard/risky to implement directly in ComfyUI as it requires manually load a model that has every changes except the layer diffusion change applied. A workaround in ComfyUI is to have another img2img pass on the layer diffuse result to simulate the effect of stop at param. diff_fg_stop_at

Generate FG from BG combined

Combines previous workflows to generate blended and FG given BG. We found that there are some color variations in the extracted FG. Need to confirm with layer diffusion authors on whether this is expected. fg_all

Note

  • Currently only SDXL is supported. See https://github.com/layerdiffuse/sd-forge-layerdiffuse#model-notes for more details.
  • To decode RGBA result, the generation dimension must be multiple of 64. Otherwise, you will get decode error: image

TODO

  • [x] Foreground conditioning
  • [x] Background conditioning
  • [x] Blended + foreground => background
  • [x] Blended + background => foreground

Core symbols most depended-on inside this repo

get_model_sd_version
called by 5
layered_diffusion.py
safeint
called by 4
lib_layerdiffusion/utils.py
apply_layered_diffusion_attn_sharing
called by 3
layered_diffusion.py
safe_numpy
called by 3
lib_layerdiffusion/utils.py
high_quality_resize
called by 3
lib_layerdiffusion/utils.py
load_file_from_url
called by 3
lib_layerdiffusion/utils.py
decode
called by 2
layered_diffusion.py
apply_c_concat
called by 2
layered_diffusion.py

Shape

Method 41
Class 21
Function 18

Languages

Python100%

Modules by API surface

layered_diffusion.py35 symbols
lib_layerdiffusion/attention_sharing.py17 symbols
lib_layerdiffusion/models.py15 symbols
lib_layerdiffusion/utils.py10 symbols
lib_layerdiffusion/enums.py3 symbols

Dependencies from manifests, versioned

diffusers0.25.0 · 1×

For agents

$ claude mcp add ComfyUI-layerdiffuse \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact