ComfyUI Node

Smart Mask Crop

Crops a focused local region around a mask, keeping a local mask for mask-based editing models such as GPT Image.

By amortegui84·Created 5 months ago·Updated 2 months ago· 3
Smart Mask Crop
  • image
  • mask
  • stitcher
  • cropped_image
  • cropped_mask
  • cropped_mask_image
  • preview_image
  • info
context_expand1.15
use_region_guidancetrue
mask_expand_percent0.0
mask_feather_percent0.0
resize_modeupscale_to_target_if_smaller
target_width1024
target_height1024
downscale_algorithmbilinear
upscale_algorithmbicubic
device_modegpu (much faster)
depad_florencetrue
use_region_mask_defaultstrue
edit_size_scale_percent100
region_info
target_size_moderegion_recommended
target_aspect_ratioregion_info
Categoryinpaint/masked

Inputs (18)

NameTypeDefaultDescription
imageIMAGE
maskMASK
context_expandFLOAT1.151–4Grow the detected mask region before cropping.
use_region_guidanceBOOLEANtrueUse Florence region metadata to override context and target size when available.
mask_expand_percentFLOAT0.00–100Extra expansion applied to the edit mask after crop. 0 uses region defaults when guidance is enabled.
mask_feather_percentFLOAT0.00–100Softens the edit mask edges after crop. 0 uses region defaults when guidance is enabled.
resize_modeCOMBOupscale_to_target_if_smaller3 options: keep_local_size, upscale_to_target_if_smaller, resize_to_target
target_widthINT102464–16384
target_heightINT102464–16384
downscale_algorithmCOMBObilinear6 options: nearest, bilinear, bicubic, lanczos, box, hamming
upscale_algorithmCOMBObicubic6 options: nearest, bilinear, bicubic, lanczos, box, hamming
device_modeCOMBOgpu (much faster)2 options: gpu (much faster), cpu (compatible)
depad_florenceBOOLEANtrueRemove 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_defaultsBOOLEANtrueWhen enabled, 0 mask expand/feather values use Florence region defaults. Disable it when you need a hard mask.
edit_size_scale_percentFLOAT10025–200Scale 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_infooptSTRING
target_size_modeoptCOMBOregion_recommendedregion_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_ratiooptCOMBOregion_infoAspect ratio used when target_size_mode is max_for_aspect_ratio.

Outputs (6)

NameTypeDescription
stitcherSTITCHER
cropped_imageIMAGE
cropped_maskMASK
cropped_mask_imageIMAGE
preview_imageIMAGE
infoSTRING