Square Mask Region
Turn any mask into a clean, padded square crop area
- mask
- MASK
Masks from real sources are messy shapes - a hand-painted blob, an odd outline from a segmentation model, whatever a detector happened to draw around a face. Most of the time that's fine, but the moment you want to crop that region out and run it through another pass (a detail pass, an upscale, an edit model), an irregular mask is the wrong shape to crop with. This node takes any mask and gives you back the region that actually matters for cropping: a square, with some breathing room added around the edges.
It's one piece of a small three-node pipeline in this pack - this node squares off the region, CutImageByMask crops the source image to it, and PasteImageByMask blends the processed result back in afterward. Individually each node is trivial; together they're a manual, fully-controllable version of the detect-crop-refine-paste loop that packs like Impact Pack's FaceDetailer automate in a single node. The advantage of doing it by hand with these three is that the mask can come from anywhere, and you decide exactly what happens to the cropped region in between.
The two fields
mask(required) - the input mask, any shape.padding(default 0, range 0–512) - how many pixels of margin to add around the region before squaring it off. Zero gets you the tightest possible fit; a larger value gives the region processing step some context beyond the exact edge of the mask, which usually produces a cleaner blend once it comes back throughPasteImageByMask- a detail pass with no surrounding context tends to look pasted-in, and a bit of padding is the cheap fix for that.
The output is a single MASK - the squared, padded version, ready to feed into CutImageByMask (or anywhere else that just needs a clean square region to work with).
Installing it
Search ComfyUI-load-lora-from-url in ComfyUI Manager, or:
cd ComfyUI/custom_nodes
git clone https://github.com/bollerdominik/ComfyUI-load-lora-from-url
Restart ComfyUI. Pure mask math, no models involved, nothing to download.
Where people get burned
- Padding pushed the region off the edge of the image. If your masked area is near a border and you set a large padding value, the squared region can extend past the image bounds. Watch for this on small source images especially, and back the padding value off if the crop looks clipped or wrong.
- Skipping this node entirely and cutting straight from the raw mask. It works, but an irregular crop shape from
CutImageByMasktends to produce a worse blend once it's pasted back, simply because the processing step downstream didn't have consistent context to work with. If your final composite has a visible seam, this is one of the first things worth adding back in. - Treating padding like it needs to be large to matter. A little goes a long way - the point is giving the next step enough surrounding pixels to work with, not turning a tight detail crop into most of the image.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| padding | INT | 00–512 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |