Imagen Mask Editing
Inpaint, outpaint, and background swap without touching a checkpoint
- image
- mask
- computed_mask
- IMAGE
This is the editing workhorse of the Vertex AI pack. It takes one image, a prompt, and a mask - or a computed mask - and returns an edited image from Imagen 3, Google's flagship image model. Background swap, object removal, outpaint, and insertion all run through this single node, and the quality is noticeably above what most local inpaint models manage on hard cases like reflections and shadows.
What it does
Four edit modes, picked by the edit_mode dropdown:
EDIT_MODE_INPAINT_REMOVAL- erase what the mask covers; the prompt describes what the rest of the image should stay like.EDIT_MODE_INPAINT_INSERTION- replace the masked region with something new, described in the prompt.EDIT_MODE_BGSWAP- keep the foreground, replace the background. The classic product-shot move.EDIT_MODE_OUTPAINT- extend the image beyond its edges. The mask defines the known region to keep.
You run one of two Imagen models, imagen-3.0-capability-001 or -002, the newer one being the one to reach for first.
How it works
The node uploads your source image and mask to Imagen as reference images and calls the edit_image API. Two details are worth knowing. First, the mask must come from exactly one source: either a hand-drawn mask (the standard ComfyUI MASK type) or a computed_mask from the Imagen Compute Mask node. Feed it both or neither and it raises an error - this is the top cause of "why is my edit node screaming." Second, your hand-drawn mask gets binarized at a 127/255 threshold before it goes up, so a soft feathered mask is not what arrives at the API.
Inputs that matter
- image - the source, any ComfyUI
IMAGE. - prompt - what should happen to the masked area. For removal, describe the rest of the image; for insertion/bgswap, describe the new content.
- mask or computed_mask - exactly one, see above.
- mask_dilation - grow or shrink the mask,
-1(default) lets the API decide. - base_steps and guidance_scale - leave at
-1to defer to the API; set them when you want explicit control. - seed, number_of_images (1–4), safety_filter_level, person_generation, output_mime_type - the standard Imagen knobs.
Output is a single batched IMAGE, straight into any preview or save node.
Installing
Pack install as usual - ComfyUI Manager searching "Vertex AI", or:
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
Plus the pack-wide setup: gcloud auth application-default login, then GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION (defaults to us-central1) either exported or typed into the node. This is a paid API call - per-image pricing - and it needs the Vertex AI / Imagen API enabled on a billing-backed project.
Where people get burned
- "No valid images were returned" - almost always the safety filters, occasionally a prompt that describes something Imagen refuses. The node passes through the RAI reason, so check the console output.
- The mask-or-computed-mask rule. One, not zero, not two. Design the graph so the choice is obvious.
- Editing with a low-res mask. Since the mask is thresholded, draw it cleanly; a sketchy mask comes back as a chunky edit.
For background swap specifically, pair this with the Compute Mask node in MASK_MODE_BACKGROUND mode and you get a one-click product-shot pipeline that would take half a dozen local nodes and a lot of fiddling.
Inputs (16)
| Name | Type | Default | Description |
|---|---|---|---|
| project_id | STRING | — | |
| location | STRING | us-central1 | — |
| prompt | STRING | — | |
| image | IMAGE | — | |
| model | COMBO | 2 options: imagen-3.0-capability-001, imagen-3.0-capability-002 | |
| edit_mode | COMBO | 4 options: EDIT_MODE_INPAINT_REMOVAL, EDIT_MODE_INPAINT_INSERTION, EDIT_MODE_BGSWAP, EDIT_MODE_OUTPAINT | |
| maskopt | MASK | — | |
| computed_maskopt | IMAGEN_COMPUTED_MASK | — | |
| mask_dilationopt | FLOAT | -1.00-1–1 | — |
| seedopt | INT | 38159722670–4294967295 | — |
| base_stepsopt | INT | -1-1–100 | — |
| guidance_scaleopt | INT | -1-1–500 | — |
| number_of_imagesopt | INT | 11–4 | — |
| safety_filter_levelopt | COMBO | 4 options: BLOCK_ONLY_HIGH, BLOCK_MEDIUM_AND_ABOVE, BLOCK_LOW_AND_ABOVE, BLOCK_NONE | |
| person_generationopt | COMBO | 3 options: ALLOW_ALL, ALLOW_ADULT, DONT_ALLOW | |
| output_mime_typeopt | COMBO | 2 options: image/png, image/jpeg |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |