Draw rectangles, lines, polygons, or circles on images
Text & Graphics
visiontextngfix
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.
The output signal is the same size and data type as the inputs to the Image, R, G, and B ports.
You can set the shape fill or border color via the input port or via the input dialog. Use the color input or color parameter to determine the appearance of the rectangle(s), line(s), polygon(s), or circle(s).
Port  Input/Output  Supported Data Types  Complex Values Supported 

Image  MbyN matrix of intensity values or an MbyNbyP color values where P is the number of color planes 
 No 
R, G, B  Scalar, vector, or matrix that is 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 Image port  No 
Pts  Use integer values to define onebased shape coordinates. If you enter noninteger values, the block rounds them to the nearest integer. 
 No 
ROI  4element vector of integers [x y width height], that define a rectangular area in which to draw the shapes. The first two elements represent the onebased coordinates of the upperleft corner of the area. The second two elements represent the width and height of the area. 
 No 
Clr  This port can be used to dynamically specify shape color. Pelement vector or an MbyP matrix, where M is the number of shapes, and P, the number of color planes. You can specify a color (RGB), for each shape, or specify one color for all shapes.  Same as Image port  No 
Output  Scalar, vector, or matrix of pixel values that contain the shape(s)  Same as Image port  No 
Use the Shape parameter and Pts port to draw the following shapes or lines:
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  Fourelement row vector [x y width
height] where


M Rectangles  Mby4 matrix $$\left[\begin{array}{cccc}{x}_{1}& {y}_{1}& widt{h}_{1}& heigh{t}_{1}\\ {x}_{2}& {y}_{2}& widt{h}_{2}& heigh{t}_{2}\\ \vdots & \vdots & \vdots & \vdots \\ {x}_{M}& {y}_{M}& widt{h}_{M}& heigh{t}_{M}\end{array}\right]$$ where each row of the matrix corresponds to a different rectangle and is of the same form as the vector for a single rectangle. 

For an example of how to use the Draw Shapes block to draw a rectangle, see Track an Object Using Correlation.
The Draw Shapes block lets you draw either a single line, or
one or more polylines. You can draw a polyline with 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  Fourelement row vector [x_{1} y_{1} x_{2} y_{2}] where


M Lines  Mby4 matrix $$\left[\begin{array}{cccc}{x}_{11}& {y}_{11}& {x}_{12}& {y}_{12}\\ {x}_{21}& {y}_{21}& {x}_{22}& {y}_{22}\\ \vdots & \vdots & \vdots & \vdots \\ {x}_{M1}& {y}_{M1}& {x}_{M2}& {y}_{M2}\end{array}\right]$$ where each row of the matrix corresponds to a different line and is of the same form as the vector for a single line. 

Single Polyline with (L1) Segments  Vector of size 2L, where L is
the number of vertices, with format, [x_{1},
y_{1}, x_{2}, y_{2},
..., x_{L}, y_{L}] .


M Polylines with (L1) Segments  Mby2L matrix $$\left[\begin{array}{ccccccc}{x}_{11}& {y}_{11}& {x}_{12}& {y}_{12}& \cdots & {x}_{1L}& {y}_{1L}\\ {x}_{21}& {y}_{21}& {x}_{22}& {y}_{22}& \cdots & {x}_{2L}& {y}_{2L}\\ \vdots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\ {x}_{M1}& {y}_{M1}& {x}_{M2}& {y}_{M2}& \cdots & {x}_{ML}& {y}_{ML}\end{array}\right]$$ where each row of the matrix corresponds to a different polyline and is of the same form as the vector for a single polyline. When you require one polyline to contain less than (L–1) number of segments, fill the matrix by repeating the coordinates of the last vertex. The block produces an error message if the number of rows is less than two or not a multiple of two. 

If you select the Use antialiasing check box, the block applies an edge smoothing algorithm.
For examples of how to use the Draw Shapes block to draw a line, see Detect Lines in Images and Measure 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 vector of size 2L, where L is
the number of vertices, with format, [x_{1} y_{1} x_{2} y_{2} ...
x_{L} y_{L}] where
[x_{1} y_{1}] to [x_{L} y_{L}] to
complete the polygon. The block produces an error if the number of
rows is negative or not a multiple of two. 

