Transparent Image to Mask (TK)
Your PNG's alpha channel is already a mask — this node just makes it one
- image
- mask
- mask
- mask_image
If you've ever dragged a transparent PNG into ComfyUI and then stared at the graph wondering how to get its transparency into a mask, this is the node you were looking for. TK_Image2Mask does exactly one job: pull the alpha channel out of an RGBA image and hand it to you as a proper ComfyUI MASK, plus an RGB preview you can actually see. It ships in a single-file pack from tackcrypto1031, sits under the TK_Nodes category, and is the kind of plumbing that looks trivial until you need it for the tenth time.
Masks are the glue of half the workflows you'll build. Background removal gives you an RGBA cutout (BiRefNet, InSPyReNet, whatever you settled on); inpainting and compositing want a MASK; a bunch of other nodes - ControlNet preprocessors, IPAdapter, inpaint models - want an IMAGE. This node is the adapter between those worlds.
How it works
The whole thing is about thirty lines of torch, so it's worth knowing exactly what happens:
- If you wire the optional
maskinput, that mask becomes the alpha - the image's own alpha channel is ignored entirely. - Otherwise, if the image has 4 channels (
RGBA), it takes channel 3 as the alpha. - If there's no mask and no alpha, it assumes full opacity (a mask of all ones).
- If
invert_maskis on, it flips everything (1.0 - alpha). - The
maskoutput is that alpha as a single-channelMASK. Themask_imageoutput is1.0 - alpharepeated to three channels - white background, black masked areas - which is why it looks like a silhouette stamp instead of a cutout.
No magic, no API, no models. Just tensor slicing.
The inputs and outputs that matter
There are only two inputs you'll touch, really:
image- your RGBA source, straight from a Load Image node or from a background-removal pipeline.invert_mask(boolean, default off) - flip the mask logic. Handy when your cutout came out inverted, which happens more than anyone admits.
The optional mask input lets you pipe in a mask from elsewhere and run it through the same inversion + preview logic. The outputs are mask (wire into inpainting, compositing, anything that takes a MASK) and mask_image (feed into nodes that want an IMAGE, or just to look at what you actually extracted - the MASK type is invisible until you render it).
Installing it
Easiest path: ComfyUI Manager, search tk_comfyui_img2mask, install, restart. Manual route:
cd ComfyUI/custom_nodes/
git clone https://github.com/tackcrypto1031/tk_comfyui_img2mask
Then restart ComfyUI. That's it - no model downloads, no heavy dependencies. The pyproject only declares torch, which ComfyUI already ships. That's the refreshing part about this pack: for once, "install and go" is literal.
One heads-up: the README's own clone command contains YOUR_USERNAME in the URL - a copy-paste artifact, not a real repo. Use the URL above. And the bundled workflow/i2m_workflow.json isn't the minimal demo the README suggests; it's this node embedded inside a large SeedVR2 upscaling graph that pulls in several other packs. It's a reference for how the author uses it (feeding a mask resize step), not a clean starting point.
Gotchas
- The
maskinput overrides the alpha. Wire both in and your image's transparency is ignored. Load Image's second output is already the alpha as aMASK, so plugging it in just passes it through - fine, but know what you're doing. - No size matching. The source code literally says "We assume match." Feed an external mask that's a different size than your image and you'll get silent misalignment downstream, because ComfyUI doesn't auto-resize masks in every node.
- Do you even need it? Core ComfyUI ships an
ImageToMasknode with an alpha channel option, so a plain alpha→mask job doesn't strictly require this pack. WhereTK_Image2Maskearns its keep is convenience: inversion and the RGB preview built in, and the optional mask passthrough - a one-stop for PNG → mask → inpaint/composite work. If you do that constantly, install it. If it's once a month, the core node is fine.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| invert_mask | BOOLEAN | false | — |
| maskopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |
| mask_image | IMAGE | — |