Image Stroke by Mask
Put a colored outline around anything in your mask — the comic-label effect
- image
- mask
- image
- mask
You know that outlined-subject look - a character or object with a clean colored ring around its edge, like a sticker or a comic caption highlight? That's exactly what this node does. Give it an image and a mask of the region you care about, and it paints a stroke around that mask's boundary and lays it over your picture. It's one of those "small node, big effect" things you reach for when a plain cutout isn't enough and you want the subject to pop off the background.
It's genuinely useful in two spots: making subject overlays readable on busy backgrounds (labels, memes, sticker-style comps), and highlighting a detected region so you can eyeball what a segmentation pass found before you commit it to an inpaint. The mask output means you can also extract the stroke region itself and use it as a matte.
How it works
The mechanism is old-school morphology, and it's refreshingly simple. The node:
- Takes your
maskand dilates it with an elliptical kernel sized bystroke_width- that makes a slightly bigger version of your region. - Subtracts the original mask from the dilated one. The leftover ring is the stroke.
- Paints that ring in
stroke_color, then pastes the original image back on top using your original mask.
So the stroke hugs the outside of the region, and the region's own pixels stay untouched. Neat touch: it's batch-safe. Give it 8 images and 8 masks and it loops over the max batch, cycling shorter inputs, so you can outline a whole sequence of frames in one pass.
The stroke_color parser is worth knowing because it's more flexible than it looks. Default is 1.0 (white). Beyond that it accepts single-letter shorthands (r, g, b, y, k...), hex (#ff0000), named colors, and - the fun ones - a/average to use the image's average color, or mk/mask to use the average color inside your masked region, which is how you get an auto-matching outline that doesn't clash with the subject.
Inputs and outputs
imageandmask- required. The mask defines the region to outline.stroke_width- 0 to 1000, default 20. In pixels, roughly. 20 is a chunky ring at 1024²; drop to 4–8 for something subtle.stroke_color- the flexible string format above.
Outputs: image (original with stroke painted on) and mask (the stroke ring, with the original region filled in so it reads as a single usable matte).
Installing it
It's part of the 1hewNodes pack. In ComfyUI Manager, search "ComfyUI 1hewNodes" and install, then restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes
Then restart ComfyUI. This node runs on numpy/Pillow/OpenCV - no model downloads, no extra weights.
Common issues
The two things that bite people: mask and image size mismatch (the node resizes the mask to the image, so a tiny mask gets a fat, blurry outline - keep them at the same resolution for crisp edges) and expecting a soft outer glow. This is a hard-edged stroke, not a feather. If you want a glow, chain it into a blur. Also note the stroke extends outward from the mask boundary - if you wanted the outline to sit inside the region instead (for text-like effects), there's no inward mode here; the pack's newer Mask Stroke node covers the outer-stroke-with-union-output case if that's what you're really after.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| stroke_width | INT | 200–1000 | — |
| stroke_color | STRING | 1.0 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |