MATLAB图像处理:条纹骨架化及长度统计
% 读取原始图像 img = imread('7-1.tif');
% 将图像二值化 bw_img = imbinarize(img);
% 进行骨架化操作 skel_img = bwmorph(bw_img, 'skel', Inf);
% 消除分支条纹 branchpoints = bwmorph(skel_img, 'branchpoints'); endpoints = bwmorph(skel_img, 'endpoints'); skel_img = skel_img & ~(branchpoints | endpoints); skel_img = bwareaopen(skel_img, 3);
% 计算条纹长度 pixel_size = 0.0595; % 纳米/像素 skel_props = regionprops(skel_img, 'PixelList'); stripe_lengths = []; for i = 1:length(skel_props) stripe_pixels = skel_props(i).PixelList; if size(stripe_pixels, 1) >= 3 stripe_length = 0; for j = 1:size(stripe_pixels, 1) if j < size(stripe_pixels, 1) && abs(stripe_pixels(j, 1) - stripe_pixels(j+1, 1)) == 1 && abs(stripe_pixels(j, 2) - stripe_pixels(j+1, 2)) == 1 % 对角线像素长度为2倍像素大小 stripe_length = stripe_length + 2 * pixel_size; else stripe_length = stripe_length + pixel_size; end end if stripe_length >= 0.483 % 剔除长度小于0.483 nm的条纹 stripe_lengths(end+1) = stripe_length; end end end
% 统计数据和图像展示 mean_length = mean(stripe_lengths); max_length = max(stripe_lengths); min_length = min(stripe_lengths); num_stripes = length(stripe_lengths);
figure; subplot(1, 2, 1); imshow(img); title('Original Image'); subplot(1, 2, 2); imshow(skel_img); title(sprintf('Skeletonized Image %d stripes found', num_stripes));
fprintf('Mean length: %.3f nm ', mean_length); fprintf('Maximum length: %.3f nm ', max_length); fprintf('Minimum length: %.3f nm ', min_length);
原文地址: http://www.cveoy.top/t/topic/m5in 著作权归作者所有。请勿转载和采集!