-
-
Save Steve132/37a5f6e74d6f91b2e84df5143f19bed8 to your computer and use it in GitHub Desktop.
groupimages.py
This file contains hidden or 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
# algorithm by chatgpt. Test by Steve132 | |
images=set([0,1,2,3,5,7,9,51,52,53,55,57]) | |
idx=0 | |
total_images = len(images) | |
while len(images) > 0: | |
image1 = list(images)[0] | |
similar_images = [image1] | |
for image2 in list(images)[1:]: | |
ssim_resized = abs(image1-image2) | |
if ssim_resized < 4: # similarity threshold | |
similar_images.append(image2) | |
if len(similar_images) > 1: | |
for image in similar_images: | |
print('image'+str(image)+f' in group_{idx}', image) | |
images.remove(image) | |
idx += 1 | |
else: | |
# Unmatched images are copied to a separate directory | |
print('image'+str(similar_images[0])+' is unmatched') | |
images.remove(similar_images[0]) | |
print(f"Processing: {idx}/{total_images} groups. {((idx)/total_images)*100:.2f}% done.") |
This file contains hidden or 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
image0 in group_0 0 | |
image1 in group_0 1 | |
image2 in group_0 2 | |
image3 in group_0 3 | |
Processing: 1/12 groups. 8.33% done. | |
image5 in group_1 5 | |
image7 in group_1 7 | |
Processing: 2/12 groups. 16.67% done. | |
image9 is unmatched | |
Processing: 2/12 groups. 16.67% done. | |
image51 in group_2 51 | |
image52 in group_2 52 | |
image53 in group_2 53 | |
Processing: 3/12 groups. 25.00% done. | |
image55 in group_3 55 | |
image57 in group_3 57 | |
Processing: 4/12 groups. 33.33% done. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment