Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import numpy as np
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import cv2
|
| 4 |
|
|
@@ -7,9 +8,7 @@ def calculate_similarity(img1, img2):
|
|
| 7 |
img1 = cv2.cvtColor(img1, cv2.COLOR_GRAY2RGB)
|
| 8 |
if len(img2.shape) == 2:
|
| 9 |
img2 = cv2.cvtColor(img2, cv2.COLOR_GRAY2RGB)
|
| 10 |
-
|
| 11 |
-
diff = cv2.absdiff(img1_resized, img2)
|
| 12 |
-
similarity_score = np.mean(diff)
|
| 13 |
return similarity_score
|
| 14 |
|
| 15 |
def image_similarity(img1, img2):
|
|
@@ -29,5 +28,5 @@ iface = gr.Interface(
|
|
| 29 |
title="Image Similarity Calculator",
|
| 30 |
description="Upload two images to compute their similarity."
|
| 31 |
)
|
| 32 |
-
iface.launch()
|
| 33 |
|
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
+
from skimage.metrics import structural_similarity as ssim
|
| 3 |
import gradio as gr
|
| 4 |
import cv2
|
| 5 |
|
|
|
|
| 8 |
img1 = cv2.cvtColor(img1, cv2.COLOR_GRAY2RGB)
|
| 9 |
if len(img2.shape) == 2:
|
| 10 |
img2 = cv2.cvtColor(img2, cv2.COLOR_GRAY2RGB)
|
| 11 |
+
similarity_score = ssim(img1, img2, multichannel=True)
|
|
|
|
|
|
|
| 12 |
return similarity_score
|
| 13 |
|
| 14 |
def image_similarity(img1, img2):
|
|
|
|
| 28 |
title="Image Similarity Calculator",
|
| 29 |
description="Upload two images to compute their similarity."
|
| 30 |
)
|
|
|
|
| 31 |
|
| 32 |
+
iface.launch(share=True)
|