kunkk commited on
Commit
6dbe802
·
verified ·
1 Parent(s): a548e24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -536,11 +536,13 @@ class ImageProcessor:
536
  # Create processor instance
537
  processor = ImageProcessor()
538
 
 
539
  def run_demo(input_image, threshold, enhance_contrast, denoise, show_contours,
540
  brightness, contrast, filter_type, process_mode):
541
  """主处理函数"""
542
  if input_image is None:
543
- return [None] * 9 + ["请上传图像"]
 
544
 
545
  # 处理图像
546
  results = processor.process_image(
@@ -554,18 +556,18 @@ def run_demo(input_image, threshold, enhance_contrast, denoise, show_contours,
554
  process_mode=process_mode
555
  )
556
 
 
557
  original, saliency_map, heatmap, overlayed, segmented, comparison, time_info, stats, analysis_plot = results
558
 
559
- # 如果需要显示轮廓
560
- if show_contours and saliency_map is not None and overlayed is not None:
561
  _, binary = cv2.threshold(saliency_map, 127, 255, cv2.THRESH_BINARY)
562
  contours, _ = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
563
  overlay_with_contours = overlayed.copy()
564
  cv2.drawContours(overlay_with_contours, contours, -1, (0,255,0), 2)
565
  overlayed = overlay_with_contours
566
 
567
- # 生成统计信息HTML
568
- # 生成统计信息HTML
569
  if stats:
570
  stats_html = "<div class='statistics-container' style='background: white; color: black;'>"
571
  for key, value in stats.items():
@@ -578,6 +580,19 @@ def run_demo(input_image, threshold, enhance_contrast, denoise, show_contours,
578
  stats_html += "</div>"
579
  else:
580
  stats_html = "<p style='color: black; font-weight: bold;'>无可用统计信息</p>"
 
 
 
 
 
 
 
 
 
 
 
 
 
581
 
582
  def create_comparison_view(original, result, slider_value):
583
  """创建滑块对比视图"""
 
536
  # Create processor instance
537
  processor = ImageProcessor()
538
 
539
+ # 修改 run_demo 函数
540
  def run_demo(input_image, threshold, enhance_contrast, denoise, show_contours,
541
  brightness, contrast, filter_type, process_mode):
542
  """主处理函数"""
543
  if input_image is None:
544
+ # 返回 9 个值(对应 9 个输出组件)
545
+ return [None] * 6 + ["请上传图像", None, None]
546
 
547
  # 处理图像
548
  results = processor.process_image(
 
556
  process_mode=process_mode
557
  )
558
 
559
+ # 解包结果(确保有 9 个值)
560
  original, saliency_map, heatmap, overlayed, segmented, comparison, time_info, stats, analysis_plot = results
561
 
562
+ # 如果需要显示轮廓(仅限完整模式)
563
+ if show_contours and process_mode == "完整分析" and saliency_map is not None and overlayed is not None:
564
  _, binary = cv2.threshold(saliency_map, 127, 255, cv2.THRESH_BINARY)
565
  contours, _ = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
566
  overlay_with_contours = overlayed.copy()
567
  cv2.drawContours(overlay_with_contours, contours, -1, (0,255,0), 2)
568
  overlayed = overlay_with_contours
569
 
570
+ # 生成统计信息HTML(始终处理)
 
571
  if stats:
572
  stats_html = "<div class='statistics-container' style='background: white; color: black;'>"
573
  for key, value in stats.items():
 
580
  stats_html += "</div>"
581
  else:
582
  stats_html = "<p style='color: black; font-weight: bold;'>无可用统计信息</p>"
583
+
584
+ # 返回 9 个值
585
+ return (
586
+ original,
587
+ saliency_map,
588
+ heatmap,
589
+ overlayed,
590
+ segmented,
591
+ comparison,
592
+ time_info,
593
+ stats_html, # 使用生成的 HTML
594
+ analysis_plot
595
+ )
596
 
597
  def create_comparison_view(original, result, slider_value):
598
  """创建滑块对比视图"""