statistics function for binary image.