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

Function detect_missing_from_rendered_diff

modules/metric_evaluator.py:1628–1706  ·  view source on GitHub ↗

从渲染对比中检测遗漏区域,并裁剪保存 这个函数会: 1. 对比原图和渲染图 2. 找出遗漏的区域 3. 从原图裁剪这些区域 4. 可选保存为单独的图片 Args: original_path: 原始图片路径 rendered_path: 渲染后的图片路径 output_dir: 裁剪区域保存目录(可选) Returns: 遗漏区域列表,每个包含: - bbox: 边界框 - cropped_image:

(original_path: str,
                                       rendered_path: str,
                                       output_dir: str = None)

Source from the content-addressed store, hash-verified

1626
1627
1628def detect_missing_from_rendered_diff(original_path: str,
1629 rendered_path: str,
1630 output_dir: str = None) -> List[Dict]:
1631 """
1632 从渲染对比中检测遗漏区域,并裁剪保存
1633
1634 这个函数会:
1635 1. 对比原图和渲染图
1636 2. 找出遗漏的区域
1637 3. 从原图裁剪这些区域
1638 4. 可选保存为单独的图片
1639
1640 Args:
1641 original_path: 原始图片路径
1642 rendered_path: 渲染后的图片路径
1643 output_dir: 裁剪区域保存目录(可选)
1644
1645 Returns:
1646 遗漏区域列表,每个包含:
1647 - bbox: 边界框
1648 - cropped_image: PIL Image对象
1649 - base64: base64编码的图像
1650
1651 使用示例:
1652 missing = detect_missing_from_rendered_diff("original.png", "rendered.png")
1653 for i, region in enumerate(missing):
1654 # 可以直接用于生成XML
1655 base64_data = region['base64']
1656 bbox = region['bbox']
1657 """
1658 import base64
1659 from io import BytesIO
1660
1661 # 检测差异区域
1662 result = compare_with_rendered(original_path, rendered_path, {
1663 'diff_threshold': 25,
1664 'min_region_area': 300,
1665 'merge_distance': 15
1666 })
1667
1668 if not result.get('missing_regions'):
1669 return []
1670
1671 # 读取原图
1672 original_pil = Image.open(original_path).convert("RGB")
1673
1674 missing_elements = []
1675
1676 for i, region in enumerate(result['missing_regions']):
1677 x1, y1, x2, y2 = region['bbox']
1678
1679 # 裁剪
1680 cropped = original_pil.crop((x1, y1, x2, y2))
1681
1682 # 转base64
1683 buffer = BytesIO()
1684 cropped.save(buffer, format='PNG')
1685 b64_data = base64.b64encode(buffer.getvalue()).decode('utf-8')

Callers

nothing calls this directly

Calls 1

compare_with_renderedFunction · 0.85

Tested by

no test coverage detected