Draw Shapes
Draw rectangles, lines, polygons, or circles on images
- Library:
Computer Vision Toolbox / Text & Graphics
Description
The Draw Shapes block draws rectangles, lines, polygons, or circles on images by overwriting pixel values. As a result, the shapes are embedded in the output image. The block uses Bresenham's line drawing algorithm to draw lines, polygons, and rectangles and 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 by manually entering the values in the Block Parameters window. Use the color parameters to determine the appearance of the rectangles, lines, polygons, or circles.
Ports
Input
Image
— Input image
M-by-N matrix of intensity values | M-by-N-by-P color
values
Input image, specified as either an M-by-N matrix of intensity values or an M-by-N-by-P matrix of color values with P color planes.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
R
— Red video stream
scalar | vector | matrix
Red video stream, specified as a scalar, vector, or a matrix. The input represents one plane of the RGB video stream. The R, G, and B ports must have the same dimensions and data type.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
G
— Green video stream
scalar | vector | matrix
Green video stream, specified as a scalar, vector, or a matrix. The input represents one plane of the RGB video stream. The R, G, and B ports must have the same dimensions and data type.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
B
— Blue video stream
scalar | vector | matrix
Blue video stream, specified as a scalar, vector, or a matrix. The input represents one plane of the RGB video stream. The R, G, and B ports must have the same dimensions and data type.
Dependencies
To enable this port, set the Image signal parameter to
Separate color signals
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
Pts
— Shape coordinates
M-by-3 matrix | M-by-4 matrix | M-by-2L
Shape coordinates. The format of the points depends on the type of shape you specify with the Shape parameter.
Rectangles
— M-by-4 matrix of M rectangles. The format for each rectangle must be, [x y width height].Shape Input to the Pts Port Drawn Shape Single Rectangle Four-element row vector in the format
[x y width height]
, where:x
andy
are the one-based coordinates of the upper-left corner of the rectangle.width
andheight
are the width and height in pixels, of the rectangle. The values ofwidth
andheight
must be greater than 0.
M Rectangles M-by-4 matrix in the format
,where each row of the matrix corresponds to a different rectangle and is of the same form as the vector for a single rectangle.Lines
— M-by-2L matrix of M polylines. The format for each polyline must be of the form [x1,y1,x2,y2,…,xL,yL].Shape Input to the Pts Port Drawn Shape Single Line Four-element row vector in the format [x1 y1 x2 y2]
, where:x1
andy1
are the coordinates of the beginning of the line.x2
andy2
are the coordinates of the end of the line.
M Lines M-by-4 matrix in the format
,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 (L-1) Segments Vector of size 2L, where L is the number of vertices, in the format, [x1, y1, x2, y2, ..., xL, yL
, whereThe polyline always contains (L-1) number of segments because the first and last vertex points do not connect. The block produces an error message when the number of rows is less than two or not a multiple of two.x1 and y1 are the coordinates of the beginning of the first line segment.
x2 and y2 are the coordinates of the end of the first line segment and the beginning of the second line segment.
xL and yL are the coordinates of the end of the (L-1)th line segment.
M Polylines with (L-1) Segments M-by-2L matrix in the format
, 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.
Polygons
— M-by-2L matrix of M polygons. The format for each polygon must be of the form [x1,y1,x2,y2,…,xL,yL]. The points are specified in consecutive order to form a polygon.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, in the format [x1 y1 x2 y2 ... xL yL]
, where:The block connectsx1 and y1 are the coordinates of the beginning of the first line segment.
x2 and y2 are the coordinates of the end of the first line segment and the beginning of the second line segment.
xL and yL are the coordinates of the end of the (L-1)th line segment and the beginning of the Lth line segment.
[x1 y1]
to[xL yL]
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 M-by-2L matrix in the format
, 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.
Circles
— M-by-3 matrix of M circles. The format for each circle must be, [x y radius].Shape Input to the Pts Port Drawn Shape Single Circle Three-element row vector in the format
[x y radius]
, where:x
andy
are coordinates for the center of the circle.radius
is the radius of the circle, which must be greater than 0.
M Circles M-by-3 matrix in the format
, where each row of the matrix corresponds to a different circle and is of the same form as the vector for a single circle.
Dependencies
Double-precision floating point is only supported if the input to the Image or R, G, and B ports is floating point.
Single-precision floating point (only supported if the input to the Image or R, G, and B ports is floating point).
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
ROI
— Region of interest
four-element vector
Region of interest, specified as a four-element vector [x y width height]. The region defines a rectangular area to draw shapes. The first two elements represent the one-based coordinates of the upper-left corner of the area. The second two elements represent the width and height of the area.
Dependencies
To enable this port, set the ROI port appears when you set
the Draw shapes in parameter to Specify region of
interest via port
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
Clr
— Color of shape
P-element vector | M-by-P matrix
Color of shape, specified as either a P-element vector or an M-by-P matrix of M number of shapes and P number of color planes. You can specify a color (RGB) for each shape, or specify one color for all shapes.
Dependencies
To enable this port, set the Border color source parameter to Input port.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
Output
Port_1
— Output image
scalar | vector | matrix
Output image, returned as a scalar, vector, or matrix.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
| bus
Parameters
Main Tab
Fill Shapes
— Fill color
off (default) | on
Select Fill Shapes to specify an intensity value or a color.
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.
Fill color source
— Source for fill color
Specify via dialog
(default) | Input port
Specify the source for the fill color value to either Specify via
dialog
or Input port
.
Dependencies
To enable this parameter, select Fill shapes.
Fill color
— Shape fill color
Black
(default) | White
| User-specified value
Specify the shape fill color.
Dependencies
To enable this parameter, select the Fill shapes parameter.
Border color source
— Border color source
(default) |
Specify the source for the border color value to either Specify via
dialog
or Input port
.
Dependencies
To enable this parameter, select the Fill shapes parameter.
Border color
— Border color
Black
(default) | White
| User-specified value
Specify the appearance of the shape's border. You can specify
Black
, White
, or
User-specified value
. This 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 Colors |
---|---|---|
Intensity image | Scalar intensity value | R-element vector where R is the number of shapes |
Color image | P-element vector where P is the number of color planes | R-by-P 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.
Dependencies
To enable this parameter, clear the Fill shapes parameter.
Color value(s)
— Color value
color value | intensity value
Specify an intensity or color value for the shape's border or fill.
Tunable: Yes
Dependencies
To enable this parameter set the Border color or
Fill color parameter to User-specified
value
.
Opacity factor (between 0 and 1)
— Opacity factor
value in the range [0,1] | R-element vector
Specify the opacity of the shading inside the shape, where 0
is
transparent and 1
is opaque.
Opacity Factor value for Drawing One Shape or Multiple Shapes with the Same Color | Opacity Factor value for Drawing Multiple Shapes with Unique Colors |
---|---|
Scalar intensity value | R-element vector where R is the number of shapes |
Dependencies
To enable this parameter, clear the Fill shapes parameter.
Use antialiasing
— Smoothing algorithm
off | on
Perform a smoothing algorithm on the line, polygon, or circle.
Dependencies
To enable this parameter, set the Shape parameter to either
Lines
,Polygons
, orCircles
.
Image Signal
— Image signal
Specify how to input and output a color video signal. Select the color video signal as one of the following:
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.Separate color signals
— Enables the R,G, and B input ports. Each port accepts one M-by-N plane of an RGB video stream.
Data Types Tab
For details on the fixed-point block parameters, see Specify Fixed-Point Attributes for Blocks.
Model Examples
Block Characteristics
Data Types |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
Version History
See Also
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)