图像分区 · 检测框转区域裁块
Turn raw SAM3 bounding boxes into clean, ready-to-edit crops
- image
- bboxes
- native_regions
- x
- y
- width
- height
- report_json
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:
- Score filter - drop any box below
minimum_score(default 0.5). This is your noise gate. - Sort - remaining boxes are ranked by score descending, then by position.
- 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. - 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 tomultiple(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- theBOUNDING_BOXfrom SAM3 (it's markedforceInput, so it has to be wired, not typed).image- the same image SAM3 scanned. Dimensions must match the bbox coordinate space.context_pixelsandmultiple- 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; raiseminimum_scoreif you're getting junk crops, lowerdeduplicate_iouif 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.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| bboxes | BOUNDING_BOX | — | |
| minimum_score | FLOAT | 0.500–1 | — |
| context_pixels | INT | 2560–4096 | — |
| multiple | INT | 161–256 | — |
| deduplicate_iou | FLOAT | 0.850–1 | — |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| native_regions | IMAGE | — |
| x | INT | — |
| y | INT | — |
| width | INT | — |
| height | INT | — |
| report_json | STRING | — |