I\'m trying to figure out how to do the equivalent of this matlab code in OpenCV, A few places to use cv::remap as an alternative to interp2, but it is
You just need to do:
remap(img, imgNew, Ix, Iy, CV_INTER_LINEAR);
Seriously, I tested it and it gives identical results to your MATLAB code (and the images you attached).
The 'irregular' grid people are mentioning refer to the sample points grid (XI and YI in your case). While in MATLAB these are allowed arbitrary values on the image, in OpenCV these have to be simply the grid of pixels in the target image (imgNew in your case):
XI = 1 2 ... n YI = 1 1 ... 1
1 2 ... n 2 2 ... 2
... ...
1 2 ... n m m ... m
This is why in OpenCV you do not even pass the remap function the XI and YI matrices since Ix and Iy are assumed to correspond to the sample points above.
Luckily you calculated your Ix and Iy matrices accordingly so it works just out of the box.
This is all due to the fact that remap is implemented by something like:
for x <- 1...n
for y <- 1...m
imgNew(x,y) = interpolate the value of img at the point (Ix(x,y), Iy(x,y))
end
end
As mentioned in the remap theory and documentation.