Smart Mask Crop
Smart Mask Crop — the focused-region editor's front end
- image
- mask
- stitcher
- cropped_image
- cropped_mask
- cropped_mask_image
- preview_image
- info
Some editors - GPT Image being the big one - accept a real mask. That changes the game versus the Nano Banana path, because you can crop a tight region around what you're editing, send the model only that crop plus a matching mask, and never let it touch the rest of the frame. Smart Mask Crop is the node that prepares that crop. It's the most configurable node in this pack, and it's the front end for the whole "local masked edit" path:
Florence-2 or SAM selector -> mask -> Smart Mask Crop
-> cropped_image -> GPT Image Edit (image_1)
-> cropped_mask_image -> GPT Image Edit (mask_image)
-> Smart Mask Stitch -> final image
The output wiring is the thing to get right: cropped_mask_image goes straight into the editor's mask_image (not the original Florence mask - it won't match the crop), and info can drive the editor's sizing so the requested output size stays aligned with the crop.
The inputs that matter
Required: image, mask, and then these three do most of the work:
context_expand(1.0–4.0, default 1.15) - grows the detected region before cropping, so the model sees a little original context around the object. Faces like 1.1–1.2; the README's guidance is 1.1–1.2 for faces, more or less as-is for other regions.target_size_mode- the sizing policy.region_recommended(default) trusts the Florence region defaults;manual_width_heightusestarget_width/target_height;max_for_aspect_ratiopicks the largest valid GPT Image size for a giventarget_aspect_ratio. For a portrait try-on where the source is already the right shape, the README's tip ismax_for_aspect_ratiowithtarget_aspect_ratio = input_image- that stops aglassesregion hint from forcing a horizontal 16:9 crop on a 4:5 workflow.mask_expand_percent/mask_feather_percent- the edit mask's expansion and softness. Both default to 0, which means "use the region's defaults" whileuse_region_mask_defaultsis on; disable that toggle if you want a hard mask you fully control.
Worth knowing: edit_size_scale_percent (25–200, default 100) scales the edit output as a percentage of the target - 50 = half size, useful when you want a quick cheap pass before committing to full detail.
Outputs: stitcher (into Smart Mask Stitch), cropped_image + cropped_mask_image (into the editor), plus cropped_mask, preview_image, and info (valid JSON with the final target size - feed it to GPT Image's region_info via auto_from_region).
Keep it local
One real mistake people make with GPT Image in this flow: prompting it to "recompose the whole portrait" or "fix the lighting globally." The editor will happily do that to the crop, which is a tiny region of the whole image - and then the stitch pastes an island of changed lighting back. The README is explicit: describe only the object, name the reference image, and explicitly preserve pixels outside the mask. The global fixes belong in a full-frame pass, not the local masked edit.
Install
Search comfyui-inpaint-cropstitch-nb2 in ComfyUI Manager or:
cd ComfyUI/custom_nodes
git clone https://github.com/amortegui84/comfyui-inpaint-cropstitch-nb2
Restart. This crop node runs locally - the FAL key is needed on the selector (if you use this pack's FAL one) and the editor, not here. And if depad_florence sounds familiar, it's the same rule as the rest of the pack: keep it True for Florence masks, False for SAM or hand-drawn ones that are already at exact resolution.
Inputs (18)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| context_expand | FLOAT | 1.151–4 | Grow the detected mask region before cropping. |
| use_region_guidance | BOOLEAN | true | Use Florence region metadata to override context and target size when available. |
| mask_expand_percent | FLOAT | 0.00–100 | Extra expansion applied to the edit mask after crop. 0 uses region defaults when guidance is enabled. |
| mask_feather_percent | FLOAT | 0.00–100 | Softens the edit mask edges after crop. 0 uses region defaults when guidance is enabled. |
| resize_mode | COMBO | upscale_to_target_if_smaller | 3 options: keep_local_size, upscale_to_target_if_smaller, resize_to_target |
| target_width | INT | 102464–16384 | — |
| target_height | INT | 102464–16384 | — |
| downscale_algorithm | COMBO | bilinear | 6 options: nearest, bilinear, bicubic, lanczos, box, hamming |
| upscale_algorithm | COMBO | bicubic | 6 options: nearest, bilinear, bicubic, lanczos, box, hamming |
| device_mode | COMBO | gpu (much faster) | 2 options: gpu (much faster), cpu (compatible) |
| depad_florence | BOOLEAN | true | Remove Florence2's internal square letterbox padding before resizing the mask. Keep True when the mask comes from Florence2Run (kijai). Disable only if your mask is already at the exact source image resolution. |
| use_region_mask_defaults | BOOLEAN | true | When enabled, 0 mask expand/feather values use Florence region defaults. Disable it when you need a hard mask. |
| edit_size_scale_percent | FLOAT | 10025–200 | Scale the edit output resolution as a percentage of the target. 100 = full region recommended size (e.g. 2752x1536 for glasses). 50 = half size, 150 = 150%%. Preserves aspect ratio. The scaled size flows via info to GPT Image nodes using auto_from_region, so both crop and output stay aligned. |
| region_infoopt | STRING | — | |
| target_size_modeopt | COMBO | region_recommended | region_recommended uses Florence/region defaults; manual_width_height uses target_width/target_height; max_for_aspect_ratio uses the largest valid GPT Image size for target_aspect_ratio. |
| target_aspect_ratioopt | COMBO | region_info | Aspect ratio used when target_size_mode is max_for_aspect_ratio. |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| stitcher | STITCHER | — |
| cropped_image | IMAGE | — |
| cropped_mask | MASK | — |
| cropped_mask_image | IMAGE | — |
| preview_image | IMAGE | — |
| info | STRING | — |