Amazon Titan Image Generator v2 is now available on Amazon Bedrock | Amazon Web Services

Voiced by Polly

Today we are announcing the general availability of Amazon Titan Image Generator v2 with new features on Amazon Bedrock. With Amazon Titan Image Generator v2, you can guide image creation using reference images, edit existing visuals, remove backgrounds, generate image variants, and safely customize the model to maintain brand style and subject matter consistency. This powerful tool streamlines workflows, increases productivity and brings creative visions to life.

Amazon Titan Image Generator v2 brings a number of new features in addition to all the features of Amazon Titan Image Generator v1, including:

  • Image editing – Provide a reference image along with a text prompt, resulting in outputs that follow the layout and structure of the user-supplied reference.
  • Image guide with color palette – Precisely control the color palette of generated images by providing a list of hex codes along with a text prompt.
  • Background removal – Automatically remove background from images containing multiple objects.
  • Consistency of the subject – Fine-tune the model so that a specific object (for example, a specific dog, shoe, or purse) is preserved in the generated images.

New Features in Amazon Titan Image Generator v2
Before you begin, if you are new to Amazon Titan models, go to the Amazon Bedrock console and select Access to the model in the lower left panel. To access the latest models of Amazon Titan z Amazonrequest access separately for Amazon Titan Image Generator G1 v2.

Here are the details of Amazon Titan Image Generator v2 in Amazon Bedrock:

Image editing
Use the image editing feature to shape your creations with precision and intent. By providing a reference image (i.e., an edited image), you can instruct the model to focus on specific visual characteristics, such as edges, object outlines, and structural features, or segmentation maps that define distinct regions and objects in the reference image. .

We support two types of image editing: Canny edge and segmentation.

  • The Canny edge algorithm is used to extract prominent edges in the reference image and create a map that the Amazon Titan Image Generator can use to guide the generation process. You can “draw” the basics of the desired image and the model will then fill in the details, textures and final aesthetic based on your guidance.
  • Segmentation provides an even more detailed level of control. By supplying a reference image, you can define specific areas or objects within the image and instruct the Amazon Titan Image Generator to generate content that aligns with those defined areas. You can precisely control the placement and rendering of characters, objects and other key elements.

Here are examples of generation that uses image manipulation.

To use the image editing feature, you can use the Amazon Bedrock API, the AWS SDK, or the AWS Command Line Interface (AWS CLI) and select CANNY_EDGE gold SEGMENTATION for controlMode of textToImageParams with your reference image.

	"taskType": "TEXT_IMAGE",
	"textToImageParams": {
 		"text": "a cartoon deer in a fairy world.",
        "conditionImage": input_image, # Optional
        "controlMode": "CANNY_EDGE" # Optional: CANNY_EDGE | SEGMENTATION
        "controlStrength": 0.7 # Optional: weight given to the condition image. Default: 0.7
     }

The following Python code example using the AWS SDK for Python (Boto3) shows how to invoke the Amazon Titan Image Generator v2 on Amazon Bedrock to use image editing.

import base64
import io
import json
import logging
import boto3
from PIL import Image
from botocore.exceptions import ClientError

def main():
    """
    Entrypoint for Amazon Titan Image Generator V2 example.
    """
    try:
        logging.basicConfig(level=logging.INFO,
                            format="%(levelname)s: %(message)s")

        model_id = 'amazon.titan-image-generator-v2:0'

        # Read image from file and encode it as base64 string.
        with open("/path/to/image", "rb") as image_file:
            input_image = base64.b64encode(image_file.read()).decode('utf8')

        body = json.dumps({
            "taskType": "TEXT_IMAGE",
            "textToImageParams": {
                "text": "a cartoon deer in a fairy world",
                "conditionImage": input_image,
                "controlMode": "CANNY_EDGE",
                "controlStrength": 0.7
            },
            "imageGenerationConfig": {
                "numberOfImages": 1,
                "height": 512,
                "width": 512,
                "cfgScale": 8.0
            }
        })

        image_bytes = generate_image(model_id=model_id,
                                     body=body)
        image = Image.open(io.BytesIO(image_bytes))
        image.show()

    except ClientError as err:
        message = err.response("Error")("Message")
        logger.error("A client error occurred: %s", message)
        print("A client error occured: " +
              format(message))
    except ImageError as err:
        logger.error(err.message)
        print(err.message)

    else:
        print(
            f"Finished generating image with Amazon Titan Image Generator V2 model {model_id}.")

