MCPcopy Create free account
hub / github.com/BIT-DataLab/Edit-Banana / refine_from_rendered_comparison

Function refine_from_rendered_comparison

modules/refinement_processor.py:532–649  ·  view source on GitHub ↗

基于渲染对比进行补救 流程: 1. 对比原图和渲染后的图像 2. 找出差异区域(遗漏的内容) 3. 从原图裁剪这些区域 4. 作为picture元素添加 Args: elements: 现有元素列表 original_path: 原始图片路径 rendered_path: DrawIO渲染后的图片路径 config: 配置参数 - diff_threshold: 差异阈值(默认30) - min_regio

(elements: List[ElementInfo],
                                     original_path: str,
                                     rendered_path: str,
                                     config: Dict = None)

Source from the content-addressed store, hash-verified

530
531
532def refine_from_rendered_comparison(elements: List[ElementInfo],
533 original_path: str,
534 rendered_path: str,
535 config: Dict = None) -> Dict[str, Any]:
536 """
537 基于渲染对比进行补救
538
539 流程:
540 1. 对比原图和渲染后的图像
541 2. 找出差异区域(遗漏的内容)
542 3. 从原图裁剪这些区域
543 4. 作为picture元素添加
544
545 Args:
546 elements: 现有元素列表
547 original_path: 原始图片路径
548 rendered_path: DrawIO渲染后的图片路径
549 config: 配置参数
550 - diff_threshold: 差异阈值(默认30)
551 - min_region_area: 最小区域面积(默认300)
552 - expand_margin: 裁剪扩展边距(默认5)
553
554 Returns:
555 {
556 'elements': 更新后的元素列表,
557 'comparison': 对比结果,
558 'new_count': 新增元素数量
559 }
560
561 使用示例:
562 result = refine_from_rendered_comparison(
563 elements,
564 "original.png",
565 "rendered.png"
566 )
567 print(f"相似度: {result['comparison']['overall_similarity']}%")
568 print(f"新增: {result['new_count']}个元素")
569 final_elements = result['elements']
570 """
571 from .metric_evaluator import compare_with_rendered
572 import io
573 import base64
574
575 default_config = {
576 'diff_threshold': 30,
577 'min_region_area': 300,
578 'expand_margin': 5,
579 'default_confidence': 0.4 # 渲染对比补救的置信度较低
580 }
581 cfg = {**default_config, **(config or {})}
582
583 # 1. 对比原图和渲染图
584 comparison = compare_with_rendered(original_path, rendered_path, {
585 'diff_threshold': cfg['diff_threshold'],
586 'min_region_area': cfg['min_region_area'],
587 'merge_distance': 15
588 })
589

Callers

nothing calls this directly

Calls 3

compare_with_renderedFunction · 0.85
ElementInfoClass · 0.85
BoundingBoxClass · 0.85

Tested by

no test coverage detected