-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dou Du
committed
Dec 17, 2024
1 parent
f69fafc
commit 1cf9633
Showing
2 changed files
with
8 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |