Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from skimage.metrics import structural_similarity as ssim
|
|
| 3 |
import gradio as gr
|
| 4 |
import cv2
|
| 5 |
|
|
|
|
| 6 |
def calculate_similarity(img1, img2):
|
| 7 |
if len(img1.shape) == 2:
|
| 8 |
img1 = cv2.cvtColor(img1, cv2.COLOR_GRAY2RGB)
|
|
@@ -12,14 +13,19 @@ def calculate_similarity(img1, img2):
|
|
| 12 |
max_width = max(img1.shape[1], img2.shape[1])
|
| 13 |
img1_resized = cv2.resize(img1, (max_width, max_height))
|
| 14 |
img2_resized = cv2.resize(img2, (max_width, max_height))
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
|
|
|
| 18 |
def image_similarity(img1, img2):
|
| 19 |
img1 = img1.astype(np.uint8)
|
| 20 |
img2 = img2.astype(np.uint8)
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 23 |
return result
|
| 24 |
|
| 25 |
iface = gr.Interface(
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import cv2
|
| 5 |
|
| 6 |
+
# Function to calculate SSIM between two images
|
| 7 |
def calculate_similarity(img1, img2):
|
| 8 |
if len(img1.shape) == 2:
|
| 9 |
img1 = cv2.cvtColor(img1, cv2.COLOR_GRAY2RGB)
|
|
|
|
| 13 |
max_width = max(img1.shape[1], img2.shape[1])
|
| 14 |
img1_resized = cv2.resize(img1, (max_width, max_height))
|
| 15 |
img2_resized = cv2.resize(img2, (max_width, max_height))
|
| 16 |
+
|
| 17 |
+
# Calculate similarity score based on SSIM
|
| 18 |
+
ssim_score = ssim(img1_resized, img2_resized, win_size=3, multichannel=True)
|
| 19 |
+
|
| 20 |
+
return ssim_score
|
| 21 |
|
| 22 |
+
# Rest of the code remains the same
|
| 23 |
def image_similarity(img1, img2):
|
| 24 |
img1 = img1.astype(np.uint8)
|
| 25 |
img2 = img2.astype(np.uint8)
|
| 26 |
+
ssim_score = calculate_similarity(img1, img2)
|
| 27 |
+
additional_score = 0.75 # Placeholder value, replace with your own calculation
|
| 28 |
+
result = f"SSIM Score: {ssim_score:.4f}\nAdditional Score: {additional_score:.4f}"
|
| 29 |
return result
|
| 30 |
|
| 31 |
iface = gr.Interface(
|