Skeleton fitting algorithm by the use of energy minimization