Crop Disjoint Mask Regions
Cut Every Separate Blob Out of a Mask, Straight Into a Tidy Batch
- image
- mask
- cropped_images
- cropped_masks
- blank_masks
- bounding_boxes
"Crop Disjoint Mask Regions" is the workhorse of the Pixel-Forge pack: give it an image and a mask, and it finds every separate region in that mask, crops each one out with padding, and hands you the results as a batch. It's the "detect and crop" half of the classic crop-and-stitch loop that ComfyUI users have been building by hand since Impact Pack's FaceDetailer made the pattern famous: find a region, crop it, process it at proper resolution, paste it back. This node automates the first two steps.
The inputs that matter
image(IMAGE) - what gets croppedmask(MASK) - tells it where the regions arepadding(INT, default 64, step 8) - how much breathing room around each region. 0 = tight crop right on the mask edge; crank it up when you want context around each blob.
Mechanically, it labels connected regions in the mask (8-connectivity, via scipy's ndimage.label), crops each labeled blob plus your padding, then resizes every crop to a fixed height of 512px, keeping aspect ratio. Then - this is the bit that makes it batch-friendly - it normalizes all the crops to the same width (the narrowest one after resizing) so they stack into a single rectangular IMAGE batch. No ragged edges, no variable-size batch.
The outputs and where they go
cropped_images(IMAGE) - the batch of region crops, all 512 tallcropped_masks(MASK) - the mask, cropped and resized to match each crop, so crop/mask pairs stay alignedblank_masks(MASK) - an all-black mask batch, same shape. It exists because the pack's similarity nodes expect masks, blank masks and boxes to travel together; if you're not using those, ignore it.bounding_boxes(BOX) - the padded crop coordinates in the original image. These are gold: they're exactly what Paste Image Batch by BBox needs to stitch the crops back where they came from.
So the natural pipeline is: this node → process or match the crops → PasteByBoundingBoxBatch with the returned boxes. Add Image Similarity (Sequential CLIP) in the middle and you have the full detect-crop-match-paste loop this pack is built around.
Things that bite
- Batch size is 1. The node raises a ValueError if
imageormaskcomes in with more than one image. Squeeze to a single frame first. - The 512 resize can soften things. Small blobs get upscaled to 512, and upscaling never adds detail. That's fine for matching or compositing work; it's wrong if you needed pixel-faithful crops.
- An empty mask returns empty tensors, which downstream nodes may or may not handle gracefully - guard for it in logic-heavy workflows.
Install
ComfyUI Manager → search "ComfyUI-Pixel-Forge" → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/ThunderBolt4931/comfyui_pixel_forge
restart, and it's under Pixel_Forge/Utils. No model downloads for this node; the pack's scipy requirement is what powers the region labeling, and it installs with the pack.
Final word: this pack is brand new (December 2025, no community footprint yet) and the README documents none of the nodes - the behavior above is straight from the source. For a crop-and-stitch loop this node is genuinely handy, but treat the whole pack as early software: verify outputs before you build a 40-node workflow on it.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| padding | INT | 640–1024 | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| cropped_images | IMAGE | — |
| cropped_masks | MASK | — |
| blank_masks | MASK | — |
| bounding_boxes | BOX | — |