CreateMaskShape
| Declaration: |
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 small script resizes the boolean array Mask to 50x50 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 [25,25], the radius of the circle is 10 pixels. The mask is then used to fill the non-masked parts of the numeric array data by the value 22.22. This array is then copied to the main data matrix of DataLab.
program MaskedArray;
const
NX = 50;
NY = 50;
var
Mask : TBool2DArray;
Data : TDouble2DArray;
begin
ResizeBool2DArray (Mask, NX, NY);
Resize2DArray (Data, NX, NY);
CreateMaskShape (mask, skCircle, [NX div 2, NY div 2, 10]);
FillMatrixMasked (data, 22.22, Mask);
DStore.Resize (NX, NY);
DStore.CopyDataFrom2DArray (data, 0,0,0,0,1,1);
end.
|
|