Products & Services Industries Academia Support User Community Company

Learn more about Video and Image Processing Blockset   

Draw Shapes - Draw rectangles, lines, polygons, or circles on images

Library

Text & Graphics

Description

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.

PortInput/OutputSupported Data TypesComplex Values Supported

Image

M-by-N matrix of intensity values or an M-by-N-by-P color values where P is the number of color planes

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point

  • Boolean

  • 8-, 16-, and 32-bit signed integer

  • 8-, 16-, and 32-bit unsigned integer

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 Image 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.

  • Double-precision floating point (only supported if the input to the I or R, G, and B ports is floating point)

  • Single-precision floating point (only supported if the input to the I or R, G, and B ports is floating point)

  • 8-, 16-, and 32-bit signed integer

  • 8-, 16-, and 32-bit unsigned integer

No

ROI

4-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.

  • Double-precision floating point

  • Single-precision floating point

  • 8-, 16-, and 32-bit signed integer

  • 8-, 16-, and 32-bit unsigned integer

No

Clr

P-element vector or P-by-N matrix, where P is the number of color planes

Same as Image port

No

Output

Scalar, vector, or matrix of pixel values that contain the shape(s)

Same as Image 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 one of the following types type of shape(s) to draw.

Use the Draw shapes in parameter to define one of the following types of area in which to draw the shapes.

If, for the Shape parameter, you select:

and you then select the,

the block performs a smoothing algorithm. The Draw Shapes block uses an algorithm similar to the poly2mask function to determine which subpixels to draw.

Use the Image signal parameter to specify one of the following ways to input and output a color video signal.

Selecting Shape Fill and Border Colors

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).

Fill Color

If you select the Fill shapes check box, the Fill color source, Fill color and Opacity factor (between 0 and 1) parameters appear in the dialog box. Use the Fill color source parameter to specify either Input port or Specify via dialog for the color source. If Specify via dialog is selected, you can specify either Black, White, or User-specified value for the Fill color parameter for the shading inside the shape. The Color value(s) parameter is applicable when the User-specified value is selected. 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.

Border Color

If the Fill shapes check box is not selected, the Border color source, and Border color parameters are available. Use the Border color source parameter to specify either Input port or Specify via dialog for the color source. If Specify via dialog is selected, you can specify either Black, White, or User-specified value for the Border color parameter. If the color is user specified, the Color value(s) parameter is used to enter the color.

Color Values

The following table describes what to enter for the Color Value(s) parameter based on the block input and the number of shapes you are drawing.

Block InputColor Value(s) for Drawing One Shape or Multiple Shapes with the Same ColorColor Value(s) for Drawing Multiple Shapes with Unique Color
Intensity imageScalar intensity valueR-element vector where R is the number of shapes
Color imageP-element vector where P is the number of color planesP-by-R 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.

Opacity Factor

The following table describes what to enter for the Opacity factor(s) (between 0 and 1) parameter based on the block input and the number of shapes you are drawing. This parameter is applicable when the Filled check box is selected.

Opacity Factor value for Drawing One Shape or Multiple Shapes with the Same ColorOopacity Factor value for Drawing Multiple Shapes with Unique Color
Scalar intensity valueR-element vector where R is the number of shapes

Defining Shapes to Draw

This section explains how to use the Shape parameter and the Pts port to draw the following shapes:

Drawing Rectangles

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.

ShapeInput to the Pts PortDrawn Shape
Single RectangleFour-element row or column vector
[r c height width] where
  • r and c are the zero-based row and column coordinates of the upper-left corner of the rectangle.

  • height and width are the height, in pixels, and width, in pixels, of the rectangle. Here, height and width must be greater than 0.

N Rectangles

4-by-N matrix

where each column 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 Tracking an Object Using Correlation.

Drawing Lines and Polylines

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.

ShapeInput to the Pts PortDrawn Shape
Single LineFour-element row or column vector [r1 c1 r2 c2] where
  • r1 and c1 are the row and column coordinates of the beginning of the line.

  • r2 and c2 are the row and column coordinates of the end of the line.

N Lines

4-by-N matrix

where each column 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 SegmentsVector of size 2L[r1 c1 r2 c2 ... rL cL] where
  • r1 and c1 are the row and column coordinates of the beginning of the first line segment.

  • r2 and c2 are the row and column coordinates of the end of the first line segment and the beginning of the second line segment

  • rL and cL are the row and column coordinates of the end of the L-1th line segment.

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.

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.

Drawing Polygons

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.

ShapeInput to the Pts PortDrawn Shape
Single Polygon with L line segmentsRow or column vector of size 2L [r1 c1 r2 c2 ... rL cL] where
  • r1 and c1 are the row and column coordinates of the beginning of the first line segment.

  • r2 and c2 are the row and column coordinates of the end of the first line segment and the beginning of the second line segment

  • rL and cL are the row and column coordinates of the end of the L-1th line segment and the beginning of the Lth line segment.

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.

Drawing Circles

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.

ShapeInput to the Pts PortDrawn Shape
Single CircleThree-element row or column vector
[r c radius] where
  • r and c are the row and column coordinates of the center of the circle.

  • radius is the radius of the circle, which must be greater than 0.

N Circles

3-by-N matrix

where each column of the matrix corresponds to a different circle and is of the same form as the vector for a single circle.

Dialog Box

Shape

Specify the type of shape(s) to draw. Your choices are Rectangles, Lines, Polygons, or Circles.

Fill shapes

Fill the shape with an intensity value or a color.

Fill color source

Specify source for fill color value to either Specify via dialog or Input port. This parameter is visible if you select the Fill shapes check box.

Fill color

If you select Black, the border is black. If you select White, the border is white. If you select User-specified value, the Color value(s) parameter appears in the dialog box. This parameter is visible if you select the Fill shapes check box.

Border color source

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 parameter is visible if you select the Fill shapes check box.

Border color

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 Color value(s) parameter appears in the dialog box. This parameter is visible if you clear the Fill shapes check box.

Color value(s)

Specify an intensity or color value for the shape's border or fill. This parameter is visible if, for the Border color or Fill color parameter, you select User-specified value. This parameter is tunable.

Opacity factor (between 0 and 1)

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.

Draw shapes in

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.

Use antialiasing

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.

Image signal

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.

See Also

Draw Markers

Video and Image Processing Blockset software

Insert Text

Video and Image Processing Blockset software

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS