Functions for pre-processing the image