Mask_image2mask
Four ways to turn an image into a mask, one node
- image
- mask
- invert_mask
Sometimes the mask you need isn't hand-painted or generated by a segmentation model - it's just sitting implicitly in an image's pixel values, and you need a way to pull it out. Mask_image2mask covers four different extraction methods in one node, switchable via mask_type, so you're not hunting for a different specialized node depending on which kind of extraction you need.
The four modes. White_Balance thresholds the image by brightness - everything between WB_low_threshold and WB_high_threshold (both 1–255) becomes mask, which is the mode you'd reach for on a high-contrast source where the region you want is simply brighter or darker than everything around it. color isolates pixels matching a specific hex color value within a tolerance set by color_threshold (0–255) - useful if you're working from a flat-color placeholder or a green-screen-style source where the region you want to mask is a known, consistent color. channel pulls a single color channel straight out as a mask - red, green, blue, or alpha - handy if you already have a source image where one channel was deliberately used to encode a mask (a common trick when passing mask data through pipelines that only carry RGB(A) images cleanly). depth extracts based on a depth value (default threshold 0.2), for pulling a mask out of a depth map rather than a color image.
Shared post-processing, regardless of mode. blur_radius (default 1, up to 32768) softens the mask edge - useful for avoiding hard, obviously-artificial boundaries in whatever you composite or inpaint afterward. expand (default 0, range −150 to 150) grows the mask outward with a positive value or shrinks it inward with a negative one, which is the standard move when your extracted mask is a pixel or two too tight or too loose around the actual region you care about.
Outputs - both directions, no extra node needed. mask is the extracted mask itself, and invert_mask is its inverse, output simultaneously. That's a small but genuinely convenient detail: a lot of workflows need both the mask and its opposite (mask the subject, invert to get the background, or vice versa), and this node saves you from adding a separate Invert Mask node just to get the second one.
Installing it. Standard for the whole pack - search "ComfyUI-Apt_Preset" in ComfyUI Manager, or clone directly:
cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git
Run install.bat on Windows for dependencies, then restart ComfyUI. Pure image processing, no external models or GPU dependency - it should work immediately once the pack imports cleanly.
Troubleshooting. If your extracted mask has ragged, noisy edges, increase blur_radius a bit before doing anything more drastic - it's the cheapest fix for a mask that looks technically correct but composites poorly. If White_Balance mode is grabbing more or less than you expect, remember it's a straightforward brightness threshold, not an edge-aware segmentation - on images with uneven lighting across the region you're trying to isolate, color or channel mode (if applicable to your source) will usually give a cleaner result than fighting with the threshold range. If the node doesn't appear after installing the pack, that's most likely the documented IMPORT FAILED issue from a missing dependency elsewhere in Apt_Preset - check your ComfyUI console log at startup and reinstall via Manager's "install missing custom nodes" rather than assuming this specific node is at fault.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask_type | COMBO | 4 options: White_Balance, color, channel, depth | |
| WB_low_threshold | INT | 11–255 | — |
| WB_high_threshold | INT | 2551–255 | — |
| color | STRING | #000000 | — |
| color_threshold | INT | 100–255 | — |
| channel | COMBO | 4 options: red, green, blue, alpha | |
| depth | FLOAT | 0.200–1 | — |
| blur_radius | INT | 11–32768 | — |
| expand | INT | 0-150–150 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |
| invert_mask | MASK | — |