Transform images into mosaics where each tile has a unique AI-generated artistic style while preserving the original structure and composition.
- Your image is transformed into N different artistic styles (one per tile)
- Each styled version preserves the original composition using Stability AI's Control Structure
- The corresponding tile is extracted from each styled image
- Tiles are combined into the final mosaic
cd /home/adam/image_collage
pip install -r requirements.txtCopy the example env file and add your keys:
cp .env.example .envEdit .env with your API keys:
OPENAI_API_KEY=sk-your-openai-key-here
STABILITY_API_KEY=sk-your-stability-key-here
Get your keys:
- OpenAI: https://platform.openai.com/api-keys
- Stability AI: https://platform.stability.ai/account/keys
python3 main.py your_image.jpg --grid 3x3python3 main.py <image_path> --grid <ROWSxCOLS> --strength <0.0-1.0>| Option | Description | Default |
|---|---|---|
--grid, -g |
Grid size as ROWSxCOLS | 3x3 |
--strength, -s |
Structure preservation (higher = more faithful) | 0.9 |
# Simple 3x3 mosaic
python3 main.py photo.jpg
# 5x6 grid with strong structure preservation
python3 main.py photo.jpg -g 5x6 -s 0.9
# 2x2 quick test
python3 main.py photo.jpg -g 2x2 -s 0.85python3 main.py "/mnt/c/Users/OWNER/Downloads/photo.jpg" -g 3x3All outputs are saved to outputs/<image_name>_v<N>/:
outputs/photo_v1/
├── photo_mosaic.png # Final mosaic
├── styled_0_0_Theme_Name.png # Full styled image for tile (0,0)
├── styled_0_1_Another_Theme.png # Full styled image for tile (0,1)
└── ...
Running the same image again auto-increments the version (_v2, _v3, etc.).
The --strength parameter (0.0-1.0) controls how much of the original image structure is preserved:
-
Higher strength (0.9-0.95) = More structure preserved. The subject, background, and composition stay very close to the original. Style changes are applied to colors and textures while keeping shapes intact.
-
Lower strength (0.7-0.8) = More creative freedom. The AI takes more liberties with the composition. Subjects may be reimagined or transformed more dramatically.
| Strength | Effect |
|---|---|
| 0.7 | More creative, may alter composition |
| 0.85 | Balanced style and structure |
| 0.9 | Strong structure preservation (recommended) |
| 0.95 | Very close to original, subtle changes |
Recommendation: Start with 0.9 for most images. Lower it if you want more dramatic artistic interpretation.
Each tile requires one Stability AI API call. Approximate costs:
- 3x3 grid (9 tiles): ~$0.30-0.50
- 4x4 grid (16 tiles): ~$0.50-0.80
- 5x6 grid (30 tiles): ~$1.00-1.50
- Python 3.8+
- OpenAI API key (for theme generation)
- Stability AI API key (for style transfer)
