Nodes/ComfyUI-ZML-Image/ZML_分离图层
ComfyUI Node

ZML_分离图层

Cut a character sheet into individual layers in one pass

By zml-w·Created about a year ago·Updated 2 months ago· 218
ZML_分离图层
  • 图像
  • 分离图像
  • 图层数量
最小面积比例0.005
合并阈值10
检测背景透明
填充背景透明
自定义检测背景颜色#FFFFFF
自定义填充背景颜色#000000

If you work with three-view character sheets or reference grids, you know the chore: you generate one image with three characters on a white background, then you have to crop each one out by hand. ZML_SeparateImageLayers automates exactly that. It looks at an image - transparent, or on a solid background - finds every disconnected region of pixels, and slices each one out as its own layer, with the rest filled with the background color you choose. The author's changelog example is precisely this: cut a white-background three-view sheet into three single views.

It's the pack's answer to a specific post-processing annoyance, and it's a good one to have around even if you only use it occasionally.

The inputs that matter

  • 图像 (required) - the input, RGBA transparent images preferred for best results.
  • 检测背景 - what counts as "background" to ignore: 透明, 白色, 黑色, 绿色, or 自定义 (with a hex like #RRGGBB in 自定义检测背景颜色). 透明 uses the alpha channel, which is the most reliable for cutouts.
  • 填充背景 - what to fill the non-subject area of each layer with: 透明 (RGBA output), a solid color, or 自定义 (via 自定义填充背景颜色).
  • 最小面积比例 - filters out tiny speckle regions; it's a fraction of total image area. 0.005 means "drop anything smaller than 0.5% of the image." Raise it to kill dust and anti-aliasing flecks.
  • 合并阈值 - the clever one. If two regions are separated by fewer than this many pixels, they merge into one layer. Default 10. This is what keeps a person's arm and their slightly-detached hand as one layer instead of two.

Outputs are 分离图像 (the layers, all at the original resolution, as an image batch) and 图层数量 (INT - how many regions were found), which you can use to sanity-check that the split behaved.

How it works

Mechanically it's connected-components on the non-background mask: label each contiguous region, filter by the minimum-area threshold, merge regions closer than the merge threshold, then for each surviving region build a full-size output image where that region's pixels are kept and everything else becomes the fill color. Because every layer keeps the original canvas size, you can stack them straight back together or feed them to compositing nodes without re-batching headaches. If the input has an alpha channel and you pick 透明 fill, you get proper RGBA cutouts ready for compositing.

Where it fits

The workflow is: generate or load your sheet, separate, then process each layer - background removal, upscaling, individual saving - and optionally re-composite. It also works for separating a collaged image into its parts for editing. The main caveats: it relies on the subject being on a detectable background, so busy backgrounds will under-perform, and tiny area thresholds can leave noise regions in. Start at the defaults and nudge 最小面积比例 up until the specks disappear.

Install

ComfyUI Manager → search "ComfyUI-ZML-Image", or cd ComfyUI/custom_nodes && git clone https://github.com/zml-w/ComfyUI-ZML-Image, restart. Displayed as ZML_分离图层 in the Chinese-default UI; the English patch covers it. It uses standard image libraries (the pack's requirements include numpy/Pillow, which ComfyUI already has), so no extra model downloads.

Categoryimage/ZML_图像/图像

Inputs (7)

NameTypeDefaultDescription
图像IMAGE输入图像,支持RGBA透明背景图像
最小面积比例FLOAT0.0050–1过滤小区域的阈值,相对于图像总面积的比例。例如0.01表示过滤掉小于图像面积1%的区域
合并阈值INT100–500控制图层合并的阈值(像素)。如果两个图层之间的间隔像素小于此值,则会合并为一个图层
检测背景COMBO透明用于检测分离的背景颜色。选择'透明'时优先使用Alpha通道
填充背景COMBO透明分离后非区域部分的填充颜色。'透明'需要输出为RGBA格式
自定义检测背景颜色optSTRING#FFFFFF自定义检测背景颜色,格式为#RRGGBB或RGB值
自定义填充背景颜色optSTRING#000000自定义填充背景颜色,格式为#RRGGBB或RGB值

Outputs (2)

NameTypeDescription
分离图像IMAGE
图层数量INT