fix crash when sample point out of image boundaries