Style customization

Imagen 3 Customization's style customization helps you generate new images from text prompts and reference images that you provide. The reference images guide new image generation.

Use cases

Imagen 3 Customization offers free-style prompting, which can give the impression that it can do more than it is trained to do. The following sections describe intended use cases for Imagen 3 Customization, and non-exhaustive examples of unintended use cases.

We recommend using Imagen 3 Customization for the intended use cases, as we've trained the model on those use cases and expect good results for them. Conversely, while you can push the model to do things outside of the intended use cases, we don't expect good results.

Intended use cases

The following are use cases intended for Imagen 3 Customization style customization:

  • Generate an image from text input that follows the specific style provided by a reference image.
  • Alter a photo of a person.
  • Alter a photo of a person and preserve their facial expression.

Examples of unintended use cases

The following are a non-exhaustive list of use cases that Imagen 3 Customization isn't trained to do, and produces poor results for:

  • Generate an image from text and using a reference image, with the intent to have some level of control of the generated composition from the reference image.

  • Generate an image of a person from a reference image that has a person with a particular facial expression.

  • Place two people in a different scene, preserve their identities, and while specifying the style of the output image (such as an oil painting) using a reference image.

  • Stylize a photo of a pet and turn it into a drawing, while preserving or specifying the composition of the image.

  • Place a product, such as a cookie or a couch, into different scenes with different product angles, and following a specific image style (such as photorealistic with specific colors, lighting styles, or animation).

Style customization example

The following depicts an example case for Imagen 3 Customization style customization:

Sample Input Sample Output
  1. Reference image1:
    Sample input for animal companion customization
  2. Text prompt:
    Generate an image in mosaic style [1] based on
    the following caption: The New York City skyline

Sample output for animal companion customization

1 Reference input image generated using Imagen 3 image generation from the prompt: a simple mosaic.

View Imagen for Editing and Customization model card

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. Make sure 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. Make sure 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.

    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.

      After installing the Google Cloud CLI, initialize it 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.

Style customization

You can provide reference images of style types when you use Imagen 3 Customization. The style that you choose affects how you form your generation request.

The prompt you use with Imagen 3 Customization might affect the quality of your generated images. The following sections describe recommended prompt templates and samples to send customization requests.

Use case Reference images Prompt template Example
Object style Subject image (1-4) Generate an image in STYLE_DESCRIPTION [1] based on the following caption: IMAGE_DESCRIPTION. Generate an image in neon sign style [1] based on the following caption: a sign saying have a great day.
Person image stylization without face mesh input Subject image (1-4) Create an image about SUBJECT_DESCRIPTION [1] to match the description: a portrait of SUBJECT_DESCRIPTION [1] ${PROMPT} Create an image about a woman with short hair[1] to match the description: a portrait of a woman with short hair[1] in 3d-cartoon style with blurred background. A cute and lovely character, smile face, looking at the camera, pastel color tone, high quality, 4k, masterpiece, super details, skin texture, texture mapping, soft shadows, soft realistic lighting, vibrant colors
Person image stylization with face mesh input Subject image (1-3)

Facemesh control image (1)
Create an image about SUBJECT_DESCRIPTION [1] in the pose of the CONTROL_IMAGE [2] to match the description: a portrait of SUBJECT_DESCRIPTION [1] ${PROMPT} Create an image about a woman with short hair [1] in the pose of the control image [2] to match the description: a portrait of a woman with short hair [1] in 3d-cartoon style with blur background. A Cute and lovely character, smile face. See the camera, pastel color tone, high quality, 4k, masterpiece, super details, skin texture, texture mapping, Soft shadows, soft realistic lighting, vibrant colors

REST

For more information about imagen-3.0-capability-001 model requests, see the imagen-3.0-capability-001 model API reference.

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

  • PROJECT_ID: Your Google Cloud project ID.
  • LOCATION: 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.
  • TEXT_PROMPT: The text prompt guides what images the model generates. To use Imagen 3 Customization, include the referenceId of the reference image or images you provide in the format [$referenceId]. For example:
    • The following text prompt is for a request that has a single reference image with "referenceId": 1 and an optional description of "styleDescription": "glowing style": Generate an image in glowing style [1] based on the following caption: A church in the mountain.
  • "referenceId": The ID of the reference image, or the ID for a series of reference images that correspond to the same subject or style. In this example the single reference image has a referenceId of (1).
  • BASE64_REFERENCE_IMAGE: A reference image to guide image generation. The image must be specified as a base64-encoded byte string.
  • STYLE_DESCRIPTION: Optional. A text description of the reference image you can then use in the prompt field. For example:
          "prompt": "Generate an image in glowing style [1] based on the following
            caption: A church in the mountain.",
          [...],
          "styleImageConfig": {
            "styleDescription": "glowing style"
          }
        
  • IMAGE_COUNT: The number of generated 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": "TEXT_PROMPT",
      "referenceImages": [
        {
          "referenceType": "REFERENCE_TYPE_STYLE",
          "referenceId": 1,
          "referenceImage": {
            "bytesBase64Encoded": "BASE64_REFERENCE_IMAGE"
          },
          "styleImageConfig": {
            "styleDescription": "STYLE_DESCRIPTION"
          }
        }
      ]
    }
  ],
  "parameters": {
    "sampleCount": IMAGE_COUNT
  }
}

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://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001: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://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"
    }
  ]
}

Python

from google import genai
from google.genai.types import EditImageConfig, Image, StyleReferenceConfig, StyleReferenceImage

client = genai.Client()

# TODO(developer): Update and un-comment below line
# output_gcs_uri = "gs://your-bucket/your-prefix"

# Create a style reference image of a neon sign stored in Google Cloud Storage
# using https://storage.googleapis.com/cloud-samples-data/generative-ai/image/neon.png
style_reference_image = StyleReferenceImage(
    reference_id=1,
    reference_image=Image(gcs_uri="gs://cloud-samples-data/generative-ai/image/neon.png"),
    config=StyleReferenceConfig(style_description="neon sign"),
)

image = client.models.edit_image(
    model="imagen-3.0-capability-001",
    prompt="generate an image of a neon sign [1] with the words: have a great day",
    reference_images=[style_reference_image],
    config=EditImageConfig(
        edit_mode="EDIT_MODE_DEFAULT",
        number_of_images=1,
        seed=1,
        safety_filter_level="BLOCK_MEDIUM_AND_ABOVE",
        person_generation="ALLOW_ADULT",
        output_gcs_uri=output_gcs_uri,
    ),
)

# Example response:
# gs://your-bucket/your-prefix
print(image.generated_images[0].image.gcs_uri)

Product usage

To view usage standards and content restrictions associated with Imagen on Vertex AI, see the usage guidelines.

Model versions

There are multiple image generation models that you can use. For more information, see Imagen models.

What's next

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