Skip to main content

Image Comparison Tool

Project description

logo-trans

PyPI version Python PRs Welcome License

About

Developed with Python utilizing the OpenCV library, this program compares two images of identical sizes, visually highlighting their differences by drawing red rectangles. Offering flexibility for various automation Quality Assurance (QA) tests, especially visual regression testing. Selenium-Reference

Key Features:

  • Utilizes standard Python language and specific modules for implementation.
  • Generates an output comprising copies of the 'actual' images, with discrepancies delineated by red rectangles.
  • This tool serves as a valuable asset for automated visual regression testing, facilitating precise visual comparisons to ensure the integrity and accuracy of image-based applications.

Usage

Installation

pip install visual-comparison

Configuration

All these methods can be combined based on your requirements.

Method Description
read_image Function to read image from the specified path. This can load both expected and actual images that need to be compared.
compare_images Function to compare two images. This function takes three arguments: expected_image, actual_image, and result_destination. It highlights the differences between the images with red rectangles.
check_match Function to check if two images match. This function takes two arguments: expected_image and actual_image. It returns true if both images are identical.
check_mismatch Function to check if two images do not match. This function takes two arguments: expected_image and actual_image. It returns true if the images are different.

To compare two images through visual-comparison module

1. Sample Code to get Similarity Index:

Get Similarity Index

    # Using ImageComparisonUtil to get similarity index and save output image as result.png
    # Load images to be compared
    expected_image = ImageComparisonUtil.read_image("expected.png")
    actual_image = ImageComparisonUtil.read_image("actual.png")
    
    # Provide the path to save output image
    result_destination = "result.png"
    
    # Compare the images, print the similarity index and save it as result.png
    similarity_index = ImageComparisonUtil.compare_images(expected_image, actual_image, result_destination)
    print("Similarity Index:", similarity_index)

2. Sample Code to assert match/mismatch:

Assert Match/Mismatch

    # Using ImageComparisonUtil
    # Load images to be compared
    expected_image = ImageComparisonUtil.read_image("expected.png")
    actual_image = ImageComparisonUtil.read_image("actual.png")
    
    # Asserting both images
    match_result = ImageComparisonUtil.check_match(expected_image, actual_image)
    assert match_result

Demo

  1. Demo shows how basic image comparison works.

Expected Image

expected

Actual Image

actual

Result

result

  1. Demo shows how colour comparison works.

Expected Image

expected

Actual Image

actual

Result

result

Support and Contributions

If you find this project useful, please consider giving it a star! ⭐ Your support is greatly appreciated. If you have any ideas for improvements or would like to contribute, we welcome your input and collaboration. Feel free to open an issue or submit a pull request. Thanks for your support!

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

visual_comparison-1.0.3.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

visual_comparison-1.0.3-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file visual_comparison-1.0.3.tar.gz.

File metadata

  • Download URL: visual_comparison-1.0.3.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for visual_comparison-1.0.3.tar.gz
Algorithm Hash digest
SHA256 d83beedbcb2794ef9785db211f81b6db7d5a60578bc597e71fdca97daa970a3d
MD5 0e37c835e96cf91b29a05c58d9aa0c02
BLAKE2b-256 96f4c4c55b26bdc0f827aca10f11f9e31764935c3995fcc465ef1acdb81bea63

See more details on using hashes here.

File details

Details for the file visual_comparison-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for visual_comparison-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1421325c5f9be73673ff0a0137c7fcdf5656f9cd25ab753e8659cb9b00c91549
MD5 2ca2c49097a0ceb2c91d780c3cc4f099
BLAKE2b-256 4da785d42ab0f70643af8f15b0e99390c6cbf5266571f7883b976082be67042f

See more details on using hashes here.

Supported by

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