Nodes/ComfyUI Impact Pack/Apply Crop Region Hook (SEGS)
ComfyUI Node Runs on cloud

Apply Crop Region Hook (SEGS)

The Adapter That Lets Bare SEGS Use Crop Region Hooks

By ltdrdata·Created 4 years ago·Updated about 15 hours ago· 3,396
Apply Crop Region Hook (SEGS)
  • segs
  • detailer_hook
  • SEGS

Impact Pack's crop-region hooks are great little problem solvers, and they all assume the same thing: that something upstream accepts a detailer_hook and will call it while planning each crop. Detectors do. FaceDetailer does. Make Tile SEGS and MASK to SEGS do not - they just emit SEGS with crop regions already computed, and there's no socket to intervene. Apply Crop Region Hook (SEGS) is the adapter that closes that gap.

What it actually does

Give it SEGS and a hook, and for every SEG it asks the hook to recompute the crop region from that SEG's bbox and its existing region - precisely the call a detector would have made. If the hook returns something different, the node rebuilds the SEG around the new region. That's it. It's a shim between "SEGS that already exist" and "hooks that want to shape regions before they exist".

The interesting part is what happens to the mask. A bigger region with an unchanged cropped mask would be misaligned, so the node reallocates a mask at the new size and copies the old mask into it, centred where it belongs, leaving the newly added margin as zeros. That's the behaviour you want - the detail pass is framed by the crop region but only blended through the mask - and it's also the thing to remember when you're debugging: growing a region through this node does not grow the area that gets painted.

It also clears the SEG's stored cropped image, because a picture of the old region is worse than no picture.

Only the hook's crop-region behaviour is applied here. If the hook also does other things - filtering, sampling sizes, tiled VAE - those are ignored by this node. Read its socket tooltip some time; it says as much, which is refreshing honesty for a node like this.

Inputs and outputs

  • segs - the SEGS to modify, typically from Make Tile SEGS, MASK to SEGS, Bounding Boxes to SEGS, or a SEGS filter.
  • detailer_hook - a hook that changes crop regions. In practice that's CropRegionMultipleDetailerHookProvider, CropRegionXYFactorDetailerHookProvider, CropRegionEqualMarginDetailerHookProvider or SamplingSizeDetailerHookProvider.
  • Output: SEGS, with the new crop regions baked in.

Placement matters more than the wiring. Put it before ControlNetApply (SEGS) - that node crops its control image to the crop region each SEG has at the time it runs. If you round your regions to multiples of 64 after the ControlNet crop, the ControlNet is conditioned on a differently framed patch than the one the detailer samples. The pack documents this, and it's the one ordering mistake people make here.

Install

It's in the pack, under ImpactPack/Util.

cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack
cd ComfyUI-Impact-Pack
pip install -r requirements.txt

Windows portable: ..\..\..\python_embeded\python.exe -m pip install -r requirements.txt. Then restart ComfyUI. Manager users search ComfyUI Impact Pack instead. First launch writes impact-pack.ini and pulls the default SAM checkpoint into models/sams unless you create an empty skip_download_model file in custom_nodes.

Like every node here, the sockets are wildcard-typed, so a type mismatch may show up as a validation complaint rather than a clean refusal. If the wire looks right and ComfyUI is still unhappy, that's usually what's happening.

Where people trip

Using it as a substitute for hooking the detector. If your SEGS came from BBOX Detector (SEGS) or Simple Detector (SEGS), those nodes already take a detailer_hook - hook them directly and skip this node; it's not doing anything extra there.

Second, expecting the mask to expand. Feed CropRegionMultipleDetailerHookProvider at 64 into this on a set of tile SEGS and you'll get neat aligned regions with masks still tight to the original tiles. Tiled upscaling likes that. If you wanted the masks feathered or dilated outward to match, that's Dilate Mask (SEGS) after this node, not before.

CategoryImpactPack/Util

Inputs (2)

NameTypeDefaultDescription
segsSEGS—
detailer_hookDETAILER_HOOKA hook that changes crop regions, such as CropRegionMultipleDetailerHookProvider. Its other effects are not applied here.

Outputs (1)

NameTypeDescription
SEGSSEGS—