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.
bSuccess, nX, nY = CCentroid:Calc( x, y ) |
x and y are initial guesses for the centroid coordinate (x,y), in pixel coordinates.
The returned values nX and nY are the centroid position in pixel coordinates.
On successful calculation, this method returns true.
On failure, this method returns false.
This method returns a boolean success flag, followed by the x and y centroid coordinates. Since the success flag is returned first, you can test for successful return value by testing the first return value as shown in the example below. Upon a successful calculation, the centroid coordinates are also stored in the class properties that can be retrieved using the class methods X and Y. The centroid calculation can fail if the starting coordinate or the calculated centroid coordinate lies outside the image.
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 |
|
-- centroid on peaks, not valleys |
|
-- calculate the centroid |
|
-- if successful, print the result |
|
-- returned by the method |
|
-- stored in the class |
|
|
|
-- clean up memory |
Case 2: Below is shown the same calculation but using the first returned parameter (the success flag) and ignoring the x,y values returned from the function call:
|
-- create a CCentroid object |
|
-- point near the centroid position |
|
-- centroid on peaks, not valleys |
|
-- Calculate the centroid, test for success |
|
-- if successful, print the result |
|
|
|
-- clean up memory |
CCentroid, X, Y, Image Coordinate System, Subpixel Coordinate Definition
Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics,
Inc. All Rights Reserved.