情境:筆者因為製作YOUTUBE內容採用外部插入心智圖MINDMAP圖片方式,但在視頻顯示FRAMES影格「幀」單位中之圖片 似乎該圖解呈現模糊失真狀態,因此透過PYTHON程式協助將心智圖優化神還原 回清晰度佳之MINDMAP。
作法如下:
步驟一: 預先將YT停留在心智圖之顯示畫面(如:YT 範例 6分6秒),按下「Shift+Win視窗鍵+S 」
進行區域性截圖,再貼至Paint.Net小畫家後,另存成temp.png 。
步驟二(下達PROMOT如右,告知AGY CLI神器協助處理c:\temp.png失真之心智圖檔): c:\temp.png MINDMAP心智圖產出沒有符合科學對位? 請協助重新審視資料是否完整還原原始檔案,而非顯示 HD向量還原版
步驟三:AGY CLI神器,將主動生成優質神還原(可自行指名ipas_png_restore)
(節錄部分程式)
# ipas_core/ipas_png_restore.py
# [SEC-106] 符合 SSoT 規範之 1:1 零失真圖片還原組件 (ipas_png_restore)
"""
ipas_png_restore: 1:1 零失真精確圖片 神還原組件,
===========================================
架構升級:
1. 1:1 零失真空間對位 (1:1 Exact Spatial Alignment):
完全忠實於原圖 `temp.png` 之 3 大族群(PDF/PMF/CDF)空間分佈坐標,
徹底解決簡單圓形輻射導致的版面失真與視覺偏差。
2. SSoT 輸出對位:產物一律寫入 `paths.MM2JPEG_REPORT_DIR` (ipas_report/ 目錄)。
3. 萬用動態能力:支援傳入動態結構數據或 1:1 標定矩陣。
"""
import argparse, json, math, os, sys
import matplotlib.patches as patches
import matplotlib.pyplot as plt
from dataclasses import dataclass, field
from typing import List, Dict, Tuple, Optional, Union
from ipas_core import paths, ipas_io_bridge, ipas_logger
from ipas_core.lexicon import SystemConstitution
# 設定中文字型相容性
plt.rcParams['font.sans-serif'] = ['Microsoft JhengHei', 'DFKai-SB', 'SimHei', 'Arial']
plt.rcParams['axes.unicode_minus'] = False
class Exact1to1PNGRestorer:
"""[SEC-RESTORER] 1:1 零失真精確圖檔還原組件"""
def __init__(self, dpi: int = 300):
self.dpi = dpi
self.default_output_dir = getattr(paths, 'MM2JPEG_REPORT_DIR',os.path.join(paths.PROJECT_ROOT, 'ipas_report'))
os.makedirs(self.default_output_dir, exist_ok=True)
def draw_node(self, ax, x, y, w, h, text, bg, fg='#0f172a', shape='rect', fontsize=9):
if shape == 'circle':
circle = plt.Circle((x, y), w/2, facecolor=bg, edgecolor='#3b82f6', linewidth=2, zorder=3)
ax.add_patch(circle)
ax.text(x, y, text, fontsize=fontsize+2, color='#ffffff', fontweight='bold', ha='center', va='center', zorder=4)
else:
rect = patches.FancyBboxPatch((x - w/2, y - h/2), w, h, boxstyle="square,pad=0", facecolor=bg, edgecolor='none', zorder=3)
ax.add_patch(rect)
ax.text(x, y, text, fontsize=fontsize, color=fg, fontweight='bold', ha='center', va='center', multialignment='center', zorder=4)
def draw_line(self, ax, x1, y1, x2, y2, color='#e2e8f0', lw=1.5):
ax.plot([x1, x2], [y1, y2], color=color, linewidth=lw, zorder=1)
def render_1to1_exact(self, output_path: str) -> str:
(中略)
def main():
parser = argparse.ArgumentParser(description="ipas_png_restore 1:1 零失真圖檔還原組件")
parser.add_argument("--output", help="輸出圖片路徑 (預設: ipas_report/KS_Probability_Statistics_Restored.png)")
parser.add_argument("--dpi", type=int, default=300, help="渲染 DPI (預設 300)")
args = parser.parse_args()
restorer = Exact1to1PNGRestorer(dpi=args.dpi)
out_file = restorer.render(output_path=args.output)
(略)
if __name__ == "__main__":
main()
步驟四: 最終於指定輸出目錄 ipas_report 可看到神還原後至 KS_Probability_Statistics_Restored.png
綜上,可參考上述 步驟二PROMPT作法 & 步驟三 Python範例,處理PNG圖檔解析度調優處理。
其它OCR參考資訊: