ocmath_make_strel
Description
Create a morphological structuring element by users selection.
Syntax
int ocmath_make_strel( StrelResult * pStrel, StrelParams * psParams, UINT nShape = SQUARE_SHAPE )
Parameters
- pStrel
- [output]pointer to the object of structure StrelResult. StrelResult defines a morphological structuring element.
- It has 4 elements:
- pNHoodMat: pointer to neighborhood matrix. The neighborhood matrix specifies the neighborhood.
- pHeightMat: pointer to height matrix. The height matrix must be real and finite valued and same size as the neighborhood matrix.
- When it is NULL or all cells of it equals 0, se is flat structuring element, or else nonflat.
- nRows: the row number of matrix;
- nCols: the column number of matrix;
- psParams
- [input] pointer to the object of structure StrelParams. StrelParams defines different parameters for different shape pStrel will be created.
- nShape = ARBITRARY_SHAPE: must set nRows, nCols, pNHood and pHeight. pNHood is a pointer to neighborhood matrix, which specifies the neighborhood.
pHeight is a pointer to height matrix, which must be real and finite valued and same size as the neighborhood matrix. When pHeight is NULL or all cells of it equals 0, the function will create a flat morphological structuring element, or else nonflat. nRows is row number of matrix; nCols is column number of matrix.
- nShape = RECTANGLE_SHAPE: must set nRows and nCols.
Creates a flat, rectangle-shaped structuring element, where nRows and nCols specifies the size. nRows and nCols must be nonnegative integers. nRows is the number of rows in the structuring element neighborhood; nCols is the number of columns.
- nShape = SQUARE_SHAPE: must set nWidth, the structuring element matrix's row and column number are all nWidth.
Creates a square structuring element whose width is nWidth pixels. nWidth must be a nonnegative integer.
- nShape = DIAMOND_SHAPE: must set nRadius, the structuring element matrix's row and column number are all 2*nRadius+1.
Creates a flat, diamond-shaped structuring element, where nRadius specifies the distance from the structuring element origin to the points of the diamond. nRadius must be a nonnegative integer scalar.
- nShape = OCTAGON_SHAPE: must set nRadius, the structuring element matrix's row and column number are all 2*nRadius+1.
Creates a flat, octagonal structuring element, where nRadius specifies the distance from the structuring element origin to the sides of the octagon, as measured along the horizontal and vertical axes. nRadius must be a nonnegative multiple of 3.
- nShape = PAIR_SHAPE: must set rowOffset and colOffset, the structuring element matrix's row and column number are 2*abs(rowOffset)+1 and 2*abs(colOffset)+1.
Creates a flat structuring element containing two members. One member is located at the origin. The second member's location is specified by rowOffset and colOffset. rowOffset and colOffset must be integers.
- nShape = LINE_SHAPE: must set nLen and thetaDeg, the structuring element matrix's row and column number are specified by 2*abs(round(1.0*(nlen-1)/2*cos(theta)))+1 and 2*abs(round(-1.0*(nlen-1)/2*sin(theta)))+1.
Creates a flat, linear structuring element, where nLen specifies the length, and thetaDeg specifies the angle (in degrees) of the line, as measured in a counterclockwise direction from the horizontal axis. nLen is approximately the distance between the centers of the structuring element members at opposite ends of the line.
- nShape = PERIODICLINE_SHAPE: we must set nP, rowOffset and colOffset, the structuring element matrix's row and column number are 2*[nP*abs(rowOffset)]+1 and 2*[nP*abs(colOffset)]+1.
Creates a flat structuring element containing 2*nP+1 members. rowOffset and colOffset are integer-valued row and column offsets. One structuring element member is located at the origin. The other members are located at 1*(rowOffset, colOffset), -1*(rowOffset, colOffset), 2*(rowOffset, colOffset), -2*(rowOffset, colOffset), ..., p*(rowOffset, colOffset), -p*(rowOffset, colOffset).
- It has 11 elements: nRows, nCols, pNHood, pHeight, nWidth, nRadius,rowOffset,colOffset, nP, nLen and thetaDeg.
- nShape
- [input] the type of morphological structuring element, there are 8 types: ARBITRARY_SHAPE, DIAMOND_SHAPE,
LINE_SHAPE, OCTAGON_SHAPE, PAIR_SHAPE, PERIODICLINE_SHAPE, RECTANGLE_SHAPE and SQUARE_SHAPE
Return
Returns 0 on success and a non-zero error code on failure.
Examples
EX1
void matrixbase_ImDilate_ex1()
{
matrix matData = {{0,0,0,0,0},
{0,1,2,3,0},
{0,2,3,4,0},
{0,3,4,5,0},
{0,0,0,0,0}};
matrix matHood = {{0,1,0},{1,2,1},{0,1,0}};
matrix matHeight;
matHeight = matHood;
StrelParams sp;
sp.nRows = 3;
sp.nCols = 3;
sp.pNHood = matHood;
sp.pHeight = matHeight;
matrix mNHood, mHeight;
mNHood.SetSize(3,3);
mHeight.SetSize(3,3);
StrelResult se;
se.nRows = 3;
se.nCols = 3;
se.pNHoodMat = mNHood;
se.pHeightMat = mHeight;
int nRet = ocmath_make_strel(&se, &sp, ARBITRARY_SHAPE);
if(nRet != OE_NOERROR)
{
printf(" Error: Make strel failed. Error Code=%d\n", nRet);
return;
}
}
Remark
See Also
header to Include
origin.h
Reference
|