The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



CreateMaskShape


Unit:SDL_openarrays
Class: none
Declaration: function CreateMaskShape (var MaskArray: TBool2DArray; Shape: TShapeKind; Params: TIntArray): integer;

The function CreateMaskShape can be used to create pixel masks based on rectangular, elliptic and circular regions. CreateMaskShape sets all matrix cells of the boolean array MaskArray within the selected Shape (including the borders) to TRUE, all other cells are left unchanged. The indices of the matrix are seen as integer coordinates (valid range: 0 <= x < length(MaskArray) and 0 <= y < length(MaskArray[0])).

Depending on the type of the shape the open array parameter Params holds different numbers of parameters. The specific meaning of each parameter can be taken from the following table:

Shape Type Parameters
skRectangle Params[0]: left edge of the rectangle
Params[1]: bottom edge of the rectangle
Params[2]: right edge of the rectangle
Params[3]: top edge of the rectangle
skEllipse Params[0]: left coordinate of bounding rectangle
Params[1]: bottom coordinate of bounding rectangle
Params[2]: right coordinate of bounding rectangle
Params[3]: top coordinate of bounding rectangle
skCircle Params[0]: x coordinate of the circle center
Params[1]: y coordinate of the circle center
Params[2]: radius of the circle
skRing Params[0]: x coordinate of the ring center
Params[1]: y coordinate of the ring center
Params[2]: radius 1 of the ring
Params[3]: radius 2 of the ring

The function returns the following error codes:

 0 ... everything OK
-1 ... invalid number of parameters (depends on the type of the shape, see table above)
-2 ... radius must not be negative

 

Example: The following code snippet resizes the boolean array Mask to 300x300 cells, resets all values to FALSE and sets all matrix cells of a circular region to TRUE values. The center of the region is at cell [100,120], the radius of the circle is 30 pixels:
...
var
  Mask  : TBool2DArray;
...
SetLength (Mask,300,300);
FillArray (Mask, FALSE);
CreateMaskShape (Mask, skCircle, [100, 120, 30]);
...



Last Update: 2023-Mar-18