Skip to main content

A lightweight Python library for generating image embeddings

Project description

Image Embeddings Library

CI codecov

A lightweight Python library for generating and comparing image embeddings using various methods. This library provides tools for image similarity search, clustering, and comparison.

Features

  • Multiple embedding methods:
    • Average Color: Simple RGB color averaging
    • Grid-based: Divides image into grid cells and computes color features
    • Edge-based: Uses Sobel edge detection and histogram features
  • Command-line interface (CLI) for easy usage
  • Normalization options for embeddings
  • Tools for finding similar images in a directory
  • Support for batch processing

Installation

From PyPI (Recommended)

pip install imgemb

From Source

git clone https://github.com/aryanraj2713/image_embeddings.git
cd image_embeddings
pip install -e ".[dev]"  # Install with development dependencies

Quick Start

Using as a Python Library

from imgemb import ImageEmbedder

# Initialize embedder
embedder = ImageEmbedder(
    method='grid',           # 'average_color', 'grid', or 'edge'
    grid_size=(4, 4),       # For grid method
    normalize=True          # Whether to normalize embeddings
)

# Generate embedding for a single image
embedding = embedder.embed_image('path/to/image.jpg')

# Compare two images
similarity = embedder.compare_images('image1.jpg', 'image2.jpg')

# Find similar images in a directory
similar_images = embedder.find_similar_images(
    'query.jpg',
    'path/to/image/directory',
    top_k=5
)

Using the Command Line Interface

  1. Compare two images:
imgemb compare image1.jpg image2.jpg --method grid --grid-size 4 4
  1. Generate embeddings for images:
imgemb generate path/to/images/ --output embeddings.json --method edge
  1. Find similar images:
imgemb find-similar query.jpg image/directory/ -k 5 --method grid

Embedding Methods

Average Color

Computes the mean RGB values of the entire image. Simple but effective for basic color-based similarity.

embedder = ImageEmbedder(method='average_color')

Grid-based

Divides the image into a grid and computes mean RGB values for each cell. Better for capturing spatial color distribution.

embedder = ImageEmbedder(method='grid', grid_size=(4, 4))

Edge-based

Uses Sobel edge detection and histogram features. Good for capturing structural similarities.

embedder = ImageEmbedder(method='edge')

Development

Setup Development Environment

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install -e ".[dev]"

Running Tests

pytest tests/ -v

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Requirements

  • Python ≥ 3.8
  • OpenCV (opencv-python)
  • NumPy
  • Matplotlib
  • scikit-learn

Citation

If you use this library in your research, please cite:

@software{image_embeddings,
  title = {Image Embeddings: A Lightweight Library for Image Similarity},
  author = {Raj, Aryan},
  year = {2024},
  url = {https://github.com/aryanraj2713/image_embeddings}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imgemb-0.1.2.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imgemb-0.1.2-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file imgemb-0.1.2.tar.gz.

File metadata

  • Download URL: imgemb-0.1.2.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for imgemb-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a05a2de7595bde097a124af82a90eb6903cf9015206759d08b239bfda04c1175
MD5 f3d939c9ced0a25114772c0c4349988e
BLAKE2b-256 7e77ff61a8bd27ec36ce9b93ef383af2c05e738ec919d73f5a5f9397df4605d7

See more details on using hashes here.

File details

Details for the file imgemb-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: imgemb-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for imgemb-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f3fae8cf24d665becd18beb1aa4a6e2e0c65a994bcf89574b3e761fd964342a6
MD5 de8470f81f5b206ee018fffd02b3528d
BLAKE2b-256 6f1f0f0ce0c57fff0f47062d00dd66b465c457f6d04be392db4bc49b0d9ff475

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page