vault backup: 2026-04-14 14:01:52
75
Dehaze/Mineru_api_client-V1.py
Normal file
@@ -0,0 +1,75 @@
|
||||
import os
|
||||
import requests
|
||||
import zipfile
|
||||
import io
|
||||
|
||||
# 1. 配置基础参数
|
||||
url = "http://10.168.1.103:4000/extract" # 请确保此处的 IP 和端口与服务端保持一致
|
||||
source_dir = "./Papers/ORI_PDF"
|
||||
target_dir = "./Papers/ORI_MD"
|
||||
|
||||
# 2. 确保源目录存在,避免报错
|
||||
if not os.path.exists(source_dir):
|
||||
print(f"错误: 找不到源文件夹 '{source_dir}'")
|
||||
exit(1)
|
||||
|
||||
# 确保目标主文件夹存在
|
||||
os.makedirs(target_dir, exist_ok=True)
|
||||
|
||||
# 3. 遍历源文件夹下的所有文件
|
||||
for filename in os.listdir(source_dir):
|
||||
# 只处理 PDF 文件
|
||||
if not filename.lower().endswith(".pdf"):
|
||||
continue
|
||||
|
||||
file_path = os.path.join(source_dir, filename)
|
||||
# 获取去掉 .pdf 后缀的文件名
|
||||
pdf_name_no_ext = os.path.splitext(filename)[0]
|
||||
|
||||
# 对应的输出文件夹路径
|
||||
output_folder = os.path.join(target_dir, pdf_name_no_ext)
|
||||
|
||||
# ==========================================
|
||||
# 【新增逻辑】:检查是否已经处理过
|
||||
# 如果输出文件夹已存在,且内部有文件,则视为已转换,直接跳过
|
||||
# ==========================================
|
||||
if os.path.exists(output_folder) and len(os.listdir(output_folder)) > 0:
|
||||
print(f"⏩ 已存在转换结果,跳过处理: {filename}")
|
||||
continue
|
||||
|
||||
print(f"正在上传并处理 {filename}...")
|
||||
|
||||
try:
|
||||
# 4. 发送请求
|
||||
with open(file_path, "rb") as f:
|
||||
files = {"file": (filename, f, "application/pdf")}
|
||||
response = requests.post(url, files=files)
|
||||
|
||||
# 5. 处理响应结果
|
||||
if response.status_code == 200:
|
||||
# 【新增防护】:检查服务端是否返回了包含报错信息的 JSON
|
||||
if response.headers.get('content-type') == 'application/json':
|
||||
error_msg = response.json()
|
||||
print(f"❌ 服务端处理失败 ({filename}):{error_msg.get('message', '未知错误')}")
|
||||
continue # 跳过解压,处理下一个
|
||||
|
||||
# 确保该 PDF 专属的输出文件夹存在
|
||||
os.makedirs(output_folder, exist_ok=True)
|
||||
|
||||
# 核心:使用 io.BytesIO 直接在内存中读取 zip 内容并解压
|
||||
try:
|
||||
with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:
|
||||
zip_ref.extractall(output_folder)
|
||||
print(f"✅ 成功!已解压并保存至文件夹: {output_folder}")
|
||||
except zipfile.BadZipFile:
|
||||
print(f"❌ 失败!{filename} 返回的内容不是有效的 ZIP 格式。")
|
||||
else:
|
||||
print(f"❌ 失败!{filename} 状态码: {response.status_code}, 报错: {response.text}")
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"❌ 网络请求异常 ({filename}): {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ 处理 {filename} 时发生未知错误: {e}")
|
||||
|
||||
print("-" * 30)
|
||||
print("批量处理任务结束!")
|
||||
104
Dehaze/Mineru_api_client-V2.py
Normal file
@@ -0,0 +1,104 @@
|
||||
import os
|
||||
import requests
|
||||
import zipfile
|
||||
import io
|
||||
import shutil # 【新增】用于删除非空文件夹
|
||||
|
||||
# 1. 配置基础参数
|
||||
url = "http://10.168.1.103:4000/extract" # 请确保此处的 IP 和端口与服务端保持一致
|
||||
source_dir = "./Papers/ORI_PDF"
|
||||
target_dir = "./Papers/ORI_MD"
|
||||
|
||||
# 2. 确保源目录存在,避免报错
|
||||
if not os.path.exists(source_dir):
|
||||
print(f"错误: 找不到源文件夹 '{source_dir}'")
|
||||
exit(1)
|
||||
|
||||
# 确保目标主文件夹存在
|
||||
os.makedirs(target_dir, exist_ok=True)
|
||||
|
||||
# 3. 遍历源文件夹下的所有文件进行上传处理
|
||||
for filename in os.listdir(source_dir):
|
||||
# 只处理 PDF 文件
|
||||
if not filename.lower().endswith(".pdf"):
|
||||
continue
|
||||
|
||||
file_path = os.path.join(source_dir, filename)
|
||||
# 获取去掉 .pdf 后缀的文件名
|
||||
pdf_name_no_ext = os.path.splitext(filename)[0]
|
||||
|
||||
# 对应的输出文件夹路径
|
||||
output_folder = os.path.join(target_dir, pdf_name_no_ext)
|
||||
|
||||
# ==========================================
|
||||
# 检查是否已经处理过
|
||||
# 如果输出文件夹已存在,且内部有文件,则视为已转换,直接跳过
|
||||
# ==========================================
|
||||
if os.path.exists(output_folder) and len(os.listdir(output_folder)) > 0:
|
||||
print(f"⏩ 已存在转换结果,跳过处理: {filename}")
|
||||
continue
|
||||
|
||||
print(f"正在上传并处理 {filename}...")
|
||||
|
||||
try:
|
||||
# 4. 发送请求
|
||||
with open(file_path, "rb") as f:
|
||||
files = {"file": (filename, f, "application/pdf")}
|
||||
response = requests.post(url, files=files)
|
||||
|
||||
# 5. 处理响应结果
|
||||
if response.status_code == 200:
|
||||
# 检查服务端是否返回了包含报错信息的 JSON
|
||||
if response.headers.get('content-type') == 'application/json':
|
||||
error_msg = response.json()
|
||||
print(f"❌ 服务端处理失败 ({filename}):{error_msg.get('message', '未知错误')}")
|
||||
continue # 跳过解压,处理下一个
|
||||
|
||||
# 确保该 PDF 专属的输出文件夹存在
|
||||
os.makedirs(output_folder, exist_ok=True)
|
||||
|
||||
# 核心:使用 io.BytesIO 直接在内存中读取 zip 内容并解压
|
||||
try:
|
||||
with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:
|
||||
zip_ref.extractall(output_folder)
|
||||
print(f"✅ 成功!已解压并保存至文件夹: {output_folder}")
|
||||
except zipfile.BadZipFile:
|
||||
print(f"❌ 失败!{filename} 返回的内容不是有效的 ZIP 格式。")
|
||||
else:
|
||||
print(f"❌ 失败!{filename} 状态码: {response.status_code}, 报错: {response.text}")
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"❌ 网络请求异常 ({filename}): {e}")
|
||||
except Exception as e:
|
||||
print(f"❌ 处理 {filename} 时发生未知错误: {e}")
|
||||
|
||||
print("-" * 30)
|
||||
print("转换任务结束,开始进行文件夹同步清理...")
|
||||
|
||||
# ==========================================
|
||||
# 【新增逻辑】:反向比对,清理多余的 MD 文件夹
|
||||
# ==========================================
|
||||
# 1. 收集当前 ORI_PDF 中所有有效的 PDF 名字(不含后缀)
|
||||
valid_pdf_names = set()
|
||||
for filename in os.listdir(source_dir):
|
||||
if filename.lower().endswith(".pdf"):
|
||||
valid_pdf_names.add(os.path.splitext(filename)[0])
|
||||
|
||||
# 2. 遍历 ORI_MD 文件夹
|
||||
if os.path.exists(target_dir):
|
||||
for folder_name in os.listdir(target_dir):
|
||||
folder_path = os.path.join(target_dir, folder_name)
|
||||
|
||||
# 仅处理文件夹(以防里面有意外的独立文件)
|
||||
if os.path.isdir(folder_path):
|
||||
# 3. 如果这个文件夹的名字不在有效的 PDF 列表中,说明是被删掉的“孤儿”
|
||||
if folder_name not in valid_pdf_names:
|
||||
print(f"🧹 发现多余文件,正在清理: {folder_name}")
|
||||
try:
|
||||
# 使用 shutil.rmtree 删除整个文件夹及其内部所有内容
|
||||
shutil.rmtree(folder_path)
|
||||
except Exception as e:
|
||||
print(f"❌ 删除 {folder_name} 时发生错误: {e}")
|
||||
|
||||
print("-" * 30)
|
||||
print("所有批量任务彻底完成!")
|
||||
51
Dehaze/Mineru_api_server-V1.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import os
|
||||
import uuid
|
||||
import shutil
|
||||
import subprocess
|
||||
from fastapi import FastAPI, UploadFile, File
|
||||
from fastapi.responses import FileResponse
|
||||
import uvicorn
|
||||
|
||||
app = FastAPI(title="MinerU Extraction API")
|
||||
|
||||
@app.post("/extract")
|
||||
def extract_document(file: UploadFile = File(...)):
|
||||
# 1. 创建独立的任务文件夹,防止多个请求同时发生时文件冲突
|
||||
task_id = str(uuid.uuid4())[:8]
|
||||
work_dir = os.path.abspath(f"./api_workspace/{task_id}")
|
||||
out_dir = os.path.join(work_dir, "OUT")
|
||||
os.makedirs(work_dir, exist_ok=True)
|
||||
|
||||
input_file_path = os.path.join(work_dir, file.filename)
|
||||
|
||||
try:
|
||||
# 2. 接收并保存客户端上传的文件
|
||||
print(f"[Task {task_id}] 收到文件: {file.filename},开始处理...")
|
||||
with open(input_file_path, "wb") as buffer:
|
||||
shutil.copyfileobj(file.file, buffer)
|
||||
|
||||
# 3. 调用你刚刚跑通的 MinerU 命令行
|
||||
# 相当于在终端执行 mineru -p xxx -o xxx
|
||||
subprocess.run(["mineru", "-p", input_file_path, "-o", out_dir], check=True)
|
||||
|
||||
# 4. 将 MinerU 的输出结果打包成 ZIP 文件
|
||||
print(f"[Task {task_id}] 解析完成,正在打包结果...")
|
||||
zip_base_path = os.path.join(work_dir, "result")
|
||||
shutil.make_archive(zip_base_path, 'zip', out_dir)
|
||||
zip_file_path = f"{zip_base_path}.zip"
|
||||
|
||||
# 5. 将 ZIP 文件作为响应返回给客户端
|
||||
return FileResponse(
|
||||
zip_file_path,
|
||||
media_type="application/zip",
|
||||
filename=f"parsed_{file.filename}.zip"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 绑定到 0.0.0.0 代表监听本机所有 IP (包括 192.168.4.6)
|
||||
# 端口设置为你要求的 5000
|
||||
print("🚀 MinerU API 启动成功!监听地址: http://192.168.4.6:5000")
|
||||
uvicorn.run(app, host="0.0.0.0", port=5000)
|
||||
66
Dehaze/Mineru_api_server-V2.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import os
|
||||
import uuid
|
||||
import shutil
|
||||
import subprocess
|
||||
from fastapi import FastAPI, UploadFile, File, BackgroundTasks # 1. 导入 BackgroundTasks
|
||||
from fastapi.responses import FileResponse
|
||||
import uvicorn
|
||||
|
||||
app = FastAPI(title="MinerU Extraction API")
|
||||
|
||||
# 定义一个清理函数
|
||||
def cleanup_task_dir(dir_path: str):
|
||||
"""删除指定的文件夹及其所有内容"""
|
||||
if os.path.exists(dir_path):
|
||||
shutil.rmtree(dir_path)
|
||||
print(f"🧹 已自动清理临时目录: {dir_path}")
|
||||
|
||||
@app.post("/extract")
|
||||
async def extract_document(background_tasks: BackgroundTasks, file: UploadFile = File(...)): # 2. 注入后台任务参数
|
||||
# 1. 创建独立的任务文件夹
|
||||
task_id = str(uuid.uuid4())[:8]
|
||||
work_dir = os.path.abspath(f"./api_workspace/{task_id}")
|
||||
out_dir = os.path.join(work_dir, "OUT")
|
||||
os.makedirs(work_dir, exist_ok=True)
|
||||
|
||||
input_file_path = os.path.join(work_dir, file.filename)
|
||||
|
||||
try:
|
||||
# 2. 接收并保存文件
|
||||
print(f"[Task {task_id}] 收到文件: {file.filename},开始处理...")
|
||||
with open(input_file_path, "wb") as buffer:
|
||||
shutil.copyfileobj(file.file, buffer)
|
||||
|
||||
# 3. 执行 MinerU 命令
|
||||
subprocess.run(["mineru", "-p", input_file_path, "-o", out_dir], check=True)
|
||||
|
||||
# 4. 穿透外层冗余文件夹,寻找真实的输出目录
|
||||
target_zip_dir = out_dir
|
||||
for root, dirs, files in os.walk(out_dir):
|
||||
if any(f.endswith('.md') for f in files):
|
||||
target_zip_dir = root
|
||||
break
|
||||
|
||||
# 5. 打包结果
|
||||
zip_base_path = os.path.join(work_dir, "result")
|
||||
shutil.make_archive(zip_base_path, 'zip', target_zip_dir)
|
||||
zip_file_path = f"{zip_base_path}.zip"
|
||||
|
||||
# 6. 【核心改进】:添加后台任务,在响应发送后删除 work_dir
|
||||
background_tasks.add_task(cleanup_task_dir, work_dir)
|
||||
|
||||
# 7. 返回给客户端
|
||||
return FileResponse(
|
||||
zip_file_path,
|
||||
media_type="application/zip",
|
||||
filename=f"parsed_{file.filename}.zip"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
# 如果出错了,也尝试清理一下该任务的文件夹,防止空间占用
|
||||
background_tasks.add_task(cleanup_task_dir, work_dir)
|
||||
return {"status": "error", "message": str(e)}
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🚀 MinerU API 启动成功!监听地址: http://192.168.4.6:5000")
|
||||
uvicorn.run(app, host="0.0.0.0", port=5000)
|
||||
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 4.2 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 7.4 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 139 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 6.2 KiB |
|
After Width: | Height: | Size: 194 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 4.8 KiB |
|
After Width: | Height: | Size: 6.5 KiB |
|
After Width: | Height: | Size: 6.6 KiB |
|
After Width: | Height: | Size: 5.8 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 176 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 6.0 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 8.1 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 6.7 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 3.6 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 70 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 2.6 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 6.5 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 3.2 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
434
Dehaze/Papers/ORI_MD/translation-去雾/translation-去雾.md
Normal file
@@ -0,0 +1,434 @@
|
||||
# 1 Introduction
|
||||
|
||||
In laparoscopic surgery, high-frequency electroknife, ultrasound knife and other energy instruments are widely used for tissue cutting, coagulation and separation. The moment these devices come into contact with biological tissues, they convert electrical or mechanical energy into heat, causing the intracellular fluid to boil, vaporize, and then burst, releasing a mixed aerosol containing water vapor, cell debris, carbonized particles and harmful chemicals, known as "surgical smoke". while the relatively closed and humid environment in the abdominal cavity (relative humidity is often close to 100%)The temperature difference between the lens and the endoscope lens can easily lead to condensation on the lens surface to form water mist. This visual degradation, which is composed of surgical fumes and lens water mist, is highly dynamic and complex. It not only reduces the contrast and clarity of the image and obscures key anatomical structures such as blood vessels and bile ducts in the gallbladder triangle, but can also lead to color distortion and affect doctors' judgment of tissue activity. In severe cases, the field of view is completely obstructed, and doctors are forced to interrupt the operation, repeatedly pulling out the lens for wiping or waiting for the smoke to dissipate. According to statistics, this not only significantly prolongs the operation time and increases the risk of anesthesia, but can also lead to serious complications such as vascular or organ damage due to blind operation.
|
||||
|
||||
At present, clinical practice mainly relies on physical means to remove smoke, including passive smoke extraction by opening the valve on the trocar, or using an active smoking device with a special smoking pipe or electric knife with smoking function, or Preoperative lens anti-fog treatment with iodophor or anti-fog oil to wipe the lens preoperatively. However, these methods often have problems such as manual operation by doctors and short effective time for defogging. In view of the limitations of physical means, computer vision-based image dehazing technology (Dehazing) came into being. Through algorithm post-processing, clear fog-free images are restored from degraded foggy images in real time, so as to achieve "virtual smoke
|
||||
|
||||
exhaust". This can not only ensure a clear field of view, but also avoid the interference of physical smoke exhaust on pneumoperitoneal pressure, which is an important research direction of smart medicine and computer-aided surgery (CAS).
|
||||
|
||||
However, in the face of drastic changes from trace fog to heavy scorched smoke, the network model with a single weight is often difficult to take into account all scenarios: it is easy to over-dehaze in light fog and cause color distortion, while under heavy fog, residual noise may remain. To this end, an adaptive dehazing network (Yun-Trans) based on dynamic Mixture of Experts (MoE) is further designed. The network introduces "fog concentration perception" and "dynamic weight generation" mechanisms, aiming to achieve accurate matching and adaptive processing of different surgical smoke scenarios.
|
||||
|
||||
# 2 Method
|
||||
|
||||
# 2.1 Construction of laparoscopic fog image model
|
||||
|
||||
# 2.1.1 Microscopic physical properties and scattering theory of laparoscopic aerosols
|
||||
|
||||
Laparoscopic surgery is performed in a relatively enclosed, tiny space filled with carbon dioxide pneumoperitoneum, an environment with significant optical features that render the standard ASM model ineffective. Therefore, we cannot simply follow the standard formula $I = J t + A ( 1 - t )$ , but need to build a new model that includes the light source geometry factor and the bipass transmission mechanism.
|
||||
|
||||
To quantify the interaction between light and surgical fumes, the microphysical properties of suspended particles were first analyzed. Surgical fume is a complex multi-dispersion aerosol system, which mainly includes smoke generated by high-frequency electric knife and ultrasound knife and condensate produced by lens condensation on the surface, and its optical scattering behavior is described by Mie Theory.
|
||||
|
||||

|
||||
Fig.1 Schematic diagram of laparoscopic surgery mist scattering model
|
||||
|
||||
For single spherical particles such as electrocutor smoke and ultrasonic knife water mist, their scattering behavior is determined by the scattering cross-section $\sigma _ { s c a }$ and the scattering phase function ?(?) . Electric knife smoke follows the Rayleigh scattering region, i.e., when the radius of the particles is much smaller than the wavelength of light ( ? ≪ ? ), the scattered light intensity $I _ { s c a }$ is inversely proportional to the fourth power of the wavelength:
|
||||
|
||||
$$
|
||||
I _ {s c a} (\theta) \propto \frac {1}{\lambda^ {4}} (1 + \cos^ {2} \theta)
|
||||
$$
|
||||
|
||||
This means that blue light (short wavelengths) is scattered the most strongly, while red light (long wavelengths) is the most penetrating. This explains why the red tissue (blood vessels, muscles) in the abdominal cavity tends to be clearer than the blue object (some instrument markings) in the smoke produced by the electroknife. For the dehaze model, it means that transmittance ?(?) is a function of wavelength ? , $t ( x , \lambda ) = e ^ { - \beta ( \lambda ) d ( x ) }$ .
|
||||
|
||||
In the Mie scattering region formed by ultrasonic knife water mist, when the radius of particles is close to or greater than the wavelength of light, the dependence of the scattering cross-section $\sigma _ { s c a }$ on the wavelength is weakened, which is approximately constant. At this point, all colors of light are scattered in equal amounts, causing the smoke to appear white. Mie scattering has strong forward scattering characteristics, that is, most of the light is scattered forward, but for coaxial
|
||||
|
||||
illumination imaging systems, we pay more attention to backscattering $( \theta \approx 1 8 0 ^ { \circ } )$ , which directly enters the lens to form a light curtain.
|
||||
|
||||
In actual surgery, the medium in the pneumoperitoneum is often a mixture of the above particles. Assuming that the number density of the class ? particles is $N _ { i }$ , the scattering cross-section is $\sigma _ { s c a , i }$ , and the absorption cross-section is $\sigma _ { a b s , i }$ , then the total extinction coefficient $\beta _ { e x t }$ of the medium is:
|
||||
|
||||
$$
|
||||
\beta_ {e x t} (\lambda , x) = \sum_ {i} N _ {i} (x) \cdot (\sigma_ {s c a, i} (\lambda) + \sigma_ {a b s, i} (\lambda))
|
||||
$$
|
||||
|
||||
Since intra-abdominal smoke is mainly scattered, the absorption is usually negligible (unless there is a large amount of carbonized black smoke), so the extinction coefficient is roughly considered to be equal to the scattering coefficient $\beta _ { s c a }$ . It should be pointed out that due to the dynamic nature of the surgical operation, $N _ { i } ( x )$ it is a function of time ? and spatial position ? . This is the physical motivation for the urgent need to introduce a "dynamic expert mechanism" for laparoscopic dehazing algorithms: the network needs to dynamically infer whether the medium is dominant Rayleigh scattering (wavelength compensation) or Mie scattering (contrast enhancement) based on the current image characteristics, so as to call different weight parameters.
|
||||
|
||||
# 2.1.2 Mathematical derivation of laparoscopic enhanced imaging model
|
||||
|
||||
Based on the physical analysis described above, we will derive a complete mathematical model describing the laparoscopic imaging process. The model consists of two parts: the Direct Attenuation Term and the Backscatter/Airlight Term.
|
||||
|
||||
# A. Light source irradiance model
|
||||
|
||||
Suppose the endoscopic light source is a point light source located at the origin $( 0 , 0 , 0 )$ , and its luminous intensity angular distribution is $I _ { s r c } ( \theta )$ (usually approximate to the Lambertian source or Gaussian distribution). Light travels through a space filled with scattering media. For any point ? in space, the distance from the light source is ? , and the angle between the light direction and the optical axis is $\phi$ . The irradiance ?(?) of the arrival point ? is affected by two factors: Geometric Spreading: the energy decays with the square of the distance, $\propto 1 / r ^ { 2 }$ .
|
||||
|
||||
Medium Extinction: Energy decays with the path exponential,according to the Beer-Lambert Law. Therefore, the incident irradiance at the point ? is:
|
||||
|
||||
$$
|
||||
E _ {i n} (P) = \frac {I _ {s r c} (\phi)}{r ^ {2}} e ^ {- \int_ {0} ^ {r} \beta_ {e x t} (s) d s}
|
||||
$$
|
||||
|
||||
To simplify the model for easy calculation, assuming that the medium is locally uniform in the optical path (with a coefficient of ? ), then:
|
||||
|
||||
$$
|
||||
E _ {i n} (P) = \frac {I _ {s r c} (\phi)}{r ^ {2}} e ^ {- \beta r}
|
||||
$$
|
||||
|
||||
# B. Direct signal attenuation term ? ?
|
||||
|
||||
This is the signal light that we want to recover to carry tissue information. When light hits the surface of the tissue (at a position $\mathrm { P _ { o b j } }$ , at a distance ?(?) from the lens), the tissue is reflected. Let the surface reflectance of the tissue be ${ \bf \Xi } ( { \bf \Lambda } \rho ( x )$ , the core component of the potentially clear image ?(?) ). The reflected light returns to the camera from the surface of the tissue, again passing through the distance $d ( x )$ of the medium attenuation. Therefore, the intensity of direct reflected light ?(?) received by the camera sensor at the pixel ? is:
|
||||
|
||||
$$
|
||||
D (x) = \left(\frac {I _ {0}}{d (x) ^ {2}} e ^ {- \beta d (x)}\right) \cdot \rho (x) \cdot e ^ {- \beta d (x)}
|
||||
$$
|
||||
|
||||
where $\left( \frac { I _ { 0 } } { d ( x ) ^ { 2 } } e ^ { - \beta d ( x ) } \right)$ is the incident illuminance, $\rho ( x )$ surface reflectance, and $e ^ { - \beta d ( x ) }$ return path attenuation. After merging the same terms, we obtain a two-way attenuation model unique to laparoscopy:
|
||||
|
||||
$$
|
||||
D (x) = \frac {I _ {0} \rho (x)}{d (x) ^ {2}} e ^ {- 2 \beta d (x)}
|
||||
$$
|
||||
|
||||
The signal term in the standard atmospheric scattering model is $J ( x ) e ^ { - \beta d ( x ) }$ . In contrast, the laparoscopic model has one e more factor (two-way attenuation) and a geometric factor $1 / d ( x ) ^ { 2 }$ . This shows that with the increase of depth $d ( x )$ , the signal intensity of laparoscopic images decays much faster than that of outdoor haze images. The deep tissue is not only obscured by smoke, but also extremely dark due to insufficient light.
|
||||
|
||||
This explains the current common phenomenon in surgery: under heavy smoke, doctors often do not see deep structures (such as the gallbladder triangle) at all, which
|
||||
|
||||
is not only a problem of reduced contrast, but also a sharp deterioration of the signal-to-noise ratio (SNR).
|
||||
|
||||
# C. Integral derivation of the backscattered light curtain term ?(?)
|
||||
|
||||
This is the main cause of the image "whitening" and "fogging", corresponding to the atmospheric light term ?(1 − ?) in the Standard Model. In laparoscopy, the light volume highly coincides with the observation cone due to the coaxial light source with the camera, which results in extremely severe backscattering.
|
||||
|
||||
Consider the line of sight that emanates from the camera center and passes through the pixels ?. In this line of sight, smoke particles within every microparticle volume ?? from distance ? = 0 to $z = d ( x )$ are receiving light and scattering part of the light back to the camera.
|
||||
|
||||
At depth ?, the light intensity received by the thin layer of smoke ?? is $E ( z ) =$ ?02 ?−?? . The scattering intensity per unit volume is determined by the ? scattering $\frac { I _ { 0 } } { z ^ { 2 } } e ^ { - \beta z }$ $\beta$ coefficient and the backscatter probability (phase function $P ( \pi ) ~ )$ . This part of the scattered light is transmitted back to the camera and needs to pass through the attenuation e of the distance ? again. Therefore, the total backscattered light intensity $B ( x )$ is the integral of the scattering contribution of all microelements on the line of sight:
|
||||
|
||||
$$
|
||||
B (x) = \int_ {z _ {m i n}} ^ {d (x)} \left(\frac {I _ {0}}{z ^ {2}} e ^ {- \beta z}\right) \cdot \beta P (\pi) \cdot e ^ {- \beta z} d z
|
||||
$$
|
||||
|
||||
Assuming that the scattering medium is uniform and the phase function is constant (let $k = I _ { 0 } \beta P ( \pi ) \rangle$ ), the integration is simplified to:
|
||||
|
||||
$$
|
||||
B (x) = k \int_ {z _ {m i n}} ^ {d (x)} \frac {e ^ {- 2 \beta z}}{z ^ {2}} d z
|
||||
$$
|
||||
|
||||
This integral term reveals a key characteristic of laparoscopic fog images: due to the presence of a denominator $z ^ { 2 }$ , the main contribution of scattered light comes from the area close to the lens. When ? very small (nearby smoke), $1 / z ^ { 2 }$ extremely large, ?−2?? close to 1, produces an extremely strong light curtain.
|
||||
|
||||
This explains why once there is smoke or water mist in front of the camera, the
|
||||
|
||||
whole picture will instantly "wash out" , completely obscuring the organization behind it. This light curtain not only reduces contrast but also introduces high-brightness signals independent of tissue structure, compressing the camera's dynamic range.
|
||||
|
||||
# D. PSF convolutional model of lens surface condensation
|
||||
|
||||
In addition to spatial scattering, the effect of water mist forming condensation on the lens surface is also crucial. This is surface degradation, not volumetric degradation. Tiny water droplets form an array of lenses on the lens surface, causing misrefraction of light and blurring images. This effect is mathematically modeled as the convolution of a clear image with the Point Spread Function (PSF).
|
||||
|
||||
$$
|
||||
I _ {b l u r} (x) = I _ {c l e a r} (x) \otimes h (x)
|
||||
$$
|
||||
|
||||
ℎ(?) where is a fuzzy nucleus determined by the size distribution of water droplets. Usually for water mist, it can be approximated as a Gaussian core or an aberration disk.
|
||||
|
||||
# E. A uniform laparoscopic enhanced imaging model
|
||||
|
||||
Considering the spatial bipath attenuation, volumetric backscatter, and surface blur, we construct a complete physical imaging model:
|
||||
|
||||
$$
|
||||
I (x) = \left(\frac {I _ {0} \rho (x)}{d (x) ^ {2}} e ^ {- 2 \beta d (x)} + k \int z _ {m i n} ^ {d (x)} \frac {e ^ {- 2 \beta z}}{z ^ {2}} d z\right) \otimes h _ {f o g} (x) + n (x)
|
||||
$$
|
||||
|
||||
Among them, $\frac { I _ { 0 } \rho ( x ) } { d ( x ) ^ { 2 } } e ^ { - 2 \beta d ( x ) }$ is the direct attenuation signal, ? | ||||