Skip to content

Commit 1cf9633

Browse files
author
Dou Du
committed
change back image test
1 parent f69fafc commit 1cf9633

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

Diff for: .github/workflows/screenshot-comparison.yml

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ jobs:
4040
pip install --upgrade pytest
4141
pip install --upgrade selenium
4242
pip install --upgrade Pillow
43-
pip install --upgrade imagededup
44-
4543
- uses: nanasess/setup-chromedriver@master
4644
- run: |
4745
export DISPLAY=:99

Diff for: test/test_figures.py

+8-23
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1-
from imagededup.methods import PHash
1+
from PIL import Image, ImageChops, ImageStat
22

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

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

10-
# Generate hashes for both images
11-
hash1 = phasher.encode_image(image_file=image1_path)
12-
hash2 = phasher.encode_image(image_file=image2_path)
13-
14-
# Calculate the Hamming distance between the two hashes
15-
distance = phasher.hamming_distance(hash1, hash2)
16-
17-
# Print similarity score
18-
print(f"Hamming distance between the two images: {distance}")
19-
20-
# Interpret the similarity
21-
if distance == 0:
22-
print("The images are identical!")
23-
elif distance < 10: # Adjust threshold as needed
24-
print("The images are very similar.")
9+
if sum(stat.mean) == 0:
10+
print('images are the same')
2511
else:
26-
raise Exception("The result is NOT the same as expected. Please check matplotlib version.")
27-
12+
raise Exception("The result is NOT the same as expected. Please check matplotlib version.")

0 commit comments

Comments
 (0)