Skip to main content

A lightweight Python library for generating image embeddings

Project description

Image Embeddings Library

CI pypi.org

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.3.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.3-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: imgemb-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 c06003aa171fafab341e2e39cfb2d0b062b4c0f8a5b9e07d85e8857b1b1ac43e
MD5 8d51ac13fb5141be940407978d711d95
BLAKE2b-256 ae7bde960bc5ec1e0923aae8f459b2e258f30d40ac6361e65d5e06c2f92df987

See more details on using hashes here.

File details

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

File metadata

  • Download URL: imgemb-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e0f293231fe9070b08526d968e2c739ab1e295dd68a6d281456eed4115787312
MD5 d9400f675609101b2e561ed87443582a
BLAKE2b-256 236e145025b579ee34314b005738e1f5bc8dcb99da379fe4ae399106a59a4ea7

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