读取二进制图像 binary_image = imread7bmp; 骨架化 skeleton_image = bwmorphbinary_image skel Inf; 消除分支条纹 branchless_image = bwmorphskeleton_image branchpoints; 获取像素长度 pixel_size = 01; 假设分辨率为10 nmpixel diag
% 读取二进制图像 binary_image = imread('7.bmp');
% 转化为二维逻辑矩阵 binary_image = logical(binary_image);
% 骨架化 skeleton_image = bwmorph(binary_image, 'skel', Inf);
% 消除分支条纹 branchless_image = bwmorph(skeleton_image, 'branchpoints');
% 获取像素长度 pixel_size = 0.1; % 假设分辨率为10 nm/pixel diagonal_factor = sqrt(2); % 对角线像素长度因子为sqrt(2)
% 初始化条纹长度变量 stripe_lengths = [];
% 遍历每个像素 for i = 1:size(branchless_image, 1) for j = 1:size(branchless_image, 2) % 如果像素是连通的 if branchless_image(i, j) % 获取连通区域 connected_region = bwselect(branchless_image, j, i, 8); % 计算像素数和长度 pixel_count = sum(connected_region(:)); if ismember(i+j, [3, 4, 5]) pixel_length = 2 * pixel_size; else pixel_length = pixel_size; end stripe_length = pixel_count * pixel_length; % 如果条纹长度大于0.483 nm,则保存 if stripe_length > 0.483 stripe_lengths(end+1) = stripe_length; end % 标记已经计算过的像素 branchless_image(connected_region) = 0; end end end
% 显示最终处理后的图像和条纹数量 figure(); imshow(binary_image); title('Original Binary Image'); figure(); imshow(skeleton_image); title('Skeletonized Image'); figure(); imshow(branchless_image); title('Branchless Image'); fprintf('Number of Stripes: %d\n', length(stripe_lengths));
原文地址: https://www.cveoy.top/t/topic/bstW 著作权归作者所有。请勿转载和采集!