www.gusucode.com > IPCV_Eval_Kit_R2019a_0ce6858工具箱matlab程序源码 > IPCV_Eval_Kit_R2019a_0ce6858/code/demo_files/I2_09_3_boundary.m

    clear;clc;close all;imtool close all

%% 2抣夋憸撪偺慡椞堟偺嫬奅傪僩儗乕僗
G = imread('coins.png');
figure;imshow(G);
BW = G > 100;
figure;imshow(BW);

%% boundarymask娭悢偺椺:
b = boundarymask(BW);         % 嫬奅傪儅僗僋偲偟偰惗惉
Ib = imoverlay(G, b, 'g');    % 儅僗僋傪夋憸偵忋彂偒
figure; imshow(Ib);           % 昞帵

%% bwboundary娭悢偺椺
b = bwboundaries(BW, 'noholes') % 寠偼僩儗乕僗偣偢丅b偼XY嵗昗偺儕僗僩
figure;imshow(G);
hold on;
visboundaries(b, 'Color','g');  % Figure忋偱尨夋憸忋偵忋彂偒
hold off


%% bwtraceboundary : 2抣夋憸撪偺堦偮偺嫬奅傪僩儗乕僗
G = imread('coins.png');
figure;imshow(G);
BW = im2bw(G);
imtool(BW);

dim = size(BW)
col = round(dim(2)/2)-90      % 僩儗乕僗奐巒揰嵗昗
row = min(find(BW(:,col)))    % 僩儗乕僗奐巒揰嵗昗
b = bwtraceboundary(BW,[row, col],'N');  % 嫬奅忋偺揰(60,26)偐傜嫬奅偵増偭偰僩儗乕僗
hold on;
plot(b(:,2),b(:,1),'g','LineWidth',3);    % visboundaries 偺巊梡傕壜擻
plot(col, row,'ro','LineWidth', 6);
hold off;
%% 尨夋憸偵忋彂偒
figure;imshow(G);shg;
hold on;
plot(b(:,2),b(:,1),'g','LineWidth',3);
plot(col, row,'ro','LineWidth', 6);
hold off;


%% bwperim : 椫妔偩偗偺2抣夋憸傪惗惉
G = imread('coins.png');
figure;imshow(G);
BW = G > 100;
figure;imshow(BW);

BWb = bwperim(BW);
imshow(BWb);
%% 尨夋憸忋偵忋彂偒
G(BWb) = 0;
I = cat(3, G+ uint8(BWb*255), G, G);
figure;imshow(I);

%% 廔椆



%% insertShape傪巊偭偨応崌
G = imread('coins.png');
figure;imshow(G);
BW = G > 100;
figure;imshow(BW);
b = bwboundaries(BW, 'noholes'); % 寠偼僩儗乕僗偣偢
I1 = insertShape(G, 'Line', reshape([b{1}(:,2),b{1}(:,1)]',1,[]), 'LineWidth',1, 'SmoothEdges',false);
imtool(I1)



% Copyright 2014 The MathWorks, Inc.