Documentation

vision.BoundaryTracer System object

Package: vision

Trace object boundary

Description

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 two-element vector of [x y] coordinates of the initial point on the object boundary. The step method outputs PTS, an M-by-2 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.

Construction

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 zero-valued pixels constitute the background.

H = vision.BoundaryTracer(Name,Value) returns an object, H, with each specified property set to the specified value. You can specify additional name-value 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

Properties

Connectivity

How to connect pixels to each other

Specify which pixels are connected to each other as one of 4 | 8. The default is 8. Set this property to 4 to connect a pixel to the pixels on the top, bottom, left, and right. Set this property to 8 to connect a pixel to the pixels on the top, bottom, left, right, and diagonally.

InitialSearchDirection

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 Connectivity property to 8, this property accepts a value of North, Northeast, East, Southeast, South, Southwest, West, or Northwest.

When you set the Connectivity property to 4, this property accepts a value of North, East, South, or West

TraceDirection

Direction in which to trace the boundary

Specify the direction in which to trace the boundary as one of Clockwise | Counterclockwise. The default is Clockwise.

MaximumPixelCount

Maximum number of boundary pixels

Specify the maximum number of boundary pixels as a scalar integer greater than 1. The object uses this value to preallocate the number of rows of the output matrix, Y. This preallocation enables the matrix to hold all the boundary pixel location values.

The default is 500.

NoBoundaryAction

How to fill empty spaces in output matrix

Specify how to fill the empty spaces in the output matrix, Y as one of None | Fill with last point found | Fill with user-defined values. The default is None. If you set this property to None, the object takes no action. Thus, any element that does not contain a boundary pixel location has no meaningful value. If you set this property to Fill with last point found, the object fills the remaining elements with the position of the last boundary pixel. If you set this property to Fill with user-defined values, you must specify the values in the FillValues property.

FillValues

Value to fill in remaining empty elements in output matrix

Set this property to a scalar value or two-element vector to fill in the remaining empty elements in the output matrix Y. This property applies when you set the NoBoundaryAction property to Fill with user-defined values.

The default is [0 0].

Methods

cloneCreate boundary tracer object with same property values
getNumInputsNumber of expected inputs to step method
getNumOutputsNumber of outputs from step method
isLockedLocked status for input attributes and nontunable properties
release Allow property value and input characteristics changes
stepTrace object boundary in binary image

Examples

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

Algorithms

This object implements the algorithm, inputs, and outputs described on the Trace Boundary block reference page. The object properties correspond to the block parameters.

Was this topic helpful?