omar87 commited on
Commit
befd8b5
·
1 Parent(s): 8c2c1dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
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,9 +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
- similarity_score = ssim(img1_resized, img2_resized, win_size=3, 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)
 
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
+ # 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)