Nodes/ComfyUI Impact Pack/Mask Rect Area (Advanced)
ComfyUI Node Runs on cloud

Mask Rect Area (Advanced)

A rectangular mask in exact pixels

By ltdrdata·Created 3 years ago·Updated 4 months ago· 3,242
Mask Rect Area (Advanced)
    • MASK
    x0
    y0
    width256
    height320
    image_width512
    image_height320
    blur_radius0

    This is the pixel-precise version of Mask Rect Area. Where the plain node works in percentages, Mask Rect Area (Advanced) works in exact pixels and asks you to state the image size explicitly. Set x: 40, y: 40, width: 256, height: 320 on a 512 x 320 canvas and you get precisely that rectangle, to the pixel. When you know the coordinates you want - because you pulled them from a detection, a crop, or a layout you're matching - this is the node that places the box exactly, with no proportional guesswork.

    The "advanced" label is doing a lot of work for what's still a very simple node. It's the same rectangle-drawing job, just addressed in pixels instead of ratios.

    How it works

    You describe a rectangle in pixel coordinates and declare the dimensions of the canvas it lives on. The node fills that rectangle white on a black mask sized to image_width x image_height. Because you name the image size, the mask comes out at the resolution you intend rather than inheriting one - which matters when you're compositing it against a specific image and can't afford a size mismatch.

    The inputs and outputs that matter

    • image_width / image_height - the size of the mask you're producing. Set these to match the image you'll apply the mask to, or you'll get a resolution mismatch downstream.
    • x / y - the top-left corner of the rectangle, in pixels.
    • width / height - the rectangle's size in pixels (defaults 256 x 320).
    • blur_radius (default 0) - feathers the edge. Keep at 0 for a hard box; raise it so a downstream inpaint blends cleanly.

    The single output is MASK, at image_width x image_height, ready for an inpaint, a detailer, a composite, or a mask operation.

    How to install it

    Ships in the Impact Pack. ComfyUI Manager: search ComfyUI Impact Pack, Install, restart. Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack comfyui-impact-pack
    cd comfyui-impact-pack
    pip install -r requirements.txt
    

    then restart. Nothing extra to download.

    Common issues & troubleshooting

    The mask doesn't line up with your image. Almost always a size mismatch: image_width/image_height must match the actual image you're masking. If your image is 1024x1024 and you left these at 512x320, the rectangle lands in the wrong place after resizing. Match them.

    Part of the rectangle is missing. It ran off the canvas. x + width can't exceed image_width, and y + height can't exceed image_height - anything past the edge just gets clipped. Add the corner to the size and check it fits.

    You'd rather work in proportions. If you want a mask that stays the same relative size regardless of resolution, use the plain Mask Rect Area node, which takes percentages. Use this Advanced one when you have concrete pixel coordinates and want them honored exactly.

    CategoryImpactPack/Operation

    Inputs (7)

    NameTypeDefaultDescription
    xINT0
    yINT0
    widthINT256
    heightINT320
    image_widthINT512
    image_heightINT320
    blur_radiusINT0

    Outputs (1)

    NameTypeDescription
    MASKMASK