Added check for image coordinate bounds