本文主要是介绍python识别增强静脉清晰度 opencv-python图像处理案例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一.任务说明
用python实现静脉清晰度提升。
二.代码实现
import cv2
import numpy as npdef 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_imagedef extract_blood_vessels(image):# 阈值分割提取静脉血管ret, thresholded_image = cv2.threshold(image, 100, 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), dtype=np.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()
三.识别效果
这篇关于python识别增强静脉清晰度 opencv-python图像处理案例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!