Nodes/ComfyUI Impact Pack/CropRegionXYFactorDetailerHookProvider
ComfyUI Node Runs on cloud

CropRegionXYFactorDetailerHookProvider

Separate Crop Factors For Width and Height, When One Number Isn't Enough

By ltdrdata·Created 4 years ago·Updated about 15 hours ago· 3,396
CropRegionXYFactorDetailerHookProvider
    • DETAILER_HOOK
    ◄crop_factor_x3.0►
    ◄crop_factor_y3.0►

    Every detector and detailer in Impact Pack gives you one crop_factor slider. It multiplies the box on both axes, so the crop around a detection is always the same shape as the detection itself, just bigger. Usually fine. Occasionally exactly wrong - a face where you want the hair and ears included but not two floors of ceiling, or a hand near the frame edge where the extra height costs you a skip. This hook gives you two sliders instead of one.

    How the region gets built

    The mechanism is refreshingly blunt. It takes the bbox and calls the pack's normal crop-region maths twice - once with crop_factor_x to get the left and right edges, once with crop_factor_y to get the top and bottom - then glues the result together into one rectangle. So crop_factor_x widens the region horizontally by that multiple of the box width, crop_factor_y does the same vertically, and the two numbers never talk to each other.

    The important consequence: the region this hook produces replaces whatever the detector or FaceDetailer made with its own crop factor. Your crop_factor widget on the detector becomes dead weight in that path. Don't spend twenty minutes tuning both.

    Sensible starting points: for faces, something like 2.0 × 3.0 pulls the crop in sideways while keeping vertical context for hair and chin. For portraits or full bodies where you want the crop to stop climbing into the background, lower crop_factor_y and leave x alone. For a crop you want genuinely tight, remember the floor is 1.0 on both - you can't crop inside the box this way, only decide how much room to leave around it.

    Inputs and outputs

    Two floats, both defaulting to 3.0, both ranging 1.0 to 100 in steps of 0.1:

    • crop_factor_x - width multiple applied to the bbox width.
    • crop_factor_y - height multiple applied to the bbox height.

    Output is a single DETAILER_HOOK. Nothing reads the SEGS, nothing returns an image; the hook is called once per detected area, during region planning.

    Wire it to the detailer_hook input of FaceDetailer if FaceDetailer is doing the detecting, or to the detailer_hook of a detector like BBOX Detector (SEGS) in a split detect-then-Detailer (SEGS) graph. Crop regions are decided at detection time and carried inside the SEGS, so attaching the hook to the detailer alone changes nothing for SEGS that already came from a detector. For SEGS that were never detected - tiles, mask-derived regions - use Apply Crop Region Hook (SEGS) to write the new region in.

    Hooks don't stack on one socket. If you want this and something like CropRegionMultipleDetailerHookProvider (multiples of 64), the two go through DetailerHookCombine, and the order matters: the first hook rewrites the region, the second one then works on that result.

    Install

    Standard Impact Pack install - the node is ImpactPack/Detailer in the add-node menu once the pack is loaded.

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

    On the Windows portable build, swap that last line for ..\..\..\python_embeded\python.exe -m pip install -r requirements.txt, then restart ComfyUI. Manager users just search ComfyUI Impact Pack. Heads-up from the install itself: the first run writes impact-pack.ini and pulls down the default SAM checkpoint into models/sams, which is a few hundred MB. Offline? Create an empty file named skip_download_model in custom_nodes before installing.

    The trap

    Widening a crop is not free. Bigger regions mean more decode, more sampling, more paste area, and a wider crop on a small face can drag in background the model then happily reinterprets - which is how detailing turns into redecorating.

    The other one is subtler: crop_factor also factors into whether a segment gets processed at all relative to guide_size. Change the region shape and you can change which detections get skipped. If a face suddenly stops being refined after you tightened the crop, look at guide_size before you blame the hook.

    CategoryImpactPack/Detailer

    Inputs (2)

    NameTypeDefaultDescription
    crop_factor_xFLOAT3.01–100—
    crop_factor_yFLOAT3.01–100—

    Outputs (1)

    NameTypeDescription
    DETAILER_HOOKDETAILER_HOOK—