32边界的链码表示&MPP算法MATLAB实现
原文:http://3y.uu456.com/bp_3psix2u34h9da6a52j1q_1.html
参考代码:
clc
clear
f = imread('Fig1102(a)(noisy_circular_stroke).tif');
subplot(2,2,1);
imshow(f)
title('原始图像')
%%%平滑图像%%%%
h = fspecial('average',9);
g = imfilter(f,h,'replicate');
subplot(2,2,2)
imshow(g)
title('平滑图像')
%%%%%%%%阈值分割
g = im2bw(g,0.5);
subplot(2,2,3)
imshow(g)
title('阈值分割结果')
B = boundaries(g);
d = cellfun('length',B);
[max_d,k] = max(d);
b = B{1};
[M,N] = size(g); % 注意 : 产生了完整的边界, 边界并没有断开, 拖动一下便可以显现
g = bound2im(b,M,N,min(b(:,1)),min(b(:,2)));
subplot(2,2,4)
imshow(g)
title('边界图像')
[s,su] = bsubsamp(b,50); %对边界进行二次取样
g2 = bound2im(s,M,N,min(s(:,1)),min(s(:,2)));
%subplot(2,3,5)
figure;
imshow(g2)
title('取样结果图')
cn = connectpoly(s(:,1),s(:,2));
g2 = bound2im(cn,M,N,min(cn(:,1)),min(cn(:,2)));
%subplot(2,3,6)
figure;
imshow(g2)
title('取样结果连接图')
c = fchcode(su)
2.使用函数 minperpoly 实现 MPP 算法,得到边界的多边形近似。 参考代码:
clc
clear
B = imread('Fig1107(a)(mapleleaf).tif');figure;subplot(121); imshow(B)
title('原始图像')
b = boundaries(B,4,'cw'); %4 连接边界
b = b{1};
[M,N] = size(B);
xmin = min(b(:,1));
ymin = min(b(:,2));
bim = bound2im(b,M,N,xmin,ymin);
subplot(122);
imshow(bim);title('边界图像')
[x,y] = minperpoly(B,2); %使用大小为 2 的方形单元得到的 MPP b2 = connectpoly(x,y);
B2 = bound2im(b2,M,N,xmin,ymin);
figure;subplot(131);
imshow(B2);title('2方形单元')
[x,y] = minperpoly(B,4); %使用大小为 4 的方形单元得到的 MPP b2 = connectpoly(x,y);
B2 = bound2im(b2,M,N,xmin,ymin);
subplot(132);
imshow(B2);title('4方形单元')
[x,y] = minperpoly(B,16); %使用大小为 16 的方形单元得到的 MPP b2 = connectpoly(x,y);
B2 = bound2im(b2,M,N,xmin,ymin);
subplot(133);
imshow(B2);title('16方形单元')
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/77029461
- 点赞
- 收藏
- 关注作者
评论(0)