Nodes/As_ComfyUI_CustomNodes/ImageMixMasked_As
ComfyUI Node

ImageMixMasked_As

Blend two images with a mask, in a single node

By flyingshutter·Created 3 years ago·Updated about a year ago· 8
ImageMixMasked_As
  • image_to
  • image_from
  • mask
  • IMAGE

ImageMixMasked_As is the image-space version of a masked composite: take two images and a mask, and where the mask is bright you see image A, where it's dark you see image B. One node, three inputs, one IMAGE out. It's the sibling of LatentMixMasked_As from the same pack, just operating on pixels instead of latent tensors.

This comes from flyingshutter's As_ComfyUI_CustomNodes pack - a self-described playground, no guaranteed support - and it has no dependencies beyond the torch/PIL/NumPy that ComfyUI already bundles. No model files, no weights, nothing to download.

How it works

The math is a per-channel linear blend, done three times (once per RGB channel):

out = image_to * mask + image_from * (1 - mask)

Where the mask is 1, you keep image_to; where the mask is 0, you keep image_from; everywhere in between you get a soft mix, which makes feathered mask edges blend naturally. A mask with a hard edge gives a hard composite; a blurred mask gives a smooth gradient transition.

The inputs that matter

  • image_to - the image that shows through where the mask is bright.
  • image_from - the image that shows where the mask is dark.
  • mask - a single-channel MASK, same spatial size as the images.

That's the whole list. One note on the code: it only operates on the first image in the batch (image_out[0,...]), so if you feed a batch of multiple images, only the first gets blended. Keep it to single images.

Where you'd use it

This is the natural finishing step for region-based workflows. Common loop: generate a full image, crop out a face or object, regenerate just that region, then use a mask to blend the new result back into the original. CropImage_AS handles the crop, this node handles the blend, and it's a lot more forgiving than a hard paste because you control the feather. You can also use it as a poor man's img2img strength - mix the original with a fresh generation using a gradient mask to get a smooth "how much do I want to change this" dial.

Installing it

cd ComfyUI/custom_nodes
git clone https://github.com/flyingshutter/As_ComfyUI_CustomNodes

Restart ComfyUI and it shows up under ASNodes - or search "As_ComfyUI_CustomNodes" in ComfyUI Manager and click install. There's no requirements.txt; the pack is intentionally dependency-free.

Common issues

The main gotcha is mask dimensions. The node does no resizing - the mask is multiplied against the image tensors as-is. If your mask is a different resolution than your images, broadcasting either errors out or silently produces a mess. If you're making masks at a different size (say, from a VAE-decoded latent at a different resolution), resize the mask first. Relatedly, check your mask's channel shape: it should be single-channel MASK, not an IMAGE. If you only have an RGB image with an alpha channel, run it through ImageToMask_AS from this same pack first.

Given that it does one thing and does it directly, the list of failure modes is short. The one worth repeating: mask size must match image size, or the blend goes sideways fast.

CategoryASNodes

Inputs (3)

NameTypeDefaultDescription
image_toIMAGE
image_fromIMAGE
maskMASK

Outputs (1)

NameTypeDescription
IMAGEIMAGE