|
1 |
| -from imagededup.methods import PHash |
| 1 | +from PIL import Image, ImageChops, ImageStat |
2 | 2 |
|
3 |
| -# Initialize the hashing method |
4 |
| -phasher = PHash() |
| 3 | +image1 = Image.open('widget-01.png') |
| 4 | +image2 = Image.open('test/widget-sample.png') |
5 | 5 |
|
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) |
9 | 8 |
|
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') |
25 | 11 | 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