I transformed an image using meshgrid, but the new coordinates are partially outside the range of the original image, causing the transformation to fail.
First I used clip
...
tX = numpy.clip(tX.astype(numpy.int),0,image.w)
tY = numpy.clip(tY.astype(numpy.int),0,image.h)
result image([tX,tY])
which resulted in effect similar to the ‘nearest’ boundary condition.
I would like for all the outside pixels to be black. I thought I could achieve this by using a boolean array on the meshgrid, but I don’t know how to apply the boolean array to the meshgrid correctly.
tXbool = numpy.abs(tX) < image.w
tXbool.shape
(850, 1280)
tX[tXbool].shape
(193180,)
Okay, thats how I did it in the end: