Skip to main content

Image-Baker

Dependabot Status GitHub License commit activity code size in bytes

Ruff PyPI version

Centered Demo

An example of baked images. (Each object is a layer and an annotation will also be extracted for all layers.)

Let's bake an image.

Why is it relevant?

When training computer vision models (especially for detection and segmentation), labeling large amounts of data is crucial for better model performance. Often, the process involves multiple cycles of labeling, training, and evaluation. By generating multiple realistic labeled datasets from a single image, the time spent on labeling can be significantly reduced.

What's up with the name?

The concept involves extracting portions of an image (e.g., objects of interest) using tools like polygons or models such as Segment Anything. These extractions are treated as layers, which can then be copied, pasted, and manipulated to create multiple instances of the desired object. By combining these layers step by step, a new labeled image with annotations in JSON format is created. The term "baking" refers to the process of merging these layers into a single cohesive image.

Getting Started

ImageBaker can be used in four ways:

  1. 🌐 Web Application (imagebaker web) - Modern, responsive browser interface running across Linux, macOS, and Windows with Label Studio-inspired UX, draggable sidebars, model text prompt prediction, and real-time compositing.
  2. 🖥️ Desktop Application (imagebaker gui) - Native Qt desktop interface (Windows & Linux).
  3. ⌨️ CLI Tool (imagebaker cli) - Command-line interface for batch baking, configuration execution, and automation.
  4. 🐍 Python Library & PyTorch Dataset - Programmatic API with on-the-fly PyTorch dataset synthesis (ImageBakerDataset, extract_baked_dataset) and multi-format exports (COCO, YOLO, DEFAULT).

Installation

Using PIP

This project is available on PyPI:

# Standard installation
pip install imagebaker

# Install with model extras
pip install "imagebaker[yolo]"       # Ultralytics YOLO detection & segmentation
pip install "imagebaker[rfdetr]"     # RF-DETR detection & instance segmentation
pip install "imagebaker[sam2]"       # Segment Anything 2 (SAM 2)
pip install "imagebaker[plugins]"    # Optional plugins (e.g. SmokeSim)
pip install "imagebaker[all]"        # All models & plugins combined

Developing Locally

Clone this repository and install it locally in editable mode:

git clone https://github.com/q-viper/image-baker.git
cd image-baker
python -m venv .venv
source .venv/bin/activate       # On Windows: .venv\Scripts\activate
pip install -e ".[all]"

Usage

🌐 Web Mode (Cross-Platform: Linux, macOS, Windows)

Launch the standalone browser-based application with Label Studio-inspired UX and zero OS dependencies:

# Launch web server and automatically open in your default browser
imagebaker web

# Specify custom host, port, project directory, and models file
imagebaker web --host 127.0.0.1 --port 8765 --project-dir . --models-file examples/loaded_models.py

🖥️ Desktop GUI Mode

Launch the native Qt visual interface:

# Simple launch (default)
imagebaker

# Explicit GUI command with models
imagebaker gui --models-file examples/loaded_models.py

⌨️ CLI Mode

Automate image composition and dataset baking from the command line:

# Simple composition
imagebaker cli bake simple bg.png fg.png -o output.png \
    --positions "0,0;100,100" --opacities "1.0,0.5"

# Config-based baking
imagebaker cli bake from-config config.py

# Get image info
imagebaker cli info image.png

# Check version
imagebaker cli version

🐍 Python API & PyTorch Integration

Integrate ImageBaker into your training loops and pipelines:

from imagebaker import ImageBaker, ImageBakerDataset, extract_baked_dataset, AnnotationFormat

# 1. Programmatic layer compositing and baking
baker = ImageBaker()
layer1 = baker.add_layer_from_file("background.png")
layer2 = baker.add_layer_from_file("foreground.png")
baker.set_layer_position(layer2, 100, 100)
baker.set_layer_opacity(layer2, 0.7)
result = baker.bake()
baker.save(result, "output.png")

# 2. PyTorch Dataset integration with on-the-fly sample synthesis
dataset = ImageBakerDataset(
    cache_dir=".imagebaker/cache",
    format=AnnotationFormat.COCO,  # AnnotationFormat.COCO, AnnotationFormat.YOLO, AnnotationFormat.DEFAULT
    split="train",
    split_ratio=(0.8, 0.1, 0.1),
    samples_per_epoch=1000,
    seed=42,
)
image_tensor, target = dataset[0]

# 3. Batch export cached baking sessions to disk
extract_baked_dataset(
    cache_dir=".imagebaker/cache",
    output_dir="./synthetic_dataset",
    annotation_format=AnnotationFormat.YOLO,
    train_ratio=0.8,
    val_ratio=0.1,
    test_ratio=0.1,
)

📚 Documentation:

Features

  • Cross-Platform Annotation Studio: Run either via the standalone Web interface (imagebaker web) or native desktop UI (imagebaker gui), featuring Label Studio-style interactive label chips, draggable sidebar splitters, and persistent user configuration.
  • AI Model Prediction & Text Prompts: Run AI model inferences (YOLO, RF-DETR detection & instance segmentation, SAM 2) with optional text prompts (e.g. "pedestrian", "car") directly from the UI or code.
  • Layerifying: Crop images based on annotations into reusable compositing layers with single-click or "Layerify All" batch processing.
  • Multi-Format Annotation Support: Import and export annotations seamlessly across COCO, YOLO, and ImageBaker Default JSON formats using the AnnotationFormat enum.
  • Baking Timeline States: Compose multiple layers with transforms (translation, scaling, rotation, edge width/opacity), interpolate states, randomize variations, and preview playback.
  • On-the-Fly PyTorch Dataset: ImageBakerDataset inherits from torch.utils.data.Dataset, dynamically synthesizing realistic labeled training samples on the fly with reproducible train/val/test splits and layer constraints.
  • Layer Drawing & Erasing: Draw and erase directly onto selected layers to add details or manual masks before baking.

Shortcuts

  • Ctrl + C: Copy selected annotation/layer.
  • Ctrl + V: Paste copied annotation/layer in its parent image/layer if it is currently open.
  • Delete: Delete selected annotation/layer.
  • Left Click: Select an annotation/layer on mouse position.
  • Left Click + Drag: Drag a selected annotation/layer.
  • Double Left Click: When using polygon annotation, completes the polygon.
  • Right Click: Unselect an annotation/layer. While annotating the polygon, undo the last point.
  • Ctrl + Mouse Wheel: Zoom In/Out on the mouse position, i.e., resize the viewport.
  • Ctrl + Drag: If done on the background, the viewport is panned.
  • Ctrl + S: Save State on Baker Tab.
  • Ctrl + D: Draw Mode on Baker Tab. Drawing can happen on a selected or main layer.
  • Ctrl + E: Erase Mode on Baker Tab.
  • Ctrl + H: Opens a help window.
  • Wheel: Change the size of the drawing pointer.
  • Q: Point mode on annotation.
  • W: Polygon mode on annotation. Moves selected layer one step up in layer lists in baker.
  • S: Moves selected layer one step down in layer list in baker.
  • E: Rectangle mode on annotation.
  • H: Hides/un-hides selected annotation/layer.
  • L: Creates layer from an annotation. If any annotation selected, creates only its, else creates layers from all visible annotations.
  • C: If any annotation is selected, a input box for Caption is created. It can be edited on baker tab as well and is state aware.
  • Numerics: Selecting number 1, 2, till 9 selects label. If not available, asks for a new label.
  • Escape: Closes the application.

Demo

Annotation Page

This is where the loading of the image folder and annotation, connection with the model running in the backend, and layerifying happen.

Baker Page

This is where the layer baking happens. And the extraction of the layers as well.

An example of drawing:

Annotated

The JSON and the baked image will be exported to the local folder, and in debug mode, the annotations and the mask for each layer will be exported too.

Demo Video

To see the tool in action, check out the demo video below:

Demo Video

Click on the image above to play the video on YouTube.

Contributions

Contributions are welcome!

Do you find this project to be useful and are you looking for some features that are not implemented yet? Feel free to open issues or submit pull requests to improve the project.

For more please visit CONTRIBUTING.

Metadata

Release files for imagebaker 0.0.68

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for imagebaker 0.0.68
File Size Uploaded Provenance Actions
imagebaker-0.0.68.tar.gz 1.1 MB Without provenance Details for imagebaker-0.0.68.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for imagebaker 0.0.68
File Interpreter ABI Platform Actions
imagebaker-0.0.68-py3-none-any.whl Python 3 none any Details for imagebaker-0.0.68-py3-none-any.whl

Total release size: 1.4 MB

Release files / imagebaker-0.0.68.tar.gz

Download URL imagebaker-0.0.68.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
a5df01e924a0e2acdab0178238b177e3a63c860c489f6fa8034356c1151c0eb3
BLAKE2b-256 checksum
How to use checksums
b05bdd30a309f87edd9e191f0f9392a28ab41f2f1025884e64e1688452bc442e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / imagebaker-0.0.68-py3-none-any.whl

Download URL imagebaker-0.0.68-py3-none-any.whl
Size 271.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ead422c00e2592dd59eee3f25e34dd3bf42f5a21bf55d91b6081481283b3709
BLAKE2b-256 checksum
How to use checksums
92c889a39aa7594b2b5d55b98449e7f295e180eefe5d82597605a8949332b60c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Security for imagebaker 0.0.68

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.68 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page