first version of computing foreground segments