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
- 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.
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
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 theserviceusage.services.enablepermission. Learn how to grant roles. -
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
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 theserviceusage.services.enablepermission. Learn how to grant roles. -
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 initIf 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
In the Google Cloud console, go to the Vertex AI > Vertex AI Studio > Generate media page.
Click Imagen. The Media playground page is displayed.
Click upload an image and then select an image to upload.
Click Export image and then Also upscale image.
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 totrueto enable watermarked images, orfalseto disable watermarked images. The default value istrue. -
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 is75. -
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
{
"predictions": [
{
"mimeType": "image/png",
"bytesBase64Encoded": "BASE64_IMG_BYTES"
}
]
}
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
- New generative media models and tools, built with and for creators
- New in Gemini: Custom Gems and improved image generation with Imagen 3
- Google DeepMind: Imagen 3 - Our highest quality text-to-image model