Function to check the boundaries of an image