Mask Crop
MaskCrop is a rectangle slice of your mask — read the defaults before you trust them
- mask
- cropped_mask
MaskCrop does exactly one thing: it slices a rectangular region out of a MASK and returns the smaller mask. No detection, no smart bbox finding, no upscaling. The whole implementation is one line - mask[0, top:bottom, left:right] - so this is about as thin a utility as the ComfyUI-AIB pack ships. If that's all you need, it's fine. But you need to know what the numbers mean, because the defaults are a trap.
It exists to serve the local-detail pattern: crop a mask down to a small region, run a high-res pass on just that area, and stitch it back. That's the same crop-and-stitch idea that became the standard inpainting workflow - give a small region its own full-resolution generation budget instead of wasting it on the whole frame. Inside the AIB pack it pairs naturally with AutoDoubleEyelidMask: grab just the left eye's mask, crop it, and detail only that eye.
Inputs and outputs
- mask (
MASK) - what you're cropping. - top, left, right, bottom (
INT, min 0) - the crop box in absolute pixel coordinates. - cropped_mask (
MASK) - the slice.
That's the trap. These are not percentages, not widths, and not relative to anything - they're raw pixel indices into the mask, in [top:bottom, left:right] order. The defaults are top=0, left=0, right=100, bottom=100, which means "crop the top-left 100×100 pixel square." For a 512×512 mask that's a tiny corner chunk, almost certainly not what you meant. If you set these by hand, set all four.
Where it bites
A few behaviors worth knowing, all from the actual code:
- No clamping, silently. Values past the mask edge just crop to the edge - numpy slices don't error. But if
bottomis belowtop, orrightbelowleft, you get a zero-size mask, which will error in whatever node eats it downstream. - Batches collapse. It hard-codes
mask[0], so a batch of masks becomes one crop. Keep your input single-frame. - It doesn't resize. The output is whatever pixels you sliced, no scaling. Feed it to a sampler expecting a different resolution and you're setting up a mismatch.
If you just need a bbox crop and want width/height instead of two corner coordinates, core ComfyUI's CropMask node does the same job with friendlier parameters - this one's appeal is being dead simple and in mask space with no bbox to compute first.
Installing it
Same story as the whole AIB pack. ComfyUI Manager (search ComfyUI-AIB), or:
cd ComfyUI/custom_nodes
git clone https://github.com/maweiqiang1978/ComfyUI-AIB
then restart ComfyUI. No model files to download. The repo has no requirements.txt, and while MaskCrop itself only needs torch/numpy (both already in ComfyUI), its sibling AutoDoubleEyelidMask imports cv2 and mediapipe at module load - and both node files import those at the top. So if the pack fails to load at all, pip install mediapipe is the fix even though you're only using this crop node.
Honest verdict: it's a five-line utility with nothing clever in it, and the clever-adjacent thing it does have - the absolute-coordinate slicing - is exactly what trips people up. Set all four corners, keep it single-frame, and it crops masks fine.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| top | INT | 0 | — |
| left | INT | 0 | — |
| right | INT | 100 | — |
| bottom | INT | 100 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| cropped_mask | MASK | — |