A method for determining a number of balls in a projection space comprises determining
a projection of a portion of a ball grid array, determining at least one local
maximum of the projection space for a given threshold, and determining at least
a distance between adjacent maximum. The method further comprises determining an
inter-peak histogram of the distances, determining an inter-ball distance for each
pair of adjacent balls that has the maximum value of the inter-peak distance histogram
corresponding to the pair of adjacent balls, and determining a position of a first
ball and a position of a last ball. The method comprises verifying the position
of the first ball and the position of the last ball based on a general inter-ball
distance, and determining the number of balls.