大型网站域名,徐州网站制作需要多少钱,网站开发有什么软件,深圳推广网站一.任务说明 用python实现静脉清晰度提升。
二.代码实现
import cv2
import numpy as npdef enhance_blood_vessels(image):# 调整图像对比度和亮度enhanced_image cv2.convertScaleAbs(image, alpha0.5, beta40)# 应用CLAHE#xff08;对比度受限的自适应直方图均衡化 cv2.convertScaleAbs(image, alpha0.5, beta40)# 应用CLAHE对比度受限的自适应直方图均衡化clahe cv2.createCLAHE(clipLimit10.0, tileGridSize(8, 8))enhanced_image clahe.apply(enhanced_image)# 应用中值滤波平滑图像enhanced_image cv2.medianBlur(enhanced_image, 9)return enhanced_imagedef extract_blood_vessels(image):# 阈值分割提取静脉血管ret, thresholded_image cv2.threshold(image, 127, 255, cv2.THRESH_BINARY)# 使用形态学操作膨胀和腐蚀进一步清理和连接血管kernel np.ones((3, 3), np.uint8)thresholded_image cv2.morphologyEx(thresholded_image, cv2.MORPH_OPEN, kernel)return thresholded_image# 读取图像
image cv2.imread(input_pic.png, cv2.IMREAD_GRAYSCALE)# 图像增强
enhanced_image enhance_blood_vessels(image)# 提取静脉血管
vessels_image extract_blood_vessels(enhanced_image)
# 将灰度图转换为彩色图
color_image np.zeros((enhanced_image.shape[0], enhanced_image.shape[1], 3), dtypenp.uint8)
for i in range(enhanced_image.shape[0]):for j in range(enhanced_image.shape[1]):color_image[i][j] (enhanced_image[i][j], enhanced_image[i][j], 100) # 使用灰度值作为RGB通道的值# 显示彩色图
cv2.imshow(Color Image, color_image)
# 显示图像
cv2.imshow(Original Image, image)
cv2.imshow(Enhanced Image, enhanced_image)
cv2.imshow(Blood Vessels, vessels_image)
cv2.waitKey(0)
cv2.destroyAllWindows()三.识别效果