Nodes/ComfyUI_Element_high/EH - Crop From Mask
ComfyUI Node

EH - Crop From Mask

Point a mask at it and it crops the region for you

By heyzne·Created 3 months ago·Updated 3 months ago· 0
EH - Crop From Mask
  • image
  • mask
  • crop
  • crop_mask
  • crop_box
padding32
min_size256

EH - Crop From Mask is the difference between telling a computer the answer and telling it the problem. The sibling node, EH_CropImage, wants four coordinates you had to go measure. This one wants a mask, and it finds the rectangle itself: it takes your image and a mask, computes the bounding box of everything the mask covers, pads it out, and hands you a crop sized around exactly the region you care about.

This is the node that makes "only masked" inpainting painless, and that's a genuinely valuable thing in 2026. The crop-edit-stitch pattern is how people keep the parts of an image they want to keep: mask the jacket, crop tight around it, run your inpaint or edit pass on just that crop at a resolution the model can actually resolve, then merge the result back. Everything you didn't mask never enters the model at all, which is what makes the unmasked pixels come back identical. EH_CropFromMask is the "crop" half of that loop - feed it a mask from SAM, from a VLM grounding box converted to a mask, or painted by hand, and it does the geometry for you.

How it works: feed it image and mask (the two required inputs) and it scans the mask for pixels above 0.5, takes the min/max row and column to form the tight bounding box, then expands it by padding (default 32px) so the model gets context around the region instead of a knife-edge boundary. That padding is not optional fluff - it's the same lesson the grounding-mask crowd keeps relearning, that tight boxes need expansion or the model invents clutter at the edge. If the padded box is still smaller than min_size (default 256), it grows outward to reach the floor. Everything clamps to the image, and if the mask turns out to be empty it quietly falls back to cropping the center quarter rather than erroring - the only symptom you'll ever see is a crop bigger than you expected.

The two inputs you'll actually touch:

  • padding - context around the region in pixels. 32 is a good starting point; raise it if your model is ignoring the mask boundary, since more context gives the edit more to blend against.
  • min_size - a floor on crop size. Keep it near your model's native resolution so the crop gets the full generation budget.

Outputs: crop (the cropped pixels), crop_mask (the same mask, cropped to the identical box - image and mask stay in exact alignment, which is exactly what an inpaint node wants to consume), and crop_box (the rectangle, for bookkeeping or any BOX-aware node downstream).

The one trap is expecting it to be smarter than it is. It is a bounding box plus padding - no segmentation, no object awareness. A stray mask pixel in a corner grows the crop to include it, and two separate masked objects become one big box around both. Give it a clean mask and it's the smoothest part of this pack; give it a dirty one and you'll wonder why your crop is half the image.

To install, search ComfyUI_Element_high in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/heyzne/ComfyUI_Element_high

Restart and the four EH nodes appear under the "ElementHigh" category. No models to download, no extra pip deps beyond ComfyUI defaults (torch, numpy, opencv-python, Pillow). Ignore the README's install URL - it points at a dead supElement repo; this one lives at heyzne.

If you want a more proven version of the same idea, lquesada's Inpaint CropAndStitch is the battle-tested, widely-circulated choice for the whole crop-edit-stitch loop. Element_high is the lean, unproven alternative - this crop node is clean and does exactly what it says, just don't expect a track record to lean on yet.

CategoryElementHigh

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
maskMASK
paddingoptINT320–500
min_sizeoptINT25664–4096

Outputs (3)

NameTypeDescription
cropIMAGE
crop_maskMASK
crop_boxBOX