finally finished region calculation function