Upscale images using Imagen

You can use Imagen on Vertex AI to upscale images, which increases their size without losing image quality.

imagen-4.0-upscale-preview supports image upscaling in Preview.

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.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

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

  4. Enable the Vertex AI API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

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

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

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

  7. Enable the Vertex AI API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  8. 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.

      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.

Upscale an image

Console

  1. In the Google Cloud console, go to the Vertex AI > Vertex AI Studio > Generate media page.

    Go to Generate Media

  2. Click Imagen. The Media playground page is displayed.

  3. Click upload an image and then select an image to upload.

  4. Click Export image and then Also upscale image.

  5. Choose a scaling factor and then click Export.

A digital watermark is automatically added to upscaled images. You can't disable digital watermark for image upscaling using the Google Cloud console.

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.
  • BASE64_SUBJECT_IMAGE: A base64-encoded image of the subject image.
  • ADD_WATERMARK: An optional Boolean value. Set to true to enable watermarked images, or false to disable watermarked images. The default value is true.
  • GCS_IMAGE_PATH: A Cloud Storage path to an image file.
  • GCS_OUTPUT_PATH: the Cloud Storage path to store the generated output to.
  • OUTPUT_MIMETYPE: An optional string that defines the output file type of the image. The following values are accepted: "image/png" or "image/jpeg". The default is "image/png".
  • COMPRESSION_QUALITY: An optional integer value that specifies the level of detail that the model preserves for JPEG images. The following range of values are accepted: 0 - 100. The higher value specifies a higher compression level. The default is 75.
  • UPSCALE_FACTOR: The scaling factor for the upscaled image. The following values are accepted:
    • "x2"
    • "x3"
    • "x4"

HTTP method and URL:

POST https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview:predict

Request JSON body:

{
  "instances": [
    {
      "image": {
        // use one of the following to specify the image to upscale
        "bytesBase64Encoded": "BASE64_SUBJECT_IMAGE"
        "gcsUri": "GCS_IMAGE_PATH"
        // end of base image input options
      },
    }
  ],
  "parameters": {
    "addWatermark": ADD_WATERMARK, // Optional
    "storageUri": "GCS_OUTPUT_PATH",
    "outputOptions": {  // Optional
      "mimeType": "OUTPUT_MIMETYPE",  // Optional
      "compressionQuality": COMPRESSION_QUALITY // Optional
    },
    "upscaleConfig": {
      "upscaleFactor": "UPSCALE_FACTOR"
    }
  }
}

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-4.0-upscale-preview: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-4.0-upscale-preview:predict" | Select-Object -Expand Content
The request returns an image object. In this example, an image objects is returned as a prediction object with a base64-encoded image.
{
  "predictions": [
    {
      "mimeType": "image/png",
      "bytesBase64Encoded": "BASE64_IMG_BYTES"
    }
  ]
}


What's next

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