| Video and Image Processing Blockset™ | ![]() |
Text & Graphics

The Draw Shapes block draws multiple rectangles, lines, polygons, or circles on images by overwriting pixel values. As a result, the shapes are embedded on the output image.
This block uses Bresenham's line drawing algorithm to draw lines, polygons, and rectangles. It uses Bresenham's circle drawing algorithm to draw circles.
| Port | Input/Output | Supported Data Types | Complex Values Supported |
|---|---|---|---|
Image | M-by-N matrix of intensity values or an M-by-N-by-P color video signal where P is the number of color planes |
| No |
R, G, B | Scalar, vector, or matrix that represents one plane of the input RGB video stream. Inputs to the R, G, and B ports must have the same dimensions and data type. | Same as I port | No |
Pts | Use integer values to define zero-based shape coordinates. If you enter noninteger values, the block rounds them to the nearest integer. For more information about how to specify shape coordinates for different shapes, see Defining Shapes to Draw. |
| No |
ROI | Four-element vector of integers that defines a rectangular area in which to draw the shapes. The first two elements represent the zero-based row and column coordinates of the upper-left corner of the area. The second two elements represent the height and width of the area. |
| No |
Output | Scalar, vector, or matrix of pixel values that contain the shape(s) | Same as I port | No |
The output signal is the same size and data type as the inputs to the Image, R, G, and B ports.
Use the Shape parameter to specify the type of shape(s) to draw. Your choices are Rectangles, Lines, Polygons, or Circles.
If you clear the Fill shapes check box, the Border value parameter appears in the dialog box. Use this parameter determine the appearance of the rectangle(s), line(s), polygon(s), or circle(s). If you select Black, the border is black. If you select White, the border is white. If you select User-specified value, the Value(s) parameter appears in the dialog box. The following table describes what to enter for the Value(s) parameter based on the block input and the number of shapes you are drawing.
| Block Input | Drawing One Shape | Drawing Multiple Shapes |
|---|---|---|
| Intensity image | Value(s) = Scalar intensity value | Value(s) = R-element vector where R is the number of shapes |
| Color image | Value(s) = P-element vector where P is the number of color planes | Value(s) = P-by-R matrix where P is the number of color planes and R is the number of shapes |
For each value in the Value(s) parameter, enter a number between the minimum and maximum values that can be represented by the data type of the input image. If you enter a value outside this range, the block produces an error message.
If you select the Fill shapes check box, the Fill value and Opacity factor (between 0 and 1) parameters appear in the dialog box. Use the Fill value parameter to specify the shading inside the shape. If you select Black, the shape is black. If you select White, the shape is white. If you select User-specified value, the Value(s) parameter appears in the dialog box. For a description of this parameter, see the preceding table. Use the Opacity factor (between 0 and 1) parameter to specify the opacity of the shading inside the shape, where 0 is transparent and 1 is opaque.
Note If you are generating code and you select the Fill shapes check box, the word length of the block input(s) cannot exceed 16 bits. |
Use the Draw shapes in parameter to define the area in which to draw the shapes.
If you select Entire image, you can draw shapes in the entire image.
If you select Specify region of interest via port, the ROI port appears on the block. Enter a four-element vector of integer values, [r c height width], where r and c are the row and column coordinates of the upper-left corner of the area, and height and width represent the height (in rows) and width (in columns) of the area.
Use the Image signal parameter to specify how to input and output a color video signal. If you select One multidimensional signal, the block accepts an M-by-N-by-P color video signal, where P is the number of color planes, at one port. If you select Separate color signals, additional ports appear on the block. Each port accepts one M-by-N plane of an RGB video stream.
This section explains how to use the Shape parameter and the Pts port to draw the following shapes:
The Draw Shapes block lets you draw one or more rectangles. Set the Shape parameter to Rectangles, and then follow the instructions in the table to specify the input to the Pts port to obtain the desired number of rectangles.
| Shape | Input to the Pts Port | Drawn Shape |
|---|---|---|
| Single Rectangle | Four-element row or column vector [r c height width] where
|
|
| N Rectangles | 4-by-N matrix
|
|
For an example of how to use the Draw Shapes block to draw a rectangle, see Tracking an Object Using Correlation.
The Draw Shapes block lets you draw either a single line, or one or more polylines, where each polyline is a series of connected line segments. Set the Shape parameter to Lines, and then follow the instructions in the table to specify the input to the Pts port to obtain the desired shape.
| Shape | Input to the Pts Port | Drawn Shape |
|---|---|---|
| Single Line | Four-element row or column vector [r1 c1 r2 c2] where
|
|
| N Lines | 4-by-N matrix
|
|
| Single Polyline with L-1 Segments | Vector of size 2L [r1 c1 r2 c2 ... rL cL] where
The block produces an error message if the number of rows is less than two or is not a multiple of two. |
|
| N Polylines with the largest number of line segments in any line being L-1 | 2L-by-N matrix
where each column of the matrix corresponds to a different polyline and is of the same form as the vector for a single polyline. If some polylines are shorter than others, repeat the ending coordinates to fill the polyline matrix. The block produces an error message if the number of rows is less than two or is not a multiple of two. |
|
If you select the Use antialiasing check box, the block applies an edge smoothing algorithm. See [1].
For examples of how to use the Draw Shapes block to draw a line, see Finding Lines in Images and Measuring an Angle Between Lines.
The Draw Shapes block lets you draw one or more polygons. Set the Shape parameter to Polygons, and then follow the instructions in the table to specify the input to the Pts port to obtain the desired number of polygons.
| Shape | Input to the Pts Port | Drawn Shape |
|---|---|---|
| Single Polygon with L line segments | Row or column vector of size 2L [r1 c1 r2 c2 ... rL
cL] where
The block connects [r1 c1] to [rL cL] to complete the polygon. The block produces an error if the number of rows is negative or not a multiple of two. |
|
| N Polygons with the largest number of line segments in any line being L | 2L-by-N matrix
where each column of the matrix corresponds to a different polygon and is of the same form as the vector for a single polygon. If some polygons are shorter than others, repeat the ending coordinates to fill the polygon matrix. The block produces an error message if the number of rows is less than two or is not a multiple of two. |
|
If you select the Use antialiasing check box, the block applies an edge smoothing algorithm. See [1].
The Draw Shapes block lets you draw one or more circles. Set the Shape parameter to Circles, and then follow the instructions in the table to specify the input to the Pts port to obtain the desired number of circles.
| Shape | Input to the Pts Port | Drawn Shape |
|---|---|---|
| Single Circle | Three-element row or column vector [r c radius] where
|
|
| N Circles | 3-by-N matrix
|
|
If you select the Use antialiasing check box, the block applies an edge smoothing algorithm that is described next. First, the block calculates the distance from a point on the circle to the nearest pixel.

