Nodes/ComfyUI-TextureAlchemy/Image + Mask Combiner
ComfyUI Node

Image + Mask Combiner

Keep your image and mask from drifting apart

By amtarr·Created 9 months ago·Updated 4 months ago· 58
Image + Mask Combiner
  • image
  • mask
  • image
  • mask
  • mask_preview

The most annoying thing about masks in ComfyUI is that they're a different tensor shape from images. An IMAGE is batch × height × width × channels; a MASK is batch × height × width. So the moment you want to do anything with both - overlay a mask preview, keep a painted region aligned with a texture, sanity-check what you're about to mask - you hit shape mismatches. Image + Mask Combiner is the tiny utility that eats the mismatch and hands you back a clean, aligned set of outputs.

Honestly, its real job is bookkeeping: it takes an IMAGE and a MASK, makes sure the mask is resized to the image's dimensions and batch count, and returns three things - the image untouched, the mask normalized, and a mask_preview (the mask repeated into RGB so you can actually see it in a Preview Image node).

How it works

It normalizes the mask to match the image: resizes with bilinear if the dimensions differ, pads or trims the batch to match, and flattens a 4-channel mask down to grayscale (or squeezes a 1-channel one). Then it builds the RGB preview by repeating the single mask channel across R, G, and B. The console also prints mask statistics - range, mean, and coverage percentage - which is a genuinely useful debugging readout. If you've ever connected a mask and wondered whether it's actually doing anything, the coverage number tells you instantly.

The inputs

  • image - any IMAGE.
  • mask - a MASK from Load Image's painted mask, MaskEditor, or any mask-producing node.

Outputs: image (passthrough), mask (resized/normalized), mask_preview (RGB visualization).

Where it fits

Use it anywhere you've got a texture and a hand-painted mask and need to confirm they line up. The typical flow: load your texture, paint a mask, route both through this node, and preview the result before committing to an inpainting or blending step. It's also the simplest bridge when a downstream node expects an IMAGE but only a MASK exists - wire the mask into the mask_preview output.

The one thing to know: this node takes a MASK on the input side, so if your mask is currently an IMAGE (grayscale), you'll need to convert it first. And the resize is purely to match the image's dimensions - it doesn't align a misaligned mask, it just rescales. If the mask was painted at a different aspect ratio, the result will be stretched, not fixed.

Installation

Part of amtarr/ComfyUI-TextureAlchemy, under Add Node → Texture Alchemist → Masks. Install via ComfyUI Manager (search "TextureAlchemy") or:

cd ComfyUI/custom_nodes
git clone https://github.com/amtarr/ComfyUI-TextureAlchemy

Restart ComfyUI. No dependencies, no models - a pure tensor utility.

CategoryTexture Alchemist/Masks

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
maskMASK

Outputs (3)

NameTypeDescription
imageIMAGE
maskMASK
mask_previewIMAGE