CV Crop by Masks
Crops around each mask of a MASK batch (e.g. from 'Connected Components', 'Labels to Masks' or 'K-Means Mask Clusters') - the mask-driven shorthand for 'OpenCV Masks to BBoxes' -> 'CV Crop by BBoxes', and it takes the SAME policy, so one 'Snap BBoxes' can drive both in lockstep. The policy MODE picks the use case: '-> batch' stacks every crop at one common size so they paste back losslessly (downstream runs once), '-> list' emits one item per region at its own tight size (downstream runs once per region). The source can be an IMAGE, MASK, NPARRAY or LATENT and the crops come back in the same type; masks are fitted to its size, so a LATENT source works with pixel-space masks. Also returns the matching cropped masks (for inpainting) and the crop regions as bounding boxes.
- image
- masks
- crops
- crop_masks
- bboxes
- region_index
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | COMFY_MATCHTYPE_V3 | What to crop. IMAGE / MASK / NPARRAY / LATENT; the crops come back in the same type. | |
| masks | MASK | One mask per region to crop (MASK batch). Several batches wired in are concatenated. | |
| padding | INT | 160–4096 | Extra context around each region in pixels - inpainting works better with surroundings included. |
| square | BOOLEAN | false | Force square crops (useful for diffusion inpainting). |
| policyopt | STRING | one source, regions -> batch | Which use case this crop serves. 'one source, regions -> batch' crops every region out of frame 0 at one common size and stacks them (the inpainting case - downstream runs once on the batch). '-> list' instead emits one item per region at its own tight size, so downstream runs once per region. The 'per-frame' modes pair region group g with frame g of a batch instead of always reading frame 0. Crop policy. In the UI this is a mode dropdown plus one widget per option; wire an 'CV Snap BBoxes' node in to drive several crop nodes from one place (the widgets then hide). A linked policy overrides only the fields it actually sets. The padding/square widgets above are the baseline; a policy overrides only the fields it sets. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| crops | COMFY_MATCHTYPE_V3 | One stacked batch (batch modes) or one item per region (list modes), in the source's own type. |
| crop_masks | MASK | Each region's mask cropped to its crop, fanned out in lockstep with 'crops'. |
| bboxes | BOUNDING_BOX | Core BOUNDING_BOX data: per-frame lists of {x, y, width, height} dicts - compatible with Draw BBoxes, Crop By Bounding Boxes, Image Crop, etc. Fanned out in lockstep with 'crops'. |
| region_index | NPARRAY | (B,) int32: which row of the input MASK batch each crop came from. Empty masks produce no crop, so this is what realigns the crops with the input batch. |