CCentroid:Calc
The Calc method computes a centroid position in an image. The starting coordinate (x,y) is passed as arguments of this method. The other centroid parameters are stored in the CCentroid class.
nX, nY, bSuccess = CCentroid:Calc( CImage, nX0, nY0 ) nX, nY, bSuccess = CCentroid:Calc( CImage, CPoint ) where |
CImage is the image object to measure.
nX0 and nY0 are initial guesses for the centroid coordinate (x,y), measured in pixels coordinates
CPoint is an initial guess for the centroid coordinate (x,y), measured in pixel coordinates.
nX and nY are the returned centroid position, measured in pixel coordinates.
bSuccess is the returned success code. On success it is true, otherwise false.
This method returns the x and y centroid coordinates plus a boolean success flag. Upon a successful calculation, the centroid coordinates are stored in the class object and later can be retrieved using the X and Y methods. The centroid calculation can fail if the starting coordinate or the calculated centroid lies outside the image. The original starting coordinates passed are stored in the CCentroid object and can be fetched using the GetStartingPos method.
Case 1: Assume that an image exists as the CImage object I. The example below shows calculation of the centroid. The results returned by the functional call and those saved in class members should be identical.
|
-- create a CCentroid object |
|
-- point near the centroid position |
|
-- calculate the centroid |
|
-- if successful, print the result |
|
-- returned by the method |
|
-- stored in the class |
|
|
Case 2: Below is shown the same calculation but hardwiring the x and y starting points and ignoring the success parameter returned by Calc. The refined x,y values for the centroid position are printed directly by setting Calc() as the last parameter for the Printf function:
|
-- create a CCentroid object |
|
-- print the result |