bug fix for a crash when input image is small

bug fix for a crash when input image is small