Nodes/SaltAI-Open-Resources/Mask Batch Crop Region
ComfyUI Node

Mask Batch Crop Region

Find and crop to a mask's region, with coordinates to paste back later

By get-salt-AI·Created 2 years ago·Updated 2 years ago· 84
Mask Batch Crop Region
  • masks
  • cropped_masks
  • crop_data_batch
  • top_int
  • left_int
  • right_int
  • bottom_int
  • width_int
  • height_int
padding24
region_type

This is the node that finds where your mask actually is and hands you both a cropped version and the coordinates, in one step - and it's the one that pairs directly with SaltCropImageLocation elsewhere in this same pack. Mask Batch Crop Region outputs a crop_data_batch, and SaltCropImageLocation has an optional input of exactly that type. Wire them together and you get the standard detection → crop → process → paste-back pattern, the same shape as Impact Pack's FaceDetailer workflow, just built out of Salt's own primitives.

How it works

Find the region, crop tight to it with some margin so you don't cut right at the edge, do your actual work on the tighter crop, then use the crop data to know exactly where to paste the result back. region_type picks whether it locks onto the dominant (largest) masked region in the batch or the minority (smallest) one - dominant is what you want almost always; minority is a genuinely unusual choice, useful only if you're deliberately isolating a small secondary detail that happened to also get masked.

The inputs and outputs that matter

  • masks (required, MASK).
  • padding (required, default 24, 0–4096) - margin in pixels added around the detected region before cropping. Always give yourself some; a zero-padding crop right at the mask boundary tends to produce visible seams once you composite the result back later, the same reason mask blur/feathering (typically 4–12px) matters in ordinary inpainting workflows.
  • region_type (required, enum: dominant / minority) - almost always leave this on dominant.

Outputs: cropped_masks (the crop applied to the mask itself), crop_data_batch (feed straight into SaltCropImageLocation to crop the matching image the same way), and six raw INTs - top_int, left_int, right_int, bottom_int, width_int, height_int - if you'd rather wire coordinates manually into something that doesn't understand CROP_DATA_BATCH.

How to install it

ComfyUI Manager: search SaltAI-Open-Resources or SaltAI, install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/get-salt-AI/SaltAI

then restart. OpenCV-backed, no model download.

Common issues & troubleshooting

Error or degenerate crop on an empty mask. An all-black mask has no dominant region to find. Make sure whatever produced your mask (CLIPSeg, SAM, hand-drawn) actually found something before this node runs - check it upstream rather than debugging the crop step first.

Crop size varies image to image across a batch. If subject sizes differ across your batch, "dominant" is computed per image, so the crop dimensions won't be uniform - that's expected, not a bug. Anything downstream that assumes a fixed crop size across the batch will choke on it; resize after cropping if you need consistency.

Visible seam after pasting the processed crop back. Usually not enough padding - raise it so the crop includes a margin beyond the exact mask boundary, giving whatever you did to the cropped region room to blend before you paste it back over the original.

CategorySALT/Masking/Process

Inputs (3)

NameTypeDefaultDescription
masksMASK
paddingINT240–4096
region_typeCOMBO2 options: dominant, minority

Outputs (8)

NameTypeDescription
cropped_masksMASK
crop_data_batchCROP_DATA_BATCH
top_intINT
left_intINT
right_intINT
bottom_intINT
width_intINT
height_intINT