Package: vision
Trace object boundary
The boundary tracer object traces object boundaries in binary images.
Use the step syntax below with input image BW
,
starting point STARTPT
, boundary tracer object, H
,
and any optional properties.
PTS = step(H,BW,STARTPT)
traces
the boundary of an object in a binary image, BW
.
The input matrix, STARTPT
, specifies the starting
point for tracing the boundary. STARTPT
is
a twoelement vector of [x y] coordinates of the initial point on
the object boundary. The step
method outputs PTS
,
an Mby2 matrix of [x y] coordinates of the boundary
points. In this matrix, M is the number of traced
boundary pixels. M is less than or equal to the
value specified by the MaximumPixelCount
property.
H = vision.BoundaryTracer
returns
a System object, H
, that traces the boundaries of
objects in a binary image. In this image nonzero pixels belong to
an object and zerovalued pixels constitute the background.
H = vision.BoundaryTracer(
returns
an object, Name
,Value
)H
, with each specified property set to
the specified value. You can specify additional namevalue pair arguments
in any order as (Name1
, Value1
,...,NameN
,ValueN
).
Code Generation Support 

Supports MATLAB^{®} Function block: Yes 
Code Generation Support, Usage Notes, and Limitations 

How to connect pixels to each other Specify which pixels are connected to each other as one of 

First search direction to find next boundary pixel Specify the first direction in which to look to find the next boundary pixel that is connected to the starting pixel. When you set the When you set the 

Direction in which to trace the boundary Specify the direction in which to trace the boundary as one
of 

Maximum number of boundary pixels Specify the maximum number of boundary pixels as a scalar integer
greater than The default is 

How to fill empty spaces in output matrix Specify how to fill the empty spaces in the output matrix, 

Value to fill in remaining empty elements in output matrix Set this property to a scalar value or twoelement vector to
fill in the remaining empty elements in the output matrix The default is 
clone  Create boundary tracer object with same property values 
getNumInputs  Number of expected inputs to step method 
getNumOutputs  Number of outputs from step method 
isLocked  Locked status for input attributes and nontunable properties 
release  Allow property value and input characteristics changes 
step  Trace object boundary in binary image 
Trace the boundary around an image of a coin:
I = imread('coins.png'); % read the image hautoth = vision.Autothresholder; BW = step(hautoth, I); % threshold the image [y, x]= find(BW,1); % select a starting point for the trace % Determine the boundaries hboundtrace = vision.BoundaryTracer; PTS = step(hboundtrace, BW, [x y]); % Display the results figure, imshow(BW); hold on; plot(PTS(:,1), PTS(:,2), 'r', 'Linewidth',2); hold on; plot(x,y,'gx','Linewidth',2); % show the starting point
This object implements the algorithm, inputs, and outputs described on the Trace Boundary block reference page. The object properties correspond to the block parameters.