omar87 commited on
Commit
86a9bf1
·
1 Parent(s): befd8b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -14
app.py CHANGED
@@ -3,7 +3,6 @@ from skimage.metrics import structural_similarity as ssim
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,19 +12,9 @@ def calculate_similarity(img1, img2):
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
- # Additional score calculation after text removal (modify this as per your requirement)
21
- text_removed_score = 0.75 # Placeholder value, replace with your own calculation
22
-
23
- # Combine the scores or choose the desired score
24
- combined_score = (ssim_score + text_removed_score) / 2
25
-
26
- return combined_score
27
 
28
- # Rest of the code remains the same
29
  def image_similarity(img1, img2):
30
  img1 = img1.astype(np.uint8)
31
  img2 = img2.astype(np.uint8)
@@ -44,4 +33,4 @@ iface = gr.Interface(
44
  description="Upload two images to compute their similarity."
45
  )
46
 
47
- iface.launch()
 
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
  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
+ similarity_score = ssim(img1_resized, img2_resized, multichannel=True)
16
+ return similarity_score
 
 
 
 
 
 
 
 
 
17
 
 
18
  def image_similarity(img1, img2):
19
  img1 = img1.astype(np.uint8)
20
  img2 = img2.astype(np.uint8)
 
33
  description="Upload two images to compute their similarity."
34
  )
35
 
36
+ iface.launch(share=True)