Imagen Compute Mask
The node that doesn't call an API (in a good way)
- IMAGEN_COMPUTED_MASK
Most nodes in the Vertex AI pack fire off a paid API call the moment you run them. This one doesn't, and that's the whole point. Imagen Compute Mask is a pure config node - you pick a mode, it hands you an IMAGEN_COMPUTED_MASK object, and that object tells the Imagen Mask Editing node how to build its mask on Google's side.
Why you'd reach for it
When you edit an image with Imagen, the mask that defines what gets changed doesn't have to come from you. Imagen can compute it: "everything in the background," "everything in the foreground," or "everything that is a car." That's what this node encodes. You don't paint a single pixel - you describe the mask semantically, and the API does the segmentation when the edit actually runs. It's the difference between hand-masking a product photo and saying "just swap the background."
How it works
The node builds a MaskReferenceImage config and passes it downstream to the Imagen Mask Editing node's computed_mask input. It needs no project ID, no credentials, no model - nothing is sent anywhere at execution time. The real work happens later, inside the Imagen API, when the edit node merges this config with your source image.
The inputs (there are two, that's it)
- mask_mode - one of three:
MASK_MODE_BACKGROUND,MASK_MODE_FOREGROUND, orMASK_MODE_SEMANTIC. - semantic_class - only relevant for semantic mode. A dropdown of 194 classes the segmentation understands:
car,person,backpack,hot_dog,skis,swimming_pool, you name it. It's a surprisingly thorough list.
Pick MASK_MODE_SEMANTIC and a class like car, and the node errors out if you forget the class - it won't silently default. The other two modes ignore it.
The single output, IMAGEN_COMPUTED_MASK, wires straight into the computed_mask input on Imagen Mask Editing.
Installing and using it
You get it with the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/khanhlvg/vertex-ai-comfyui-nodes.git
cd vertex-ai-comfyui-nodes
pip install -r requirements.txt
Then restart ComfyUI. There's no per-node setup because this node is inert - the project/region/auth requirements belong to the Imagen Mask Editing node it feeds. If that node already works in your graph, this one just works.
The trap
Imagen Mask Editing accepts either a hand-drawn mask or a computed_mask from this node, never both, and never neither - it raises an error if you feed it two or zero. So decide which lane you're in before wiring. If you're doing background swap or background removal, computed masks are almost always the better lane: no masking by hand, and the segmentation is done by the same model that does the edit, so the mask and the change agree with each other.
A second, subtler gotcha: the computed mask is described in terms of the current image content, but it's applied during a specific edit pass. Semantic "person" plus EDIT_MODE_INPAINT_INSERTION works great; semantic modes don't make sense for outpaint, where there's no content to segment. Match the mode to the edit, and this little node saves you the most tedious part of image editing.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| mask_mode | COMBO | 3 options: MASK_MODE_BACKGROUND, MASK_MODE_FOREGROUND, MASK_MODE_SEMANTIC | |
| semantic_classopt | COMBO | 194 options: backpack, carrot, sidewalk_pavement, skis, umbrella, hot_dog, +188 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGEN_COMPUTED_MASK | IMAGEN_COMPUTED_MASK | — |