例8.1使用函数bwboundaries和bound2im.
clc,clear,close all;
f = [
0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 1 1 1 1 1 1 1 1 1 1 1 1 0;
0 1 1 1 1 1 1 1 1 1 1 1 1 0;
0 1 1 0 0 0 0 0 0 0 0 1 1 0;
0 1 1 0 1 1 1 1 1 1 0 1 1 0;
0 1 1 0 1 1 1 1 1 1 0 1 1 0;
0 1 1 0 1 1 0 0 1 1 0 1 1 0;
0 1 1 0 1 1 0 0 1 1 0 1 1 0;
0 1 1 0 1 1 1 1 1 1 0 1 1 0;
0 1 1 0 1 1 1 1 1 1 0 1 1 0;
0 1 1 0 0 0 0 0 0 0 0 1 1 0;
0 1 1 1 1 1 1 1 1 1 1 1 1 0;
0 1 1 1 1 1 1 1 1 1 1 1 1 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0
];
B = bwboundaries(f, 'noholes');
numel(B)
b = cat(1, B{:});
[M, N] = size(f);
imgae = bound2im(b, M, N)
[B, L, NR, A] = bwboundaries(f);
numel(B)
numel(B) - NR
bR = cat(1, B{1:2}, B{4});
imageBoundaries = bound2im(bR, M, N);
imageNumveredBoundaries = imageBoundaries.*L
bR = cat(1, B{:});
imageBoundaries = bound2im(bR, M, N);
imageNumberedBoundaries = imageBoundaries.*L
find(A(:,1))
find(A(1,:))
A
full(A)
例8.2弗雷曼链码及其某些变化
clc,clear,close all;
f = imread('F:\qq\Digital-Image-Processing-main\Digital-Image-Processing-main\matlab教材示例图片\dipum_images_ch11\Fig1102(a)(noisy_circular_stroke).tif');
figure
subplot(231),imshow(f)
h = fspecial('average', 9);
g = imfilter(f, h, 'replicate');
subplot(232),imshow(g)
gB = im2bw(g, 0.5);
subplot(233),imshow(gB)
B = bwboundaries(gB, 'noholes');
d = cellfun('length', B);
[maxd, k] = max(d);
b = B{k};
[M N] = size(g);
g = bound2im(b, M, N);
subplot(234),imshow(g)
[s, su] = bsubsamp(b, 50);
g2 = bound2im(s, M, N);
subplot(235),imshow(g2)
cn = connectpoly(s(:, 1), s(:, 2));
g3 = bound2im(cn, M, N);
subplot(236),imshow(g3)
c = fchcode(su);
c.x0y0
c.fcc
c.mm
c.diff
c.diffmm
例8.3得到包围一个区域的边界的细胞组合体
clc,clear,close all;
f = imread('F:\qq\Digital-Image-Processing-main\Digital-Image-Processing-main\数字图像处理第三版 教材图片\DIP3E_CH12_Original_Images\DIP3E_Original_Images_CH12\Fig1209(b)(eye template).tif');
g = bwperim(f, 8);
Q = qtdecomp(g, 0, 2);
R = imfill(gF, 'holes') & g;
B = bwboundaries(f, 4, 'noholes');
b = B{1};
例8.4使用函数 im2minperpoly
clc,clear,close all;
f = imread('F:\qq\Digital-Image-Processing-main\Digital-Image-Processing-main\matlab教材示例图片\dipum_images_ch11\Fig1107(a)(mapleleaf).tif');
figure
subplot(321),imshow(f)
B = bwboundaries(f, 4, 'noholes');
b = B{1};
[M, N] = size(f);
bOriginal = bound2im(b, M, N);
subplot(322),imshow(bOriginal)
[X, Y] = im2minperpoly(f, 2);
b2 = connectpoly(X, Y);
bCellsize2 = bound2im(b2, M, N);
subplot(323),imshow(bCellsize2)
[X, Y] = im2minperpoly(f, 3);
b2 = connectpoly(X, Y);
bCellsize2 = bound2im(b2, M, N);
subplot(324),imshow(bCellsize2)
[X, Y] = im2minperpoly(f, 4);
b2 = connectpoly(X, Y);
bCellsize2 = bound2im(b2, M, N);
subplot(325),imshow(bCellsize2)
[X, Y] = im2minperpoly(f, 8);
b2 = connectpoly(X, Y);
bCellsize2 = bound2im(b2, M, N);
subplot(326),imshow(bCellsize2)
figure
[X, Y] = im2minperpoly(f, 10);
b2 = connectpoly(X, Y);
bCellsize2 = bound2im(b2, M, N);
subplot(221),imshow(bCellsize2)
[X, Y] = im2minperpoly(f, 16);
b2 = connectpoly(X, Y);
bCellsize2 = bound2im(b2, M, N);
subplot(222),imshow(bCellsize2)
[X, Y] = im2minperpoly(f, 20);
b2 = co