Image Comparison Tool
Project description
visual-comparison
visual-comparison is a lightweight Python library for visual regression testing. It compares two images of the same size, computes a structural similarity score, and can generate output images that highlight visual differences.
It is designed for automation and QA workflows where you want a simple API, reliable packaging, and compatibility with current NumPy releases.
Features
- Supports modern Python versions from 3.9 through 3.13.
- Compatible with current NumPy releases, including NumPy 2.x.
- Compares images from file paths or in-memory NumPy arrays.
- Produces SSIM-based similarity scores.
- Can save either a combined diff box or separate diff boxes.
- Useful for UI testing, screenshot comparison, and visual regression checks.
Installation
pip install visual-comparison
For local development:
pip install -e .
Quick Start
from visual_comparison import ImageComparisonUtil
expected = ImageComparisonUtil.read_image("expected.png")
actual = ImageComparisonUtil.read_image("actual.png")
similarity = ImageComparisonUtil.compare_images(
expected,
actual,
"result.png",
)
print(f"Similarity Index: {similarity}")
API
| Method | Description |
|---|---|
read_image(path) |
Load an image from disk. |
save_image(path, image) |
Save an image to disk. |
compare_images(expected, actual, result_destination=None) |
Return the SSIM score and optionally save one combined red bounding box around changed regions. |
compare_images_sep(expected, actual, result_destination=None) |
Return the SSIM score and optionally save separate bounding boxes for each changed region. |
compare_images_bw(expected, actual, result_destination=None) |
Return the SSIM score and optionally save a black-and-white diff image. |
check_match(expected, actual) |
Return True when images are effectively identical. |
check_mismatch(expected, actual) |
Return True when images differ. |
Repository Structure
.
|-- src/visual_comparison/ # Library source
|-- tests/ # Unit tests
|-- examples/ # Example scripts
|-- sample_images/ # Demo images
|-- .github/workflows/ # CI configuration
|-- README.md
|-- LICENSE
|-- pyproject.toml
|-- requirements.txt
`-- setup.py
Examples
- Similarity example:
examples/get_similarity_index.py - Match and mismatch assertions:
examples/asserting_match.py
Demo Images
Basic comparison:
- Expected:
- Actual:
- Result:
Colour comparison:
- Expected:
- Actual:
- Result:
Development
Install dependencies and run the tests:
pip install -r requirements.txt
python -m unittest discover -v
Contributing
Contributions are welcome through issues and pull requests. If you are proposing an API or packaging change, please include a test update alongside it.
License
This project is licensed under the MIT License. See LICENSE for details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file visual_comparison-1.0.5.tar.gz.
File metadata
- Download URL: visual_comparison-1.0.5.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5ff7888f951c3ee40ad9d7f98c4119e8f269af1927b88cffd9e8daad7971ba7
|
|
| MD5 |
77a14374da45c451f99d07bc74d57b11
|
|
| BLAKE2b-256 |
72768612879f9fb26dceee842bdae0ffcc483c159c54be86e9cf48c967e6677a
|
File details
Details for the file visual_comparison-1.0.5-py3-none-any.whl.
File metadata
- Download URL: visual_comparison-1.0.5-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dea6e34327f3e8aa873feed81c429e9011a51863e72fc4fe93c7994ff67e3861
|
|
| MD5 |
b9c69439e98e76eba5fb96f16e190a8c
|
|
| BLAKE2b-256 |
1e25bc16fe7d1ab3ff6c3c0c4664c87d4d733292dee4897c87ea66589acba20d
|