基于MATLAB的多尺度血管检测与线追踪实现

基于MATLAB的多尺度血管检测与线追踪实现,整合了高斯滤波、Hessian分析和形态学处理技术:


一、算法框架设计

% 主程序流程
clear; clc;
img = imread('vascular_image.png'); % 读取血管图像
img_gray = rgb2gray(img); % 转换为灰度图像

% 多尺度预处理
[smoothed_imgs, scales] = multiScaleSmoothing(img_gray, [1,2,4]);

% 多尺度特征提取
vesselness = zeros(size(img_gray));
for i = 1:numel(scales)
    vesselness(:,:,i) = computeVesselness(smoothed_imgs(:,:,i), scales(i));
end

% 中心线追踪
skeleton = multiScaleSkeleton(img_gray, scales);

% 后处理优化
final_centerline = postProcess(skeleton, vesselness);

二、核心模块实现

1. 多尺度高斯滤波

function [smoothed, scales] = multiScaleSmoothing(img, sigmas)
    smoothed = cell(1,numel(sigmas));
    scales = sigmas;
    for i = 1:numel(sigmas)
        smoothed{i} = imgaussfilt(img, sigmas(i));
    end
end

2. Hessian血管增强

function vesselness = computeVesselness(img, sigma)
    % 计算Hessian矩阵
    [Hxx, Hxy, Hyy] = hessianDouble(img, sigma);
    
    % 特征值分析
    [Dxx, Dxy, Dyy] = eig2(Hxx, Hxy, Hyy);
    Rb = (Dxx.*Dyy - Dxy.^2) ./ (Dxx + Dyy + eps).^2;
    S = sqrt(Dxx.^2 + Dyy.^2 + 2*Dxy.^2);
    
    % 血管响应函数
    beta = 0.5; gamma = 15;
    vesselness = exp(-Rb/(2*beta^2)).*(1 - exp(-S/(2*gamma^2)));
end

function [Hxx, Hxy, Hyy] = hessianDouble(img, sigma)
    % 双边高斯滤波
    h = fspecial('gaussian', [5 5], sigma);
    I = imfilter(img, h, 'replicate');
    
    % 中心差分计算二阶导数
    Hxx = (imfilter(I, fspecial('sobel')/8, 'replicate')...
        - imfilter(I, fspecial('sobel')/8', 'replicate'))/2;
    Hxy = (imfilter(I, fspecial('prewitt')/8, 'replicate')...
        - imfilter(I, fspecial('prewitt')/8', 'replicate'))/2;
    Hyy = (imfilter(I, fspecial('sobel')/8', 'replicate')...
        - imfilter(I, fspecial('sobel')/8, 'replicate'))/2;
end

3. 多尺度骨架提取

function skeleton = multiScaleSkeleton(img, scales)
    skeleton = false(size(img));
    for i = 1:numel(scales)
        % 形态学细化
        thinned = bwmorph(img, 'thin', Inf);
        % 尺度空间融合
        skeleton = skeleton | imresize(thinned, 1/scales(i));
    end
end

三、完整处理流程

  1. 图像预处理

    % 直方图均衡化增强对比度
    img_enhanced = adapthisteq(img_gray);
    
    % 自适应中值滤波去噪
    denoised = medfilt2(img_enhanced, [3 3]);
    
  2. 多尺度血管增强

    % 构建尺度空间金字塔
    pyramid = imagePyramid(denoised, 3);
    
    % 多尺度血管响应计算
    vesselness_map = zeros(size(denoised));
    for i = 1:numel(pyramid)
        vesselness_map(:,:,i) = computeVesselness(pyramid{i}, 2^i);
    end
    
  3. 中心线追踪算法

    % 基于梯度方向追踪
    [dx, dy] = gradient(double(img_enhanced));
    angles = atan2(dy, dx);
    
    % 轨迹追踪
    centerline = zeros(size(img_enhanced));
    for y = 2:size(img_enhanced,1)-1
        for x = 2:size(img_enhanced,2)-1
            if vesselness_map(y,x) > 0.2
                % 方向追踪算法
                centerline = tracePath(centerline, x, y, angles);
            end
        end
    end
    

四、后处理优化

% 形态学后处理
clean_centerline = bwareaopen(centerline, 50);

% 断点连接算法
clean_centerline = morphological_repair(clean_centerline);

% 三维可视化(扩展)
figure;
vol3d('CData', cat(3, clean_centerline, clean_centerline*0.5, clean_centerline*0.3));
axis equal;

参考代码 利用MATLAB编程完成血管检测 多尺度线追踪 www.youwenfan.com/contentcnj/63151.html

五、性能评估指标

% 真值对比分析
ground_truth = imread('vessel_ground_truth.png');
accuracy = sum(clean_centerline(:) & ground_truth(:)) / sum(ground_truth(:));
precision = sum(clean_centerline(:) & ground_truth(:)) / sum(clean_centerline(:));
recall = sum(clean_centerline(:) & ground_truth(:)) / sum(ground_truth(:));

% 可视化对比
figure;
subplot(1,3,1); imshow(clean_centerline); title('提取结果');
subplot(1,3,2); imshow(ground_truth); title('真实血管');
subplot(1,3,3); imshow(clean_centerline & ground_truth); title('重叠区域');

六、扩展应用场景

  1. 动态血管追踪

    % 4D时序血管追踪
    for t = 1:num_frames
        [smoothed(:,:,t), scales] = multiScaleSmoothing(frames(:,:,t));
        vesselness(:,:,t) = computeVesselness(smoothed(:,:,t), scales);
    end
    
  2. 三维血管重建

    % 堆叠多帧中心线
    3d_centerline = cat(3, centerline(:,:,1), centerline(:,:,2));
    
    % 体绘制可视化
    isovalue = 0.5;
    p = patch(isosurface(3d_centerline, isovalue));
    isonormals(3d_centerline, p);
    shading interp;
    camlight; lighting gouraud;
    

七、优化建议

  1. 并行计算加速

    % 使用parfor进行多尺度并行处理
    parfor i = 1:numel(scales)
        vesselness(:,:,i) = computeVesselness(smoothed(:,:,i), scales(i));
    end
    
  2. GPU加速方案

    % 将图像数据转移至GPU
    gpu_img = gpuArray(img_gray);
    
    % 在GPU上执行滤波操作
    gpu_smoothed = imgaussfilt(gpu_img, sigma);
    
posted @ 2025-10-15 16:35  风一直那个吹  阅读(7)  评论(0)    收藏  举报