def generate_image(model_id, body):
    """
    Generate an image using Amazon Titan Image Generator V2 model on demand.
    Args:
        model_id (str): The model ID to use.
        body (str) : The request body to use.
    Returns:
        image_bytes (bytes): The image generated by the model.
    """

    logger.info(
        "Generating image with Amazon Titan Image Generator V2 model %s", model_id)

    bedrock = boto3.client(service_name="bedrock-runtime")

    accept = "application/json"
    content_type = "application/json"

    response = bedrock.invoke_model(
        body=body, modelId=model_id, accept=accept, contentType=content_type
    )
    response_body = json.loads(response.get("body").read())

    base64_image = response_body.get("images")(0)
    base64_bytes = base64_image.encode('ascii')
    image_bytes = base64.b64decode(base64_bytes)

    finish_reason = response_body.get("error")

    if finish_reason is not None:
        raise ImageError(f"Image generation error. Error is {finish_reason}")

    logger.info(
        "Successfully generated image with Amazon Titan Image Generator V2 model %s", model_id)

    return image_bytes
	
class ImageError(Exception):
    "Custom exception for errors returned by Amazon Titan Image Generator V2"

    def __init__(self, message):
        self.message = message

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

if __name__ == "__main__":
    main()

Color adjustment
Most designers want to generate images according to color coding guidelines, so they look for control over the color palette in the generated images.

With the Amazon Titan Image Generator v2, you can generate color-adjusted images based on a color palette—a list of hexadecimal colors provided as part of the input following color labeling guidelines. You can also provide a reference image as input (optional) to generate an image with the provided hexadecimal colors when inheriting the style from the reference image.

In this example, the prompt describes:
a jar of salad dressing in a rustic kitchen surrounded by fresh vegetables with studio lighting

The generated image reflects both the content of the text prompt and the specified color scheme to comply with the brand’s color guidelines.

To use the color adjustment function, you can set taskType on COLOR_GUIDED_GENERATION with your prompt and hex codes.

       "taskType": "COLOR_GUIDED_GENERATION",
       "colorGuidedGenerationParam": {
             "text": "a jar of salad dressing in a rustic kitchen surrounded by fresh vegetables with studio lighting",                         
	         "colors": ('#ff8080', '#ffb280', '#ffe680', '#e5ff80'), # Optional: list of color hex codes 
             "referenceImage": input_image, #Optional
        }

Background removal
Whether you want to compose an image over a solid color background or layer it over another scene, the ability to cleanly and precisely remove the background is an essential tool in your creative workflow. You can instantly remove background from your images in one step. Amazon Titan Image Generator v2 can intelligently detect and segment multiple foreground objects, ensuring that even complex scenes with overlapping elements are cleanly isolated.

An example shows a picture of an iguana sitting on a tree in a forest. The model was able to identify the iguana as the main object and remove the forest background and replace it with a transparent background. This allows the iguana to stand out clearly without the distracting forest around it.

To use the background removal function, you can set taskType on BACKGROUND_REMOVAL with your input image.

    "taskType": "BACKGROUND_REMOVAL",
    "backgroundRemovalParams": {
 		"image": input_image,
    }

Object consistency with fine tuning
Now you can seamlessly incorporate specific objects into visually captivating scenes. Whether it’s a branded product, a company logo, or a beloved family pet, you can fine-tune the Amazon Titan model using reference images to learn the unique characteristics of your chosen object.

Once the model is fine-tuned, you can simply provide a text prompt and the Amazon Titan Generator will generate images that maintain a consistent representation of the object and naturally place it in different, imaginative contexts. This opens up a world of possibilities for marketing, advertising and visual storytelling.

For example, you can use an image with a caption Ron the dog during fine tuning give a prompt like Ron the dog wearing a superhero cape during inference with a tuned model and get a unique image as a response.

To learn, visit the Model Inference Parameters and Code Examples for Amazon Titan Image Generator in the AWS documentation.

Now available
The Amazon Titan Generator v2 is available today on Amazon Bedrock in the US East (N. Virginia) and US West (Oregon) regions. Check out the full list of regions for future updates. To learn more, check out the Amazon Titan product page and the Amazon Bedrock pricing page.

Try the Amazon Titan Image Generator v2 in Amazon Bedrock today and submit your feedback to AWS re:Post for Amazon Bedrock or through your usual AWS support contacts.

Visit our community.aws page for detailed technical content and learn how our Builder communities are using Amazon Bedrock in their solutions.

Channy

Leave a Comment