Background Generator is a GenAI tool designed to generate coherent backgrounds in images. It allows you to upload a photo with a subject (object, product or a person) and generate a consistent background. The subject's illumination is also adjusted.
Background generator utilizes generative AI to create authentic-looking backgrounds in photos. It's particularly useful for:
- Content creation: Create diverse representation in your visual content
The following instructions suppose you have already installed a recent version of Python. To use any PiktID API, an access token is required.
Step 0 - Register here. 10 credits are given for free to all new users.
Step 1 - Clone the Eddie - Person Generator repository
# Installation commands
$ git clone https://github.com/piktid/background-generator.git
$ cd background-generatorStep 2 - Export the email and password as environmental variables
$ export PIKTID_EMAIL={Your email here}
$ export PIKTID_PASSWORD={Your password here}or the authenticaton tokens - get them in https://studio.piktid.com/profile -> Tokens & Sessions
$ export ACCESS_TOKEN={Your access token}
$ export REFRESH_TOKEN={Your refresh token}Step 3a - Run the main function with a URL or local file path of the image and a keyword
# Using a URL with a text
$ python3 main.py --input_url 'your-url' --keyword 'Forest'
# Using a local file path with a keyword
$ python3 main.py --input_filepath '/path/to/your/image.jpg' --keyword 'Wedding'Available keywords are organized by categories:
- Materials & Textures: Silk, Wood, Marble, Stone, Metal, Leather, Paper, Gold
- Nature & Landscapes: Beach, Forest, Mountains, Desert, Lake, Garden, Tropical, Sky
- Florals: Roses, Lavender, Flowers, Leaves
- Indoor Spaces: Studio, Living Room, Kitchen, Bathroom, Bedroom, Office, Cafe, Gym, Library
- Outdoor Spaces: Street, Rooftop, Pool, Courtyard, Balcony, Skyscraper
- Special Occasions: Christmas, Halloween, Easter, Wedding, Birthday
- Artistic & Stylized: Paint, Graffiti, Abstract, Vintage, Minimalist
- Architectural: Modern, Industrial, Classic, Futuristic
- Colors & Gradients: Solid, Gradients, Ombre
- Seasonal: Spring, Summer, Autumn, Winter
- Professional & Business: Corporate, Medical, Conference
- Entertainment: Cinema, Concert, Night
- Transportation: Car, Airplane, Train
- Weather & Effects: Rain, Fog, Sunset, Sunrise, Fire, Water, Snow
Step 3b - Run the main function with a URL or local file path of the image and specify a text
# Using a URL with a text
$ python3 main.py --input_url 'your-url' --prompt ' .. commercial photo, red and white room lighting, depth of field,high level feeling,perfect lighting'
# Using a local file path with a text
$ python3 main.py --input_filepath '/path/to/your/image.jpg' --prompt ' .. commercial photo, depth of field,high level feeling,perfect lighting'You can customize the generation parameters with the following options:
# Generate a variation with specific parameters
$ python3 main.py --input_filepath '/path/to/your/image.jpg' --seed 12345 --prompt_strength 0.8 --output_filepath '/path/to/save/output.jpg'- input_url: URL of the image to process
- input_filepath: Local path to the image file
- output_filepath: Where to save the generated image
- keyword: Predefined keyword for background generation (alternative to prompt)
- prompt: Textual description of the background (REQUIRED if keyword not used)
- prompt_strength: How much the background follows the prompt (default: 1)
- relight_strength: How much the output light should change wrt to the original (default: 1)
- seed: Random seed for reproducible results (default: random)
- refine: Refine the generation output (default: False)
You can also generate backgrounds based on reference images. There are two ways to provide a reference image:
# Using a local reference image file
$ python3 main.py --input_filepath '/path/to/your/image.jpg' --reference_path '/path/to/reference.jpg' --prompt 'a beer in ..' --seed 0 --prompt_strength 0.5
# Using a reference image URL
$ python3 main.py --input_filepath '/path/to/your/image.jpg' --reference_url 'https://example.com/reference-image.jpg' --prompt 'background is ..' --seed 0 --prompt_strength 0.3The reference image will be used as a style guide for generating the background while maintaining consistency with the provided prompt.
After uploading images, you'll receive unique IDs for both the input and reference images. You can use these IDs to resume or create new variations without uploading the images again:
$ python3 main.py --id_image "22FXXXXXX" --reference_name "0OqUXXXXXX" --prompt "shoes on a white room" --seed 0This is particularly useful when:
- Working with the same images multiple times
- Creating variations of previous generations
- Saving bandwidth by avoiding re-uploads
