Skip to content

Draw Mask

Interactive mask-drawing node that converts a user-drawn canvas into a single-channel grayscale mask. It outputs a normalized mask tensor sized to the specified width and height, with optional brush controls for an intuitive drawing experience.
Preview

Usage

Use this node when you need a custom mask for tasks like inpainting, region selection, or compositing. Configure the target width/height to match downstream processing, draw on the canvas in the UI, and pass the resulting mask to nodes that accept a MASK input.

Inputs

FieldRequiredTypeDescriptionExample
canvasTrueCANVASThe interactive drawing surface input. Expects a data-URL image string from the UI representing the drawn mask in grayscale.data:image/png;base64,
widthTrueINTOutput mask width in pixels. Also updates the canvas aspect ratio in the UI.512
heightTrueINTOutput mask height in pixels. Also updates the canvas aspect ratio in the UI.512
brush_sizeTrueINTBrush size used in the UI while drawing. Does not change output scaling; purely a drawing control.10
brush_colorTrueINTBrush intensity in grayscale (0 = black, 255 = white) used in the UI while drawing.255

Outputs

FieldTypeDescriptionExample
maskMASKA single-channel normalized mask tensor shaped (1, height, width), with values in [0.0, 1.0] derived from the drawn canvas.MASK tensor with shape (1, 512, 512)

Important Notes

  • Normalization: The mask is normalized to [0.0, 1.0] from the grayscale canvas (0 = black, 1 = white).
  • Resizing: The drawn canvas is resized to the specified width and height before output. Set width/height to match downstream nodes.
  • Empty mask handling: If the canvas is fully empty (all pixels black), the node returns a zero mask with the specified width/height even if the canvas image size differs.
  • Brush controls: brush_size and brush_color only affect the UI drawing experience; they do not alter the mask after it is drawn.
  • Input format: The canvas must be a data-URL string containing a base64-encoded image.

Troubleshooting

  • Mask dimensions don't match downstream expectations: Ensure width and height here match what later nodes require.
  • Mask appears all black or all white: Verify brush_color and drawing on the canvas; remember that 0 is black (0.0) and 255 is white (1.0).
  • No effect from changing brush_size/brush_color: These settings only affect the drawing UI. Redraw after adjusting them.
  • Canvas not recognized: Provide a valid data-URL image string (e.g., data:image/png;base64,).

Example Pipelines

Example
Example