Documentation Center

  • Trial Software
  • Product Updates

vision.ShapeInserter System object

Package: vision

Draw rectangles, lines, polygons, or circles on an image

Description

The ShapeInserter object can draw multiple rectangles, lines, polygons, or circles in a 2-D grayscale or truecolor RGB image. The output image can then be displayed or saved to a file.

Construction

shapeInserter = vision.ShapeInserter returns a System object, shapeInserter, that draws multiple rectangles, lines, polygons, or circles on images by overwriting pixel values.

shapeInserter = vision.ShapeInserter(Name,Value) returns a shape inserter System object, shapeInserter, with each specified property set to the specified value. You can specify additional name-value pair arguments in any order as (Name1, Value1,...,NameN,ValueN).

Code Generation Support
Supports MATLAB® Function block: Yes
System Objects in MATLAB Code Generation
Code Generation Support, Usage Notes, and Limitations.

To insert a shape:

  1. Define and set up your shape inserter using the constructor.

  2. Call the step method with the input image, I, the shape inserter object, shapeInserter, points PTS, and any optional properties. See the syntax below for using the step method.

J = step(shapeInserter,I,PTS) draws the shape specified by the Shape property on input image I. The input PTS specify the coordinates for the location of the shape. The shapes are embedded on the output image J.

J = step(shapeInserter,I,PTS,ROI) draws a shape inside an area defined by the ROI input. This applies only when you set the ROIInputPort property to true. The ROI input defines a rectangular area as [x y width height], where [x y] determine the upper-left corner location of the rectangle, and width and height specify the size.

J = step(shapeInserter,I,PTS,...,CLR) draws the shape with the border or fill color specified by the input CLR. This applies when you set the BorderColorSource property or the FillColorSource property to 'Input port'.

Properties

Shape

Shape to draw

You can specify the type of shape as Rectangles, Lines, Polygons, or Circles. When you specify the type of shape to draw, you must also specify the location. The PTS input specifies the location of the points. The table shows the format for the points input for the different shapes. For a more detailed explanation on how to specify shapes and lines, see Draw Shapes and Lines.

Shape propertyPTS input
'Rectangles'

M-by-4 matrix, where M specifies the number of rectangles. Each row specifies a rectangle in the format [x y width height], where [x y] determine the upper-left corner location of the rectangle, and width and height specify the size.

'Lines'

M-by-2L matrix, where M specifies the number of polylines. Each row specifies a polyline as a series of consecutive point locations, [x1, y1, x2, y2, ..., xL, yL].

'Polygons'

M-by-2L matrix, where M specifies the number of polygons. Each row specifies a polygon as an array of consecutive point locations, [x1, y1, x2, y2, ..., xL, yL]. The point define the vertices of a polygon.

'Circles'

M-by-3 matrix, where M specifies the number of circles. Each row specifies a circle in the format [x y radius], where [x y] define the coordinates of the center of the circle.

Default: Rectangles

Fill

Enable filling shape

Set this property to true to fill the shape with an intensity value or a color. This property only applies for the 'Rectangles', 'Polygons', and 'Circles' shapes.

Default: false

BorderColorSource

Source of border color

Specify how the shape's border color is provided as Input port or Property. This property applies when you set the Shape property to Lines or, when you do not set the Shape property to Lines and you set the Fill property to false. When you set theBorderColorSource property to Input port, a border color vector must be provided as an input to the System object's step method.

Default: Property

BorderColor

Border color of shape

Specify the appearance of the shape's border as Black, White, or Custom. When you set this property to Custom, you can use the CustomBorderColor property to specify the value. This property applies when you set the BorderColorSource property to Property.

Default: Black

CustomBorderColor

Intensity or color value for shape's border

Specify an intensity or color value for the shape's border. For an intensity image input, this property can be set to either a scalar intensity value for one shape, or an R-element vector where R specifies the number of shapes. For a color input image, you can set this property to:

