some functions to process 2d image