Recontextualize product images

Imagen product recontext on Vertex AI lets you edit product images into different scenes or backgrounds. You provide images of a product and an optional prompt, and Imagen product recontext generates images of your product in recontextualized in new scenes or backgrounds.

To request access to Imagen product recontext, complete the Vertex AI - Generative Media for Marketing Access Request form.

Supported product types

Imagen product recontext supports the following product types:

  • Appliances
  • Business and industrial
  • Clothing
  • Electronics
  • Furniture
  • Garden and yard
  • Hardware
  • Health and beauty
  • Jewelry
  • Pets
  • Shoes
  • Sporting goods
  • Toys and games
  • Vehicles

Product recontextualization example

The following shows an example use case for product recontextualization:

Sample Inputs Sample Outputs Prompt used
A black laptop with multicolor backlighting on the keyboard
             and a colorful test image on the screen, placed on a white
             background. A black laptop with multicolor backlighting on the keyboard
             and a colorful test image on the screen, now placed on a workbench.
             Behind the workbench is a window, with multicolor advertisements
             displayed outside. On a cluttered workbench in a rainy, neon-lit cyberpunk alley, with holographic advertisements flickering in the background.
A digital SLR camera with a large lens attached, placed on a
             whilte background. A digital SLR camera with a large lens attached, placed on a
             whilte background. The camera is now placed on a cliff edge, with a
             wide waterfall in the background. Placed on a mossy rock on the edge of a cliff, overlooking a massive, powerful waterfall in a dramatic, overcast Icelandic landscape.
A pair of sunglasses placed on a white background. A pair of sunglasses, now placed on a table with a cup of
             coffee placed on a saucer in the foreground, and a scenic view of
             the top of a church and a body of water with hills in the
             background. Resting on a white cafe table in Santorini, with a cup of coffee, overlooking the Aegean Sea and iconic blue-domed buildings.

Try Imagen product recontext in a Colab

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI API.

    Enable the API

  8. Set up authentication for your environment.

    To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.

      Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:

      gcloud init

      If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    For more information, see Authenticate for using REST in the Google Cloud authentication documentation.

Generate product images in different scenes

REST

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

  • REGION: The region that your project is located in. For more information about supported regions, see Generative AI on Vertex AI locations.
  • PROJECT_ID: Your Google Cloud project ID.
  • TEXT_PROMPT: Optional. A text prompt to guide the images that the model generates.
  • BASE64_SUBJECT_IMAGE: A base64-encoded image of the subject image.
  • PERSON_SETTING: Optional: A string value that controls the type of person or face generation that the model allows. You can use the following values for personGeneration:
    • "allow_adult": Allows generation of adults only, except for celebrity generation. Celebrity generation isn't allowed for any setting. This is the default setting.
    • "allow_all": Allows generation of people of all ages, except for celebrity generation. Celebrity generation is not allowed for any setting.
    • "dont_allow": Doesn't allow generation of people or faces in generated output.
  • SAFETY_SETTING: Optional: A string value that controls the safety filter threshold for generated images. You can use the following values to select your safety setting:
    • "block_low_and_above": The most stringent safety threshold. "block_low_and_above" filters the largest number of generated images.
    • "block_medium_and_above": The medium safety threshold, which balances filtering for potentially harmful and safe content. "block_medium_and_above" is the default safety setting.
    • "block_only_high": The lowest safety threshold, which reduces the number of requests blocked due to safety filter. Using "block_only_high" safety threshold might increase the number of objectionable images generated by the model.
  • WATERMARK_SETTING: Optional: A boolean. When this values is set to true, the model adds a digital watermark that you can use to verify the generated image. The default value is true.
  • IMAGE_COUNT: The number of images to generate. The accepted range of values is 1-4.
  • PROMPT_SETTING: Optional: A boolean. When this value is set to true, the model uses enhanced prmopts. The default value is true.

HTTP method and URL:

POST https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-product-recontext-preview-06-30:predict

Request JSON body:

{
  "instances": [
    {
      "prompt": "TEXT_PROMPT",
      "productImages": [
        {
          "image": {
            "bytesBase64Encoded": "BASE64_SUBJECT_IMAGE"
          },
        }
      ]
    }
  ],
  "parameters": {
    "personGeneration": PERSON_SETTING,
    "safetySetting": SAFETY_SETTING,
    "addWatermark": WATERMARK_SETTING,
    "sampleCount": IMAGE_COUNT,
    "enhancePrompt": PROMPT_SETTING
  }
}

To send your request, choose one of these options:

curl

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://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-product-recontext-preview-06-30:predict"

PowerShell

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://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-product-recontext-preview-06-30:predict" | Select-Object -Expand Content
The request returns image objects. In this example, two image objects are returned, with two prediction objects as base64-encoded images.
{
  "predictions": [
    {
      "mimeType": "image/png",
      "bytesBase64Encoded": "BASE64_IMG_BYTES"
    },
    {
      "bytesBase64Encoded": "BASE64_IMG_BYTES",
      "mimeType": "image/png"
    }
  ]
}