A P-element vector where P is the number of color planes.
A P-by-R matrix where P is the number of color planes and R is the number of shapes.

This property applies when you set the BorderColor property to Custom. This property is tunable when you set the Antialiasing property to false.

Default: [200 255 100]

FillColorSource

Source of fill color

Specify how to provide the shape's fill color as Input port or Property. This property applies when you set the Fill property to true, and you do not set the Shape property to Lines. When you set the FillColorSource to Input port, you must provide a fill color vector as an input to the System object's step method.

Default: Property

FillColor

Fill color of shape

Specify the intensity of the shading inside the shape as Black, White, or Custom. When you set this property to Custom, you can use the CustomFillColor property to specify the value. This property applies when set the FillColorSource property to Property.

Default: Black

CustomFillColor

Intensity or color value for shape's interior

Specify an intensity or color value for the shape's interior. For an intensity input image, you can set this property to a scalar intensity value for one shape, or an R-element vector where R specifies the number of shapes. For a color input image, you can set this property to:

A P-element vector where P is the number of color planes.
A P-by-R matrix where P is the number of color planes and R is the number of shapes.

This property applies when you set the FillColor property to Custom. This property is tunable when you set the Antialiasing property to false.

Default: [200 255 100]

Opacity

Opacity of the shading inside shapes

Specify the opacity of the shading inside the shape by a scalar value between 0 and 1, where 0 is transparent and 1 is opaque. This property applies when you set the Fill property to true.

Default: 0.6

ROIInputPort

Enable definition of area for drawing shapes via input

Set this property to true to define the area in which to draw the shapes via an input to the step method. Specify the area as 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. When you set the property to false, the entire image will be used as the area in which to draw.

Default: false

Antialiasing

Enable performing smoothing algorithm on shapes

Set this property to true to perform a smoothing algorithm on the line, polygon, or circle. This property applies when you set the Shape property to Lines, Polygons, or Circles.

Default: false

 Fixed-Point Properties

Methods

cloneCreate shape inserter object with same property values
getNumInputsNumber of expected inputs to step method
getNumOutputsNumber of outputs from step method
isLockedLocked status for input attributes and non-tunable properties
release Allow property value and input characteristics changes
stepDraw specified shape on image

Examples

expand all

Draw a Black Rectangle in a Grayscale Input Image

Create the shape inserter object.

shapeInserter = vision.ShapeInserter;

Read the input image.

I = imread('cameraman.tif');

Define the rectangle dimensions as [x y width height].

rectangle = int32([10 10 30 30]);

Draw the rectangle and display the result.

J = step(shapeInserter, I, rectangle);
imshow(J); 

Draw Two Yellow Circles in a Grayscale Input I-mage.

Class of yellow must match class of the input, I.

yellow = uint8([255 255 0]); % [R G B]; class of yellow must match class of I

Create the shape inserter object.

shapeInserter = vision.ShapeInserter('Shape','Circles','BorderColor','Custom','CustomBorderColor',yellow);

Read the input image.

I = imread('cameraman.tif'); 

Define the circle dimensions

circles = int32([30 30 20; 80 80 25]); %  [x1 y1 radius1;x2 y2 radius2]

Convert I to an RGB image.

RGB = repmat(I,[1,1,3]); % convert I to an RGB image

Draw the circles and display the result.

J = step(shapeInserter, RGB, circles);
imshow(J); 

Draw a Red Triangle in a Color Image

Create a shape inserter object and read the image file.

shapeInserter = vision.ShapeInserter('Shape','Polygons','BorderColor','Custom', 'CustomBorderColor', uint8([255 0 0]));
I = imread('autumn.tif');

Define vertices which will form a triangle: [x1 y1 x2 y2 x3 y3].

polygon = int32([50 60 100 60 75 30]); 

Draw the triangles and display the result.

J = step(shapeInserter, I, polygon);
imshow(J); 

See Also

|

Was this topic helpful?