CropRegionEqualMarginDetailerHookProvider
Same Margin On All Four Sides — Because crop_factor Multiplies Both Axes
- DETAILER_HOOK
Here's something that annoys me every time I detail a standing figure: crop_factor multiplies both sides of the bbox. A face that's roughly square comes out fine. A body that's 100 pixels wide and 400 tall becomes a 300×1200 crop - a thin sliver of margin at the sides and a giant column of background above and below, all of it resampled and composited. This hook exists purely to fix that arithmetic.
What it does
CropRegionEqualMarginDetailerHookProvider is a detailer hook with a very narrow job: after the detector has built a crop region the normal way, it throws that region away and rebuilds one where the margin is the same on all four sides.
The margin it uses is the one the short side would have got anyway - roughly min(bbox_w, bbox_h) * (crop_factor - 1). In practice, from the 100×400 body box above at the default crop factor of 3: the width stays at 300, and the height drops from 1200 to 600. Same framing around the subject, a quarter of the background. Since detailing cost scales with the area you decode and sample, that's a real speed and VRAM saving, not just tidiness.
One subtlety worth knowing, because it's where the numbers in the source get smart: the hook doesn't read a crop factor from anywhere. It looks at the region the detector already produced, works out the ratio of each side to its bbox side, and takes the larger of the two as the factor. That matters at image edges, where a crop region gets clipped and can only ever get shorter. It also leaves a side alone if it's within a pixel of the target, so you don't get regions jittering by one pixel for no reason.
Inputs and outputs
There are none. Literally nothing to set - this node is a widget-less box with one output, DETAILER_HOOK, which goes into a detailer_hook socket. That's the whole interface.
Where you plug it in decides when it applies:
FaceDetailer'sdetailer_hookinput. The one-shot case. FaceDetailer runs detection and refinement itself, so a hook connected here is used for both halves of the loop and you're done.- A detector's
detailer_hook, e.g.BBOX Detector (SEGS). Use this in split workflows where you detect once and then feedDetailer (SEGS). The crop regions are decided at detection time and travel inside the SEGS, so fixing them at the detector is what actually changes anything downstream. - Not the detailer on its own, if the SEGS came from a detector. By the time
Detailer (SEGS)sees the SEGS the crop region is already baked in. For SEGS that were never detected -Make Tile SEGS,MASK to SEGS- you needApply Crop Region Hook (SEGS)to write the region into the SEGS first.
You only get one detailer_hook socket per node, so if you also want, say, rounded masks or a tiled VAE, run both hooks through DetailerHookCombine.
Installing it
It ships in Impact Pack, so it's the pack install, nothing extra. In ComfyUI Manager search ComfyUI Impact Pack and install; manually it's:
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack
cd ComfyUI-Impact-Pack
pip install -r requirements.txt
Portable Windows users need ..\..\..\python_embeded\python.exe -m pip install -r requirements.txt instead of that last line, because the plain pip on your PATH may not be ComfyUI's Python. Then restart ComfyUI. On first launch the pack writes impact-pack.ini into its own folder and downloads the default SAM checkpoint into models/sams unless you drop an empty file named skip_download_model in custom_nodes. The node itself lives in the ImpactPack/Detailer right-click menu.
When it goes wrong
The hook can only work with what the detector gave it, so if your crop regions are already clamped to the image edge, some of that margin simply isn't there to take away - expect asymmetric framing on subjects at the border.
And be honest about what it fixes. It's a framing and cost fix, not a quality fix: if a face is being skipped because guide_size is too high for its bbox, or coming out mush because the crop is still tiny, equal margins won't change either. Those are the guide_size and sampling-resolution knobs, and SamplingSizeDetailerHookProvider is the better lever if that's your actual problem.
Inputs (0)
No inputs
Outputs (1)
| Name | Type | Description |
|---|---|---|
| DETAILER_HOOK | DETAILER_HOOK | — |