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.

Syntax

bSuccess, nX, nY = CCentroid:Calc( x, y )

bullet.gif    x and y are initial guesses for the centroid coordinate (x,y), in pixel coordinates.

bullet.gif    The returned values nX and nY are the centroid position in pixel coordinates.

bullet.gif    On successful calculation, this method returns true.

bullet.gif    On failure, this method returns false.

Remarks

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.

Example

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.

 

C = new_centroid()

-- create a CCentroid object

x0 = 192 ; y0 = 440

-- point near the centroid position

C:SetSign(true)

-- centroid on peaks, not valleys

bSuccess, x, y = C:Calc(I,x0,y0)

-- calculate the centroid

if bSuccess then

-- if successful, print the result

 Printf("X=%lg, Y=%lg", x,y)

-- returned by the method

 Printf("X=%lg, Y=%lg", C:X(),C:Y())

-- stored in the class

end

 

C:delete()

-- 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:

 

C = new_centroid()

-- create a CCentroid object

x0 = 192 ; y0 = 440

-- point near the centroid position

C:SetSign(true)

-- centroid on peaks, not valleys

if C:Calc(I,x0,y0) then

-- Calculate the centroid, test for success

 Printf("X=%lg, Y=%lg", C:X(),C:Y())

-- if successful, print the result

end

 

C:delete()

-- clean up memory

Related Topics

CCentroid, X, Y, Image Coordinate System, Subpixel Coordinate Definition

 

Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.