| Video and Image Processing Blockset™ | ![]() |
Analysis & Enhancement

The Trace Boundaries block traces object boundaries in binary images, where nonzero pixels represent objects and 0 pixels represent the background.
| Port | Input/Output | Supported Data Types | Complex Values Supported |
|---|---|---|---|
BW | Vector or matrix that represents a binary image | Boolean | No |
Start Pts | 2-by-N matrix where each column represents the zero-based row and column coordinates of the boundary starting point, and N is the total number of starting points:
|
| No |
Pts | 2M-by-N matrix where each column contains the zero-based row and column coordinates of the boundary pixels, M is the maximum number of boundary pixels, and N is the total number of starting points:
| Same as Start Pts port | No |
Count | 1-by-N vector where each element represents the actual number of boundary pixels found for the corresponding starting point, where N is the number of starting points. | 32-bit unsigned integer | No |
Use the Connectivity parameter to define which pixels are connected to each other. If you want a pixel to be connected to the other pixels located on the top, bottom, left, and right, select 4. If you want a pixel to be connected to the other pixels on the top, bottom, left, right, and diagonally, select 8. For more information about this parameter, see the Label block reference page.
Use the Initial search direction parameter to specify the first direction in which to look to find the next boundary pixel that is connected to the starting pixel. If, for the Connectivity parameter, you select 4, the following figure illustrates the four possible initial search directions:

If, for the Connectivity parameter, you select 8, the following figure illustrates the eight possible initial search directions:

Use the Trace direction parameter to specify the direction in which to trace the boundary. Your choices are Clockwise or Counterclockwise.
Use the Maximum number of boundary pixels parameter to specify the maximum number of boundary pixels for each starting point. The block uses this value to preallocate the number of rows of the Pts port output matrix so that it can hold all the boundary pixel location values.
To output the actual number of boundary pixels for each starting point, select the Output number of boundary pixels found check box. The Count port appears on the block. The block outputs a 1-by-N vector at this port where each element represents the actual number of boundary pixels found for each starting point. Here, N is the number of starting points.
Because you specify the number of rows of the Pts port output matrix using the Maximum number of boundary pixels parameter, use the Action to take for empty output points parameter to specify what happens to the empty elements in this vector when the number of boundary pixels is less than the maximum.
If you select None, the block takes no action. So, any element that does not contain a boundary pixel location will not have a meaningful value.
If you select Fill with last point found, the block fills the remaining elements with the position of the last boundary pixel.
If you select Fill with user-defined values, the Fill values parameter appears on the block.
For the Fill values parameter, enter a scalar value or two-element vector that you want the block to use to fill in the empty elements.
The Trace Boundaries dialog box appears as shown in the following figure.

Specify which pixels are connected to each other. If you want a pixel to be connected to the pixels on the top, bottom, left, and right, select 4. If you want a pixel to be connected to the pixels on the top, bottom, left, right, and diagonally, select 8.
Specify the first direction in which to look to find the next boundary pixel that is connected to the starting pixel.
Specify the direction in which to trace the boundary. Your choices are Clockwise or Counterclockwise.
Specify the maximum number of boundary pixels. The block uses this value to preallocate the number of rows of the Pts port output matrix so that it can hold all the boundary pixel location values.
If you select this check box, the block outputs a vector at the Count port where each element represents the actual number of boundary pixels found for each starting point.
Specify how to fill the empty spaces in the Pts port output matrix. If you select None, the block takes no action. So, any element that does not contain a boundary pixel location will not have a meaningful value. If you select Fill with last point found, the block fills the remaining elements with the position of the last boundary pixel. If you select Fill with user-defined values, the Fill values parameter appears on the block.
Enter a scalar value or two-element vector that you want the block to use to fill in the remaining empty elements. This parameter is visible if, for the Action to take for empty output points parameter, you select Fill with user-defined values.
Video and Image Processing Blockset | |
Video and Image Processing Blockset | |
Image Processing Toolbox | |
Image Processing Toolbox |
![]() | Top-hat | Translate | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |