Nodes/Region Edit Toolkit/图像分区 · 检测框转区域裁块
ComfyUI Node

图像分区 · 检测框转区域裁块

Turn raw SAM3 bounding boxes into clean, ready-to-edit crops

By Liu-Bot24·Created 2 months ago·Updated about a month ago· 1
图像分区 · 检测框转区域裁块
  • image
  • bboxes
  • native_regions
  • x
  • y
  • width
  • height
  • report_json
minimum_score0.50
context_pixels256
multiple16
deduplicate_iou0.85

A SAM3 run over a busy photo returns more than you want: overlapping boxes, low-confidence junk, and coordinates that don't care whether they're aligned to anything a diffusion model can digest. RegionEditDetectionsToRegionCrops is the cleanup pass - it takes the raw BOUNDING_BOX output from your SAM3 locator, filters it, dedupes it, and produces native-resolution context crops you can actually edit, along with the coordinates to put them back.

This is the node that makes the pack's smart-removal workflow feel automatic. The README's flow is: SAM3 finds the target (and optionally the protected regions) → this node turns detections into crops → you edit each crop → a strict composite puts everything back at the exact pixel it came from. Without it you'd be hand-rectangling every box, which is precisely the kind of fiddly manual step this pack exists to remove.

How it works

Under the hood it's a pipeline of four filters:

  1. Score filter - drop any box below minimum_score (default 0.5). This is your noise gate.
  2. Sort - remaining boxes are ranked by score descending, then by position.
  3. IoU dedup - for each candidate, if it overlaps an already-kept box by more than deduplicate_iou (default 0.85), it's discarded. One object → one crop, instead of three nested boxes on the same cat.
  4. Align and expand - each surviving box is padded out by context_pixels (default 256) so the crop has room around the object (crucial for edit models, which change everything in context), then snapped to multiple (default 16) so the crop lands on alignment boundaries your VAE and the strict composite are happy with.

The output is a list of native_regions - one crop per kept detection, at full source resolution, never resized. The companion list outputs x, y, width, height stay in lockstep with the crops, index for index. That pairing is the contract: whichever crop you edit, its coordinates travel with it, and the composite later trusts them.

Inputs that matter

  • bboxes - the BOUNDING_BOX from SAM3 (it's marked forceInput, so it has to be wired, not typed).
  • image - the same image SAM3 scanned. Dimensions must match the bbox coordinate space.
  • context_pixels and multiple - the two knobs that decide crop size and alignment. More context = safer edits, bigger crops.
  • minimum_score / deduplicate_iou - the two filters. Start with defaults; raise minimum_score if you're getting junk crops, lower deduplicate_iou if overlapping objects are collapsing into one.

Outputs beyond the list: report_json, which counts raw boxes vs. score-filtered vs. kept, and logs each crop's source box and final rect. If the locator returns nothing above your score, it raises a clear error rather than silently cropping zero regions.

Install

Same pack-wide routine: ComfyUI Manager → search "Region Edit Toolkit" (package ID native-region-tile-planner-merge) → install → restart. Or git clone https://github.com/Liu-Bot24/ComfyUI-Region-Edit-Toolkit.git into custom_nodes, pip install -r requirements.txt into ComfyUI's Python, restart. Python 3.10+, deps numpy/Pillow/scipy/argostranslate. No models bundled - SAM3 weights are yours to point at, and the example workflows expect them in your local model directories.

Gotchas

This node consumes SAM3's output but SAM3 itself is a separate install (the example workflow lists it as a missing node to add via Manager). The classic failure is a coordinate-space mismatch: SAM3 scans one image, you feed a different one to this node, and the crops come out garbage or the node errors. And remember the dedup - if you lower deduplicate_iou too far, a single large object gets split into several overlapping crops, and your edit pass spends its budget re-editing the same pixels twice.

CategoryRegion Edit Toolkit/Selection

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
bboxesBOUNDING_BOX
minimum_scoreFLOAT0.500–1
context_pixelsINT2560–4096
multipleINT161–256
deduplicate_iouFLOAT0.850–1

Outputs (6)

NameTypeDescription
native_regionsIMAGE
xINT
yINT
widthINT
heightINT
report_jsonSTRING