一.任务说明
用python实现静脉清晰度提升。
二.代码实现
import cv2
import numpy as np
def enhance_blood_vessels(image):
# 调整图像对比度和亮度
enhanced_image = cv2.convertScaleAbs(image, alpha=0.5, beta=100)
# 应用CLAHE(对比度受限的自适应直方图均衡化)
clahe = cv2.createCLAHE(clipLimit=30.0, tileGridSize=(8, 8))
enhanced_image = clahe.apply(enhanced_image)
# 应用中值滤波平滑图像
enhanced_image = cv2.medianBlur(enhanced_image, 1)
return enhanced_image
def extract_blood_vessels(image):
# 阈值分割提取静脉血管
ret, thresholded_image = cv2.threshold(image, 100, 255, cv2.THRESH_BINARY)
# 使用形态学操作(膨胀和腐蚀)进一步清理和连接血管
kernel = np.ones((3, 3), np.uint8)
thre