shriarul5273 commited on
Commit
35dd5f2
Β·
1 Parent(s): 6dbd5d6

Add method name labels to images in slider comparison

Browse files
Files changed (2) hide show
  1. app.py +31 -1
  2. app_local.py +31 -1
app.py CHANGED
@@ -434,6 +434,36 @@ def create_slider_comparison(left_img, right_img, method1, method2, progress=gr.
434
  if result1 is None or result2 is None:
435
  return None, "❌ Processing failed."
436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
437
  status = f"""🎚️ **Interactive Comparison Ready**
438
 
439
  **{m1.display_name}:** {status1.split(':')[-1].strip() if ':' in status1 else status1}
@@ -441,7 +471,7 @@ def create_slider_comparison(left_img, right_img, method1, method2, progress=gr.
441
 
442
  πŸ’‘ **Tip:** Drag the slider to compare the two methods interactively!"""
443
 
444
- return (result1, result2), status
445
 
446
 
447
  def create_app() -> gr.Blocks:
 
434
  if result1 is None or result2 is None:
435
  return None, "❌ Processing failed."
436
 
437
+ # Add method names to the top of the images for slider comparison
438
+ def add_method_label(img: np.ndarray, method_name: str) -> np.ndarray:
439
+ """Add method name label to the top of the image"""
440
+ h, w = img.shape[:2]
441
+
442
+ # Create new image with space for label
443
+ labeled_img = np.zeros((h + 40, w, 3), dtype=np.uint8)
444
+ labeled_img.fill(255) # White background for label area
445
+
446
+ # Place original image below the label area
447
+ labeled_img[40:, :] = img
448
+
449
+ # Add method name label
450
+ font = cv2.FONT_HERSHEY_SIMPLEX
451
+ font_scale = 0.7
452
+ font_thickness = 2
453
+
454
+ # Calculate text size and position
455
+ text_size = cv2.getTextSize(method_name, font, font_scale, font_thickness)[0]
456
+ text_x = (w - text_size[0]) // 2
457
+ text_y = 28 # Position in the label area
458
+
459
+ cv2.putText(labeled_img, method_name, (text_x, text_y), font, font_scale, (0, 0, 0), font_thickness)
460
+
461
+ return labeled_img
462
+
463
+ # Add labels to both images
464
+ labeled_result1 = add_method_label(result1, m1.display_name)
465
+ labeled_result2 = add_method_label(result2, m2.display_name)
466
+
467
  status = f"""🎚️ **Interactive Comparison Ready**
468
 
469
  **{m1.display_name}:** {status1.split(':')[-1].strip() if ':' in status1 else status1}
 
471
 
472
  πŸ’‘ **Tip:** Drag the slider to compare the two methods interactively!"""
473
 
474
+ return (labeled_result1, labeled_result2), status
475
 
476
 
477
  def create_app() -> gr.Blocks:
app_local.py CHANGED
@@ -553,6 +553,36 @@ def create_app() -> gr.Blocks:
553
  if result1 is None or result2 is None:
554
  return None, "❌ Processing failed."
555
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
556
  status = f"""🎚️ **Interactive Comparison Ready**
557
 
558
  **{m1.display_name}:** {status1.split(':')[-1].strip() if ':' in status1 else status1}
@@ -560,7 +590,7 @@ def create_app() -> gr.Blocks:
560
 
561
  πŸ’‘ **Tip:** Drag the slider to compare the two methods interactively!"""
562
 
563
- return (result1, result2), status
564
 
565
  slider_compare_btn.click(
566
  fn=create_slider_comparison,
 
553
  if result1 is None or result2 is None:
554
  return None, "❌ Processing failed."
555
 
556
+ # Add method names to the top of the images for slider comparison
557
+ def add_method_label(img: np.ndarray, method_name: str) -> np.ndarray:
558
+ """Add method name label to the top of the image"""
559
+ h, w = img.shape[:2]
560
+
561
+ # Create new image with space for label
562
+ labeled_img = np.zeros((h + 40, w, 3), dtype=np.uint8)
563
+ labeled_img.fill(255) # White background for label area
564
+
565
+ # Place original image below the label area
566
+ labeled_img[40:, :] = img
567
+
568
+ # Add method name label
569
+ font = cv2.FONT_HERSHEY_SIMPLEX
570
+ font_scale = 0.7
571
+ font_thickness = 2
572
+
573
+ # Calculate text size and position
574
+ text_size = cv2.getTextSize(method_name, font, font_scale, font_thickness)[0]
575
+ text_x = (w - text_size[0]) // 2
576
+ text_y = 28 # Position in the label area
577
+
578
+ cv2.putText(labeled_img, method_name, (text_x, text_y), font, font_scale, (0, 0, 0), font_thickness)
579
+
580
+ return labeled_img
581
+
582
+ # Add labels to both images
583
+ labeled_result1 = add_method_label(result1, m1.display_name)
584
+ labeled_result2 = add_method_label(result2, m2.display_name)
585
+
586
  status = f"""🎚️ **Interactive Comparison Ready**
587
 
588
  **{m1.display_name}:** {status1.split(':')[-1].strip() if ':' in status1 else status1}
 
590
 
591
  πŸ’‘ **Tip:** Drag the slider to compare the two methods interactively!"""
592
 
593
+ return (labeled_result1, labeled_result2), status
594
 
595
  slider_compare_btn.click(
596
  fn=create_slider_comparison,