flatten the image as much as possible