commit 7fd88244b5720f95562dca5cd185324727312505
parent 871f8fdb443772ac58ee574b826d5042c29038cc
Author: minerva-jupiter <ryouturn@gmail.com>
Date: Tue, 20 Jan 2026 21:24:52 +0900
feat(image-comparison): Add utility for structural image similarity comparison
Diffstat:
1 file changed, 22 insertions(+), 0 deletions(-)
diff --git a/imagecompare.py b/imagecompare.py
@@ -0,0 +1,22 @@
+import cv2
+from skimage.metrics import structural_similarity as ssim
+
+def judge_image_difference(image_path_a, image_path_b):
+ img_a = cv2.imread(image_path_a)
+ img_b = cv2.imread(image_path_b)
+
+ if img_a.shape != img_b.shape:
+ return False, 0.0
+
+ gray_a = cv2.cvtColor(img_a, cv2.COLOR_BGR2GRAY)
+ gray_b = cv2.cvtColor(img_b, cv2.COLOR_BGR2GRAY)
+
+ score, _ = ssim(gray_a, gray_b, full=True)
+
+ is_identical = score == 1.0
+ return is_identical, score
+
+if __name__ == "__main__":
+ identical, similarity_score = judge_image_difference(r"C:\Users\ryout\Downloads\2026_01_20_21_14_33.png", r"C:\Users\ryout\Downloads\2026_01_20_21_15_05.png")
+ print(f"Identical: {identical}")
+ print(f"Similarity Score: {similarity_score}")