Implementation:Googleapis Python genai Models Upscale Image
| Knowledge Sources | |
|---|---|
| Domains | Computer_Vision, Image_Processing |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for upscaling image resolution using neural super-resolution models provided by the google-genai models module.
Description
Models.upscale_image takes an input Image, an upscale model, and an upscale factor to produce a higher-resolution version. The method supports x2 and x4 upscale factors. Optional configuration controls the output MIME type and whether to enhance the input image. The input Image can come from generate_images output or be loaded from a file.
Usage
Call client.models.upscale_image with the upscale model, input Image object, and desired upscale factor. The input image can be obtained from generate_images output or created from a file using types.Image.from_file.
Code Reference
Source Location
- Repository: googleapis/python-genai
- File: google/genai/models.py
- Lines: L5973-6045
Signature
class Models:
def upscale_image(
self,
*,
model: str,
image: types.ImageOrDict,
upscale_factor: str,
config: Optional[types.UpscaleImageConfigOrDict] = None,
) -> types.UpscaleImageResponse:
"""Upscales an image to higher resolution.
Args:
model: Upscale model ID.
image: Input Image object to upscale.
upscale_factor: 'x2' or 'x4'.
config: Optional upscale configuration.
"""
Import
from google import genai
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model | str | Yes | Upscale model ID |
| image | ImageOrDict | Yes | Input Image to upscale |
| upscale_factor | str | Yes | Upscale factor: 'x2' or 'x4' |
| config | Optional[UpscaleImageConfigOrDict] | No | Output format and enhancement options |
Outputs
| Name | Type | Description |
|---|---|---|
| UpscaleImageResponse | UpscaleImageResponse | Response with upscaled image data |
Usage Examples
Upscale a Generated Image
from google import genai
from google.genai import types
client = genai.Client(api_key="YOUR_API_KEY")
# Generate an image first
gen_response = client.models.generate_images(
model="imagen-4.0-generate-001",
prompt="A detailed botanical illustration"
)
# Upscale the first generated image
upscale_response = client.models.upscale_image(
model="imagen-3.0-generate-001",
image=gen_response.generated_images[0].image,
upscale_factor="x2"
)
upscale_response.generated_images[0].image.save("upscaled_botanical.png")