Private Image Mask
Make parts of an image transparent — and don't let the mask polarity catch you
- image
- mask_image
- image
Sometimes you don't want to generate a mask so much as spend one - you've got a cutout, and you want to punch a transparent hole in it: erase a region, hide a watermark, carve a shape out of a product shot before you composite it. PrivateImageMask does exactly one thing: it takes an image and a mask, and turns the bright parts of the mask into transparency. That's the whole node, and it's genuinely handy in an area where core ComfyUI makes you fumble through channel splits and image composites.
It's one of two nodes in the pack comfyui_private_postprocessor, a tiny toolbox last touched in mid-2024, with an empty README and no real community footprint. That means no bells and whistles - but it also means no dependencies. It's numpy, PIL, torch and cv2, all of which ComfyUI already ships.
How it works
Under the hood it's a short OpenCV pipeline, which is worth understanding because the polarity is easy to get backwards:
- Your
imageis converted to BGRA so it has an alpha channel to write into. - Your
mask_imageis converted to grayscale and binarized atmask_gray_threshold: pixels at or above the threshold become white, everything below becomes black. - That binary mask is inverted and used as the new alpha channel. Bright mask = alpha 0 = transparent. Dark mask = alpha 255 = fully visible.
That inversion is the gotcha. In most of ComfyUI, mask conventions run white = the region you act on (think inpainting masks). This node is the opposite: white in the mask means "cut this out." Feed it a standard white-subject-on-black mask expecting to keep the subject, and you'll get the subject deleted and the background kept. If that happens, invert your mask upstream (the Invert Image or mask-invert node) and you're set.
The inputs that matter
Three inputs, one of which does the real thinking:
image(IMAGE) - the image to be made transparent. The code assumes it carries alpha (it converts RGBA→BGRA), so feed it an RGBA cutout rather than a raw VAE decode.mask_image(IMAGE) - your selection, used as the transparency template. Any grayscale image works; a soft mask just gets thresholded into hard on/off.mask_gray_threshold(INT, default 127) - the brightness cutoff. Mid-grey and brighter become transparent. Drop it toward 0 and almost everything gets cut out; raise it toward 255 and only the brightest pixels do. Think of it as the "how much do I erase" dial.
Output: a single image (IMAGE) with the new alpha baked in, ready to wire into anything that composites transparent images. One note: if your input is a batch, the same mask is applied to every frame - there's no per-frame mask handling.
Install
ComfyUI Manager → search comfyui_private_postprocessor, or:
cd ComfyUI/custom_nodes
git clone https://github.com/githubYiheng/comfyui_private_postprocessor
Restart ComfyUI and you're done - no pip install, no model downloads.
The honest verdict
It's a one-trick node from a pack nobody maintains, and it shows: no error handling to speak of, an OpenCV call that'll throw if your input lacks alpha, and a mask polarity that will bite you exactly once. But that one trick - turning a mask into an alpha channel in a single click - is fiddly to assemble from core nodes, and when you need it, it's nice to have the shortcut. Keep the inversion in mind and it's a genuinely useful little blade.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask_image | IMAGE | — | |
| mask_gray_threshold | INT | 127 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |