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:
- Read an input image.
- Use the Nova Canvas model to replace the background based on a text prompt.
- Save the updated image with the new background.
Prerequisites
Before you begin, make sure you have:
- AWS Account: Ensure you have access to Amazon Bedrock Nova Canvas Model.
- Python Environment: Python 3.8 or later installed.
- AWS CLI: Configured with appropriate credentials.
- Input Image: A sample image to test the solution.
- 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
- 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

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
- E-Commerce: Enhance product images by replacing cluttered backgrounds.
- Real Estate: Present properties with clean and appealing surroundings.
- Creative Design: Enable graphic designers to generate custom scenes effortlessly.
- 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:
- Be sure to clap and follow the writer ️👏️️
- Follow us: X | LinkedIn | YouTube | Discord | Newsletter | Podcast
- Create a free AI-powered blog on Differ.
- More content at PlainEnglish.io
- Have a story to share? Join our global community of writers today!