The error message says that low >= high, given that in your function call, low=0 and high=h-new_h, then the problem is that the new_h is larger that h, Meaning that the size of the random crop you want is actually bigger than the original image.