Files
shellfiles/bin/wsl/similar_images.py
2026-01-19 21:36:25 -05:00

38 lines
1.2 KiB
Python
Executable File

#!/usr/bin/python3
import argparse
from skimage.metrics import structural_similarity as ssim
import cv2
def are_images_similar(image_path1, image_path2, similarity_threshold=0.95):
# Load both images in grayscale mode
image1 = cv2.imread(image_path1, cv2.IMREAD_GRAYSCALE)
image2 = cv2.imread(image_path2, cv2.IMREAD_GRAYSCALE)
# Check if images are the same size
if image1.shape != image2.shape:
print("Images have different dimensions.")
return False
# Calculate the SSIM between the two images
score, _ = ssim(image1, image2, full=True)
# Return True if the score is above the similarity threshold
return score >= similarity_threshold
def main():
# Set up argument parser
parser = argparse.ArgumentParser(description="Compare two images for similarity.")
parser.add_argument("image1_path", type=str, help="Path to the first image file")
parser.add_argument("image2_path", type=str, help="Path to the second image file")
# Parse arguments
args = parser.parse_args()
# Compare images
if are_images_similar(args.image1_path, args.image2_path):
print(f"\nFound similar videos:\n{args.image1_path} and {args.image2_path}\n")
if __name__ == "__main__":
main()