Then, it uses the following equations to calculate the intensity at pixels i and j:
![]()
In the previous equations, factor is the value you entered for the Opacity factor parameter. If you did not enter an opacity factor, the block sets
it to 1.
is the value you entered for
the Border intensity parameter.

Specify the type of shape(s) to draw. Your choices are Rectangles, Lines, Polygons, or Circles.
Fill the shape with an intensity value or a color.
Specify the intensity of the shading inside the shape. This parameter is visible if you select the Fill shapes check box.
Specify the appearance of the shape's border. If you select Black, the border is black. If you select White, the border is white. If you select User-specified value, the Value(s) parameter appears in the dialog box. This parameter is visible if you clear the Fill shapes check box.
Specify an intensity or color value for the shape's border or fill. This parameter is visible if, for the Border value or Fill value parameter, you select User-specified value. Tunable when Use antialiasing is turned off.
Specify the opacity of the shading inside the shape, where 0 is transparent and 1 is opaque. This parameter is visible if you select the Fill shapes check box.
Define the area in which to draw the shapes. If you select Entire image, you can draw shapes in the entire image. If you select Specify region of interest via port, the ROI port appears on the block. Enter a four-element vector, [r c height width], where r and c are the row and column coordinates of the upper-left corner of the area, and height and width represent the height (in rows) and width (in columns) of the area.
Perform a smoothing algorithm on the line, polygon, or circle. This parameter is visible if, for the Shape parameter, you select Lines, Polygons, or Circles.
Specify how to input and output a color video signal. If you select One multidimensional signal, the block accepts an M-by-N-by-P color video signal, where P is the number of color planes, at one port. If you select Separate color signals, additional ports appear on the block. Each port accepts one M-by-N plane of an RGB video stream.
[1] Gupta, S. and R.F. Sproull, "Filtering Edges for Gray-Scale Displays", Computer Graphics, Vol. 15, No. 3, August 1981.
Video and Image Processing Blockset | |
Video and Image Processing Blockset |
![]() | Draw Shape (Obsolete) | Edge Detection | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |