fixes to C and R code for region growing