AWS in Plain English

New AWS, Cloud, and DevOps content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

Changing Image Background Using Amazon Bedrock Nova Canvas Model and Outpainting

--

An illustrated example on how to use a prompt to change image background in python using Bedrock

Amazon Bedrock’s Nova Canvas model offers a state-of-the-art solution for editing images using generative AI. With its outpainting feature, you can easily modify or replace image backgrounds using text prompts. This blog demonstrates how to leverage Nova Canvas for background modification, from reading an input image to generating an edited version with a new background.

What We’re Building

In this tutorial, we’ll:

  1. Read an input image.
  2. Use the Nova Canvas model to replace the background based on a text prompt.
  3. Save the updated image with the new background.

Prerequisites

Before you begin, make sure you have:

  1. AWS Account: Ensure you have access to Amazon Bedrock Nova Canvas Model.
  2. Python Environment: Python 3.8 or later installed.
  3. AWS CLI: Configured with appropriate credentials.
  4. Input Image: A sample image to test the solution.
  5. Required Libraries: Install the following Python packages:
pip install boto3 pillow

The Code

To view the complete implementation, access the full script in this GitHub repository.

You can clone the repository to your local terminal with below commands:

git clone https://github.com/awsdataarchitect/bedrock-examples
cd bedrock-examples

How It Works

  1. Input Image Preparation
  • The input image is converted to a base64-encoded string.

2. Outpainting Parameters

  • Define the OUTPAINTING task type with a text-based prompt describing the desired background.
  • Specify additional settings, such as the negative prompt for unwanted artifacts.

3. Invoke Nova Canvas

  • The script sends the prepared request to the Nova Canvas model using the boto3 Bedrock client.

4. Process the Response

  • The returned image bytes are decoded and saved as the output image.

5. Output the Result

  • The generated image is saved locally and displayed.

Running the Script

Run the script from the command line using:

python3 bedrock_nova_image_bg_change_prompt.py <image_path> <background_prompt>

Example:

python3 bedrock_nova_image_bg_change_prompt.py prompt_image_bg_demo.jpg "scenic beach sunset palm trees"

Sample Results

Bedrock Nova Canvas Model with Prompt based Outpainting Capabilities

Key Features of the Nova Canvas Model using Bedrock Runtime

1. Outpainting

Modify and expand images beyond their original boundaries using detailed text prompts.

2. Precision Editing

Use PRECISE outpainting mode for highly detailed and accurate results.

3. Cost Efficiency

Process images at a fraction of the cost compared to traditional editing tools.

4. Scalable and Automated

Easily integrate into workflows to handle thousands of images with minimal effort.

Industry Use Cases

  1. E-Commerce: Enhance product images by replacing cluttered backgrounds.
  2. Real Estate: Present properties with clean and appealing surroundings.
  3. Creative Design: Enable graphic designers to generate custom scenes effortlessly.
  4. Social Media Tools: Empower users to create personalized, high-quality content.

Conclusion

Amazon Bedrock’s Nova Canvas model revolutionizes image editing with its advanced outpainting capabilities. By leveraging this powerful API from Bedrock, you can achieve professional-grade background modifications programmatically, saving time and resources while unlocking endless creative possibilities.

Try it out and bring AI-powered efficiency to your image workflows!

In Plain English 🚀

Thank you for being a part of the In Plain English community! Before you go:

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Published in AWS in Plain English

New AWS, Cloud, and DevOps content every day. Follow to join our 3.5M+ monthly readers.

Written by Vivek V

AWS Ambassador | 15x AWS Certified (All-Star Award) | AWS Certification Subject Matter Expert for MLA-C01 + other Exams | CKAD/CKA/KCNA/KCSA | 5x Azure

No responses yet

What are your thoughts?