> [!CAUTION]
> **Caution:** The following table describes image generation endpoints that are deprecated and their replacements. We recommend updating your model endpoints before June 30, 2026, to avoid service disruption.
>
> | Discontinued endpoints | Recommended endpoint migration |
> |---|---|
> | `imagegeneration@002` | `gemini-2.5-flash-image` |
> | `imagegeneration@003` | `gemini-2.5-flash-image` |
> | `imagegeneration@004` | `gemini-2.5-flash-image` |
> | `imagegeneration@005` | `gemini-2.5-flash-image` |
> | `imagegeneration@006` | `gemini-2.5-flash-image` |
> | `imagetext@001` | `gemini-2.5-flash-image` |
> | `imagen-3.0-capability-001` | `gemini-2.5-flash-image` |
> | `imagen-3.0-capability-002` | `gemini-2.5-flash-image` |
> | `imagen-3.0-fast-generate-001` | `gemini-2.5-flash-image` |
> | `imagen-3.0-generate-001` | `gemini-2.5-flash-image` |
> | `imagen-3.0-generate-002` | `gemini-2.5-flash-image` |
> | `imagen-4.0-fast-generate-001` | `gemini-2.5-flash-image` |
> | `imagen-4.0-generate-001` | `gemini-2.5-flash-image` |
> | `imagen-4.0-ultra-generate-001` | `gemini-2.5-flash-image` |
>
<br />

This page describes how to remove objects from an image using a mask area, a
process also known as inpainting. You can provide your own mask or let
Imagen generate one for you.

The following models support removing objects from an image:

- [`imagen-3.0-capability-001`](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/models/imagen/3-0-generate.md.txt#3.0-capability-001)

## Content removal example


> [!NOTE]
> To see an example of Imagen 3 Editing,
> run the "Imagen 3 Image Editing" notebook in one of the following
> environments:
>
> [![](https://docs.cloud.google.com/static/vertex-ai/images/colab-logo-32px.png)Open in Colab](https://colab.research.google.com/github/GoogleCloudPlatform/generative-ai/blob/main/vision/getting-started/imagen3_editing.ipynb)
>
>
> \|
>
> [![](https://docs.cloud.google.com/static/vertex-ai/images/colab-enterprise-logo-32px.png)Open in Colab Enterprise](https://console.cloud.google.com/vertex-ai/colab/import/https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fgenerative-ai%2Fmain%2Fvision%2Fgetting-started%2Fimagen3_editing.ipynb)
>
>
> \|
>
> [![](https://docs.cloud.google.com/static/vertex-ai/images/vertex-ai-workbench-logo-32px.png)Open
> in Vertex AI Workbench](https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/generative-ai/main/vision/getting-started/imagen3_editing.ipynb)
>
>
> \|
>
> [![](https://docs.cloud.google.com/static/vertex-ai/images/github-logo-32px.png)View on GitHub](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/vision/getting-started/imagen3_editing.ipynb)

<br />

The following example uses inpainting and an image mask to remove content from
an existing image:

**Inputs**

| Base image^\*^ to edit | Mask area specified using tools in the Google Cloud console | Text prompt |
|---|---|---|
| ![Sample base image of a red couch that has a bag of lemons placed on the right and a throw pillow on the left corner. The couch is placed at an angle, with a single foot placed on a white area rug. In front of the couch on the area rug are two lemons.](https://docs.cloud.google.com/static/vertex-ai/generative-ai/docs/image/images/inpainting-remove_base-image.jpg) | ![The sample base image of the red couch is depicted, with masked areas defined for the bag of lemons on the couch and two lemons on the rug.](https://docs.cloud.google.com/static/vertex-ai/generative-ai/docs/image/images/inpainting-remove_mask-image.png) | Prompt: Remove selected objects from the image |

^\* *Image credit: [Inside Weather](https://unsplash.com/photos/red-fabric-sofa-dbH_vy7vICE) on [Unsplash](https://unsplash.com/).*^

**Output after specifying a mask area in the Google Cloud console**

|---|---|---|
| ![A sample edited image depicts the couch and rug in the input example without lemons](https://docs.cloud.google.com/static/vertex-ai/generative-ai/docs/image/images/inpainting-remove_output1.png) | ![A sample edited image depicts the couch and rug in the input example without lemons](https://docs.cloud.google.com/static/vertex-ai/generative-ai/docs/image/images/inpainting-remove_output2.png) | ![A sample edited image depicts the couch and rug in the input example without lemons](https://docs.cloud.google.com/static/vertex-ai/generative-ai/docs/image/images/inpainting-remove_output3.png) |


[View Imagen for Editing and Customization model card](https://console.cloud.google.com/vertex-ai/publishers/google/model-garden/imagen-3.0-capability-001)

## Before you begin

1. Set up authentication for your environment.

   Select the tab for how you plan to use the samples on this page:

   ### Console


   When you use the Google Cloud console to access Google Cloud services and
   APIs, you don't need to set up authentication.

   ### REST


   To use the REST API samples on this page in a local development environment, you use the
   credentials you provide to the gcloud CLI.
   1. [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.
   2. If you're using an external identity provider (IdP), you must first [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud.md.txt).


   For more information, see
   [Authenticate for using REST](https://docs.cloud.google.com/docs/authentication/rest.md.txt)
   in the Google Cloud authentication documentation.

## Remove with a defined mask area

Use the following samples to specify inpainting to remove content. In these
samples you specify a base image, a text prompt, and a mask area to modify
the base image.

### Console

1.
   In the Google Cloud console, go to the **Vertex AI \> Vertex AI Studio** page.


   [Go to Vertex AI Studio](https://console.cloud.google.com/vertex-ai/studio/media/generate;tab=image)
2.
   Click **Generate media**.

3.
   Click **Image**.

4. From the **Task** list, select **Inpaint-remove**.

5. From the **Model** list, select the Imagen model to use.

6. In **Input image** click **Add** and select the image that you are editing
   to upload.

7. In the **Prompt** box, enter a prompt that describes how to edit the image.

8. Do one of the following to specify a mask:

   - Upload your own mask:
     1. Create a mask on your computer.
     2. Click upload **Import mask** and select a mask to upload.
   - Define your mask: in the editing toolbar, use the mask tools (**box** , **brush** , or masked_transitions **invert** tool) to specify the area or areas to add content to.
9. Click **Run**.

### REST

For more information about the Imagen API, see the following:

<br />

- [Method:
  `endpoints.predict`](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/projects.locations.endpoints/predict)
- [`VisionGenerativeModelInstance`](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/Shared.Types/VisionGenerativeModelInstance)
- [`VisionGenerativeModelParams`](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/Shared.Types/VisionGenerativeModelParams)
- [`VisionGenerativeModelResult`](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/Shared.Types/VisionGenerativeModelResult)


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: Your Google Cloud [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifying_projects).
- <var translate="no">LOCATION</var>: Your project's region. For example, `us-central1`, `europe-west2`, or `asia-northeast3`. For a list of available regions, see [Generative AI on Vertex AI locations](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/learn/locations-genai). When a regional API endpoint is used, the region from the endpoint's URL determines where the request is processed, and this `LOCATION` in the resource path is ignored if it conflicts.
- `prompt`: For image outpainting you can provide an empty string to create the edited images. If you choose to provide a prompt, use a description of the masked area for best results. For example, "*a blue sky*" instead of "***insert** a blue sky*".
- `referenceType`: A `ReferenceImage` is an image that provides additional context for image editing. A normal RGB raw reference image (`REFERENCE_TYPE_RAW`) is required for editing use cases. At most one raw reference image may exist in one request. The output image has the same height and width as raw reference image. A mask reference image (`REFERENCE_TYPE_MASK`) is required for masked editing use cases. If a raw reference image is present, the mask image has to be the same height and width as the raw reference image. If the mask reference image is empty and `maskMode` is not set to `MASK_MODE_USER_PROVIDED`, the mask is computed based on the raw reference image.
- <var translate="no">B64_BASE_IMAGE</var>: The base image to edit or upscale. The image must be specified as a [base64-encoded](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/image/base64-encode.md.txt) byte string. Size limit: 10 MB.
- <var translate="no">B64_OUTPAINTING_MASK</var>: The black and white image you want to use as a mask layer to edit the original image. The mask should be same resolution as input image. The output image will be the same resolution as the input image. This mask image must be specified as a [base64-encoded](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/image/base64-encode.md.txt) byte string. Size limit: 10 MB.
- <var translate="no">MASK_DILATION</var> - float. The percentage of image width to dilate this mask by. A value of `0.03` is recommended for outpainting. Setting `"dilation": 0.0` might result in obvious borders at the extension point, or might cause a white border effect.
- <var translate="no">EDIT_STEPS</var> - integer. The number of sampling steps for the base model. For outpainting, start at `35` steps. Increase steps if the quality doesn't meet your requirements.
- <var translate="no">EDIT_IMAGE_COUNT</var> - The number of edited images. Accepted integer values: 1-4. Default value: 4.


HTTP method and URL:

```
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict
```


Request JSON body:

```
{
  "instances": [
    {
      "prompt": "",
      "referenceImages": [
        {
          "referenceType": "REFERENCE_TYPE_RAW",
          "referenceId": 1,
          "referenceImage": {
            "bytesBase64Encoded": "B64_BASE_IMAGE"
          }
        },
        {
          "referenceType": "REFERENCE_TYPE_MASK",
          "referenceId": 2,
          "referenceImage": {
            "bytesBase64Encoded": "B64_OUTPAINTING_MASK"
          },
          "maskImageConfig": {
            "maskMode": "MASK_MODE_USER_PROVIDED",
            "dilation": MASK_DILATION
          }
        }
      ]
    }
  ],
  "parameters": {
    "editConfig": {
      "baseSteps": EDIT_STEPS
    },
    "editMode": "EDIT_MODE_OUTPAINT",
    "sampleCount": EDIT_IMAGE_COUNT
  }
}
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict" | Select-Object -Expand Content
```
The following sample response is for a request with `"sampleCount": 2`. The response returns two prediction objects, with the generated image bytes base64-encoded.

```
{
  "predictions": [
    {
      "bytesBase64Encoded": "BASE64_IMG_BYTES",
      "mimeType": "image/png"
    },
    {
      "mimeType": "image/png",
      "bytesBase64Encoded": "BASE64_IMG_BYTES"
    }
  ]
}
```

<br />

<br />

## Remove with automatic mask detection

Use the following samples to specify inpainting to remove content. In these
samples you specify a base image and a text prompt. Imagen
automatically detects and creates a mask area to modify the base image.

### Console

1.
   In the Google Cloud console, go to the **Vertex AI \> Vertex AI Studio** page.


   [Go to Vertex AI Studio](https://console.cloud.google.com/vertex-ai/studio/media/generate;tab=image)
2.
   Click **Generate media**.

3.
   Click **Image**.

4. From the **Task** list, select **Inpaint-remove**.

5. From the **Model** list, select the Imagen model to use.

6. In **Input image** click **Add** and select the image that you are editing
   to upload.

7. In the **Prompt** box, enter a prompt that describes how to edit the image.

8. In the editing toolbar, click background_replace**Extract mask**.

9. Select one of the mask extraction options:

   - **Background elements**: detects the background elements and creates a
     mask around them.

   - **Foreground elements**:
     detects the foreground objects and creates a mask around them.

   - background_replace **People**:
     detects people and creates a mask around them.

10. Click **Run**.

### REST


Before using any of the request data,
make the following replacements:

- <var translate="no">PROJECT_ID</var>: Your Google Cloud [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifying_projects).
- <var translate="no">LOCATION</var>: Your project's region. For example, `us-central1`, `europe-west2`, or `asia-northeast3`. For a list of available regions, see [Generative AI on Vertex AI locations](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/learn/locations-genai). When a regional API endpoint is used, the region from the endpoint's URL determines where the request is processed, and this `LOCATION` in the resource path is ignored if it conflicts.
- `prompt`: For best results, omit a prompt and `negativePrompt` when you use inpainting for removal.
- <var translate="no">B64_BASE_IMAGE</var>: The base image to edit or upscale. The image must be specified as a [base64-encoded](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/image/base64-encode.md.txt) byte string. Size limit: 10 MB.
- <var translate="no">MASK_MODE</var> - A string that sets the type of automatic mask creation the model uses. Available values:
  - `MASK_MODE_BACKGROUND`: Automatically generates a mask using background segmentation. Use this setting for modifying background content.
  - `MASK_MODE_FOREGROUND`: Automatically generates a mask using foreground segmentation. Use this setting to modify foreground content, such as removing these foreground objects (removal using inpainting).
  - `MASK_MODE_SEMANTIC`: Automatically generates a mask using semantic segmentation based on the [segmentation
    classes](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/model-reference/imagen-api-customization#segment-ids) you specify in the `maskImageConfig.maskClasses` array. For example:

    ```
              "maskImageConfig": {
                "maskMode": "MASK_MODE_SEMANTIC",
                "maskClasses": [175, 176], // bicycle, car
                "dilation": 0.01
              }
            
    ```
- <var translate="no">MASK_DILATION</var> - float. The percentage of image width to dilate this mask by. A value of `0.01` is recommended to compensate for imperfect input masks.
- <var translate="no">EDIT_STEPS</var> - integer. The number of sampling steps for the base model. For inpainting removal, start at `12` steps. Increase steps to upper limit of `75` if the quality doesn't meet your requirements. Increasing steps also increases request latency.
- <var translate="no">EDIT_IMAGE_COUNT</var> - The number of edited images. Accepted integer values: 1-4. Default value: 4.


HTTP method and URL:

```
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict
```


Request JSON body:

```
{
  "instances": [
    {
      "prompt": "",
      "referenceImages": [
        {
          "referenceType": "REFERENCE_TYPE_RAW",
          "referenceId": 1,
          "referenceImage": {
            "bytesBase64Encoded": "B64_BASE_IMAGE"
          }
        },
        {
          "referenceType": "REFERENCE_TYPE_MASK",
          "referenceId": 2,
          "maskImageConfig": {
            "maskMode": "MASK_MODE",
            "dilation": MASK_DILATION
          }
        }
      ]
    }
  ],
  "parameters": {
    "editConfig": {
      "baseSteps": EDIT_STEPS
    },
    "editMode": "EDIT_MODE_INPAINT_REMOVAL",
    "sampleCount": EDIT_IMAGE_COUNT
  }
}
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict" | Select-Object -Expand Content
```
The following sample response is for a request with `"sampleCount": 2`. The response returns two prediction objects, with the generated image bytes base64-encoded.

```
{
  "predictions": [
    {
      "bytesBase64Encoded": "BASE64_IMG_BYTES",
      "mimeType": "image/png"
    },
    {
      "mimeType": "image/png",
      "bytesBase64Encoded": "BASE64_IMG_BYTES"
    }
  ]
}
```

<br />

## Limitations

The following sections explain limitations of Imagen's remove
objects feature.

### Modified pixels

Pixels generated by the model that aren't in the mask are generated at the
model's resolution (for example, 1024x1024) and aren't guaranteed to be
identical to the input. This might result in minor changes to the generated
image.

For perfect image preservation, we recommend blending the generated image with
the input image using the mask. Blending is typically required if the input
image resolution is 2K or higher.

### Removal limitation

Small objects adjacent to the mask might also be removed. For best results,
make the mask as precise as possible.

Removing large areas of the sky in outdoor images might result in unwanted
artifacts. For best results, we recommend providing a prompt.

## What's next

Read articles about Imagen and other Generative AI on Vertex AI
products:

- [A developer's guide to getting started with Imagen 3 on
  Vertex AI](https://cloud.google.com/blog/products/ai-machine-learning/a-developers-guide-to-imagen-3-on-vertex-ai?e=0?utm_source%3Dlinkedin)
- [New generative media models and tools, built with and for creators](https://blog.google/technology/ai/google-generative-ai-veo-imagen-3/#veo)
- [New in Gemini: Custom Gems and improved image generation with
  Imagen 3](https://blog.google/products/gemini/google-gemini-update-august-2024/)
- [Google DeepMind: Imagen 3 - Our highest quality
  text-to-image model](https://deepmind.google/technologies/imagen-3/)