Nodes/ComfyUI_Swwan/Image And Mask Preview (Swwan)
ComfyUI Node

Image And Mask Preview (Swwan)

See the mask on the image before you burn GPU time

By aining2022·Created 10 months ago·Updated about 18 hours ago· 33
Image And Mask Preview (Swwan)
  • image
  • mask
  • region_color
  • number_color
  • composite
◄mask_opacity1.00►
◄mask_color255, 255, 255►
◄pass_throughfalse►
◄preview_modestandard►
◄show_numbersfalse►
◄number_opacity0.8►
◄number_scale▾►
◄font_scale0.6►
◄number_fontFreeMono.ttf►

The mask QA node

Masks are invisible until they ruin a render. This node shows one on top of an image: the mask becomes a coloured overlay at the opacity you choose, so you can confirm a detection, an inverted alpha, or a hand-painted region before you spend two minutes sampling.

The pack's version is KJNodes' ImageAndMaskPreview with an extra trick bolted on from 孤海's Goohaitools toolbox - a regions preview mode that numbers and colour-codes segmented regions, which is the mode you want when the mask isn't one blob but seventeen.

Two other things it does: with only a mask wired it previews the mask as a greyscale image, and with only an image wired it just passes the image through. So it's a workable "show me whatever I have" node at the end of any branch.

Inputs

Required (all three sit as widgets, no wiring needed):

  • mask_opacity - 0 to 1, default 1. How strongly the overlay paints.
  • mask_color - default 255, 255, 255. Accepts an RGB triple in 0–255 or a hex string with the #; anything else is parsed as hex and will quietly misbehave, so don't type white.
  • pass_through - default False. See below, because this one changes the node's identity.

Optional:

  • image and mask - wire either or both.
  • preview_mode - standard or regions.
  • region_color, show_numbers, number_opacity, number_scale, font_scale, number_font, number_color - the region-annotation controls, and only for regions mode. number_scale is Chinese-labelled (跟随遮罩缩放 = scale with the mask, 固定大小 = fixed size) and number_font offers a macOS face that the pack substitutes for FreeMono, because it doesn't ship that font.

Output: composite, one IMAGE.

pass_through is the important switch

With it off (the default) the node behaves like a preview: it writes a PNG into ComfyUI's temp directory and displays it. With it on it doesn't write a preview at all - it returns the composited image out of the composite socket so you can wire it onward. The author's framing is that this lets you pass a mask-highlighted image into a video combine node, and that's exactly the use: a debug view that's also a real frame in the pipeline.

The catch is worth stating plainly: in the default mode you should treat composite as empty and not wire anything to it. If a downstream node is complaining about a missing input and this node is upstream, pass_through is the first thing to check.

regions mode

Switch preview_mode to regions and the node composites the mask as numbered, coloured regions over the image - the QA view for segmentation output, a SEGS-to-mask pipeline, or a detector whose blobs you need to count. It requires both image and mask and raises Region Preview requires both image and mask if you forget one. region_color and number_color are COLORCODE sockets, which is where the pack's Color Converter comes in if you want those values driven by a wire instead of the picker.

There's a detail lurking in this mode: it binarises the mask at 0.5 before labelling. A soft, feathered mask will get hard edges in the preview - the preview is telling you where the mask is, not how soft it is.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan
cd ComfyUI_Swwan
python -m pip install -r requirements.txt

Manager → ComfyUI Swwan, restart ComfyUI, hard-refresh. No models and no optional pip packages for standard mode; the region path is PIL-based too.

Gotchas

Because it's a preview that writes to temp with a randomised prefix, its outputs aren't in your output folder and won't turn up in the gallery - same as core Preview Image. It also, like core previews, embeds the workflow metadata into that temp PNG, which is fine, but means the file has your graph in it if you go hunting for it later.

And the standard mask-overlay maths assumes the mask is a real mask, not 1 - alpha from a Load Image you forgot to invert. If the overlay is painted on everything except your subject, that's not this node - that's the alpha convention, and inverting upstream is the fix.

CategorySwwan/Advanced/IO

Inputs (13)

NameTypeDefaultDescription
mask_opacityFLOAT1.000–1—
mask_colorSTRING255, 255, 255—
pass_throughBOOLEANfalse—
imageoptIMAGE—
maskoptMASK—
preview_modeoptCOMBOstandard2 options: standard, regions
region_coloroptCOLORCODE#00ffff—
show_numbersoptBOOLEANfalse—
number_opacityoptFLOAT0.80–1—
number_scaleoptCOMBO2 options: 跟随遮罩缩放, 固定大小
font_scaleoptFLOAT0.60.1–2—
number_fontoptCOMBOFreeMono.ttf3 options: FreeMono.ttf, FreeMonoBoldOblique.otf, 苹方特粗.ttf
number_coloroptCOLORCODE#ffffff—

Outputs (1)

NameTypeDescription
compositeIMAGE—