Skip to content

Draw Mask

Interactive node to draw a grayscale mask on a canvas and output it as a normalized tensor mask. It decodes the provided canvas image, resizes it to the specified dimensions, and ensures values are in the 0–1 range. If the canvas is empty (all black), it returns a zero mask with the requested size.
Preview

Usage

Use this node when you need a hand-drawn mask for image operations such as inpainting, blending, or selective processing. Configure canvas size and brush parameters in the UI, draw on the canvas, and connect the resulting mask to downstream nodes that accept MASK inputs.

Inputs

FieldRequiredTypeDescriptionExample
canvasTrueCANVASThe drawn canvas image encoded as a data URL string. Represents the grayscale mask drawn in the UI.data:image/png;base64,
widthTrueINTOutput mask width in pixels. Also controls the canvas aspect ratio in the UI.512
heightTrueINTOutput mask height in pixels. Also controls the canvas aspect ratio in the UI.512
brush_sizeTrueINTBrush diameter used in the drawing UI. Adjust to control stroke thickness.10
brush_colorTrueINTBrush intensity in grayscale from 0 (black) to 255 (white). Controls how strongly drawn areas contribute to the mask.255

Outputs

FieldTypeDescriptionExample
maskMASKA single-channel mask tensor with shape (1, height, width), normalized to 0–1. Matches the specified width and height.A tensor-like mask with values between 0.0 (black) and 1.0 (white) at size 1x512x512

Important Notes

  • Width and height must be between 32 and 2048 pixels; values outside this range are not allowed.
  • Brush size must be between 1 and 100; brush color must be between 0 and 255.
  • The mask is grayscale: 0 (black) indicates no mask, 1 (white) indicates full mask, intermediate values represent partial strength.
  • If the canvas is entirely empty/black, an all-zero mask is produced with the requested dimensions.
  • The input canvas is resized to the specified width and height, which may introduce smoothing.
  • The canvas input must be a valid data URL (e.g., PNG) encoded as base64.

Troubleshooting

  • Mask appears all zero: Ensure you drew with a non-zero brush_color and that the canvas contains non-black content.
  • Output size is unexpected: Confirm width and height are set as intended; the mask is always resized to these values.
  • Edges look soft or blurry: Resizing the canvas to different dimensions can soften edges; draw at the target size to minimize resampling artifacts.
  • Invalid canvas error or no output: Verify the canvas string is a properly formatted data URL (e.g., data:image/png;base64,<...>).
  • Downstream node rejects mask shape: Ensure the receiving node expects a single-channel mask with shape (1, H, W).

Example Pipelines

Example
Example