www.gusucode.com > images 案例代码 matlab源码程序 > images/TraceBoundaryAndVisualizeContoursExample.m
%% Trace Boundary and Visualize Contours % %% % Read image and display it. % Copyright 2015 The MathWorks, Inc. BW = imread('blobs.png'); imshow(BW,[]); %% % Pick an object in the image and trace the boundary. To select an object, % specify a pixel on its boundary. This example uses the coordinates of a % pixel on the boundary of the thick white circle, obtained through visual % inspection using |impixelinfo|. The example specifies the initial search % direction, the connectivity, how many boundary pixels should be % returned, and the direction in which to perform the search. r = 163; c = 37; contour = bwtraceboundary(BW,[r c],'W',8,Inf,'counterclockwise'); %% % Plot the contour on the image. hold on; plot(contour(:,2),contour(:,1),'g','LineWidth',2);