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.0.tar.gz (13.4 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.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: imgemb-0.1.0.tar.gz
  • Upload date:
  • Size: 13.4 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.0.tar.gz
Algorithm Hash digest
SHA256 2e1dff65f5aa9c0b0414681bde37b622d09805623a03415674881ab4a221feb3
MD5 5df442c0239ba19f1c815621b711de7c
BLAKE2b-256 a46658cd27ff0b75e1a4ede4b09e142d75d4e6cb76595b9c0a80f1955406a342

See more details on using hashes here.

File details

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

File metadata

  • Download URL: imgemb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 468e5e2fed1d618521d67682dd96e6de33e68eebbb75d9a4adacd12e5e80e66f
MD5 7d9ab90ef019c7b62ca4217ab05ebded
BLAKE2b-256 47e83aba14ef503f427e7f4f666f9770246e5a79ccc71d52b2ab65e7ac14b254

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