M Polygons with the largest number of line segments in any line being L  Mby2L matrix $$\left[\begin{array}{ccccccc}{x}_{11}& {y}_{11}& {x}_{12}& {y}_{12}& \cdots & {x}_{1L}& {y}_{1L}\\ {x}_{21}& {y}_{21}& {x}_{22}& {y}_{22}& \cdots & {x}_{2L}& {y}_{2L}\\ \vdots & \vdots & \vdots & \vdots & \ddots & \vdots & \vdots \\ {x}_{M1}& {y}_{M1}& {x}_{M2}& {y}_{M2}& \cdots & {x}_{ML}& {y}_{ML}\end{array}\right]$$ where each row 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. 

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  Threeelement row vector[x y radius] where


M Circles  Mby3 matrix $$\left[\begin{array}{ccc}{x}_{1}& {y}_{1}& radiu{s}_{1}\\ {x}_{2}& {y}_{2}& radiu{s}_{2}\\ \vdots & \vdots & \vdots \\ {x}_{M}& {y}_{M}& radiu{s}_{M}\end{array}\right]$$ where each row of the matrix corresponds to a different circle and is of the same form as the vector for a single circle. 

Specify the type of shape(s) to draw. Your choices are Rectangles
, Lines
, Polygons
,
or Circles
.
The block performs a smoothing algorithm when you select the Use
antialiasing check box with either Lines
, Polygons
,
or Circles
. The block uses an algorithm
similar to the poly2mask
function
to determine which subpixels to draw.
Fill the shape with an intensity value or a color.
When you select this check box, the Fill color source, Fill color and Opacity factor (between 0 and 1) parameters appear in the dialog box.
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. 
When you do not select the Fill shapes check box, the Border color source, and Border color parameters are available.
Specify source for fill color value to either Specify
via dialog
or Input port
. This parameter
appears when you select the Fill shapes check
box. When you select Input port
, the color input
port clr appears on the block.
Specify the fill color for shape. You can specify either Black
, White
,
or Userspecified value
. When you select Userspecified
value
, the Color value(s) parameter
appears in the dialog box. This parameter is visible if you select
the Fill shapes check box.
Specify source for the border color value to either Specify
via dialog
or Input port
. Border color
options are visible when the fill shapes options are not selected.
This appears when you select the Fill shapes check
box. When you select Input port
, the color input
port clr appears on the block.
Specify the appearance of the shape's border. You can specify
either Black
, White
, or Userspecified
value
. If you select Userspecified value
,
the Color value(s) parameter appears in the dialog
box. This parameter appears when you clear the Fill shapes check
box.
Specify an intensity or color value for the shape's border or
fill. This parameter applies when you set the Border color or Fill
color parameter to Userspecified value
.
This parameter is tunable.
The following table describes what to enter for the color value based on the block input and the number of shapes you are drawing.
Block Input  Color Value(s) for Drawing One Shape or Multiple Shapes with the Same Color  Color Value(s) for Drawing Multiple Shapes with Unique Color 

Intensity image  Scalar intensity value  Relement vector where R is the number of shapes 
Color image  Pelement vector where P is the number of color planes  RbyP matrix where P is the number of color planes and R is the number of shapes 
For each value in the Color 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.
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.
The following table describes what to enter for this parameter
based on the block input and the number of shapes you are drawing.
This parameter applies when you select the Filled
check
box.
Opacity Factor value for Drawing One Shape or Multiple Shapes with the Same Color  Oopacity Factor value for Drawing Multiple Shapes with Unique Color 

Scalar intensity value  Relement vector where R is the number of shapes 
Specify the type of area in which to draw shapes. You can define one of the following:
Entire image
, enables you to draw
shapes in the entire image.
Specify region of interest via port
.
When you select this option, the ROI port appears on the block. Enter
a fourelement vector of integer values, [x y width height]
,
where [x y
] are the coordinates of the upperleft
corner of the area.
Note: If you specify values that are outside the image, the block sets the values to the image boundaries. 
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. Select one of the following:
One multidimensional signal
, the
block accepts an MbyNbyP color
video signal, where P is the number of color
planes, at one port.
Separate color signals
, additional
ports appear on the block. Each port accepts one MbyN plane
of an RGB video stream.
Computer Vision System Toolbox™ software  
Computer Vision System Toolbox software 