Contour To Mask
Turn one contour back into a filled mask
- image
- contour
- IMAGE
Contours finds the shapes; this node closes the loop. Contour To Mask takes a single contour and a reference image, and draws that contour filled into a blank canvas the same size as the reference - giving you back a solid binary silhouette you can use as a mask or wire into any image-based workflow.
If your pipeline is "segment a photo, find contours, then act on one specific shape," this is the node that turns a boundary back into something usable.
How it works
Mechanically it's OpenCV's drawContours with thickness -1 (fill) onto a black image sized like the reference image input:
- image - used for two things: its dimensions define the output canvas, and it's the context you're masking against. Pass the original image here, not a shrunken version, or the mask will be the wrong size.
- contour - a single
CV_CONTOUR, fromContours' list output orGetContourFromList. - output_format -
RGB(default) orGRAY. Both produce the same filled silhouette; RGB gives you a white shape on black across three channels, GRAY a single-channel image. If the downstream node wants a proper mask (single channel), pick GRAY.
Output: one IMAGE. Note it's still an IMAGE, not the core MASK type - ComfyUI's mask-typed ports are separate. If you need a genuine MASK, many ComfyUI nodes accept a grayscale image as mask-like input, or you can feed the GRAY output through a converter.
Where it slots in
A typical contour workflow in this pack:
- Threshold a grayscale version of your image.
Contours→ getCV_CONTOURSandCV_CONTOUR.- Use
Filter ContourorGetContourFromListto pick the shape you care about. Contour To Maskto get the filled mask.- Composite, inpaint with it, or stack it with other masks.
The gotcha that bites people: canvas size comes from the image input, not from the contour. A contour from a downscaled source fed with a full-size reference gives you a correctly-scaled canvas but a contour whose coordinates no longer line up. Keep the source image dimensions consistent between Contours and Contour To Mask.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_bmad_nodes
cd comfyui_bmad_nodes
pip install -r requirements.txt
or install "comfyui_bmad_nodes" via ComfyUI Manager and restart. OpenCV does the drawing; no models, no downloads beyond the pack's shared requirements. If you're already using Contours, this is the natural next step in the chain.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| contour | CV_CONTOUR | — | |
| output_format | COMBO | RGB | 2 options: RGB, GRAY |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |