Skip to content

Commit

Permalink
change back image test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dou Du committed Dec 17, 2024
1 parent f69fafc commit 1cf9633
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/screenshot-comparison.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ jobs:
pip install --upgrade pytest
pip install --upgrade selenium
pip install --upgrade Pillow
pip install --upgrade imagededup
- uses: nanasess/setup-chromedriver@master
- run: |
export DISPLAY=:99
Expand Down
31 changes: 8 additions & 23 deletions test/test_figures.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
from imagededup.methods import PHash
from PIL import Image, ImageChops, ImageStat

# Initialize the hashing method
phasher = PHash()
image1 = Image.open('widget-01.png')
image2 = Image.open('test/widget-sample.png')

# Provide the paths to your images
image1_path = 'widget-01.png'
image2_path = 'test/widget-sample.png'
diff = ImageChops.difference(image1, image2)
stat = ImageStat.Stat(diff)

# Generate hashes for both images
hash1 = phasher.encode_image(image_file=image1_path)
hash2 = phasher.encode_image(image_file=image2_path)

# Calculate the Hamming distance between the two hashes
distance = phasher.hamming_distance(hash1, hash2)

# Print similarity score
print(f"Hamming distance between the two images: {distance}")

# Interpret the similarity
if distance == 0:
print("The images are identical!")
elif distance < 10: # Adjust threshold as needed
print("The images are very similar.")
if sum(stat.mean) == 0:
print('images are the same')
else:
raise Exception("The result is NOT the same as expected. Please check matplotlib version.")

raise Exception("The result is NOT the same as expected. Please check matplotlib version.")

0 comments on commit 1cf9633

Please sign in to comment.