A fast algorithm to calculate the Euler number for binary images