I understand that you are trying to use a custom interpolation method.
According to MathWorks documentation of “imwarp” function, there is no direct way to implement a custom interpolation method.
Here is a workaround to implement inverse image warping as used in “imwarp” function along with custom interpolation method.
Considerations
- The “imwarp” function performs inverse warping by using a displacement field that maps the coordinates in the warped image back to the original image.
- If (u,v) is a coordinate in the warped image then (x,y) = (u+Du,v+Dv) is the corresponding coordinate in the original image
- The custom kernel for interpolation should be a function that takes as input x, y and the original Image I and returns an intensity for the location (u,v) in the warped image.
- (x,y) need not be inside the image boundary, (x,y) can also be floating point and not lie on the integer image grid. The custom interpolation function should be able to handle all these basic conditions.
- Additionally, I have assumed that the size of the warped image is equal to the original image.If not compute the max and min bounds using the displacement field and set the locations that map outside the original image to all zero or any value, you desire.
Steps to implement custom interpolation method:
- First, define a displacement field Du and Dv.
- Next, using a for loop iterate over all (u,v) in the warped image integer grid compute the corresponding coordinate (x,y)=(u+Du,v+Dv).
- Compute the intensity using custom interpolation method by passing the original image and the corresponding coordinates (x,y) as input.
- Save the returned intensity at the location (u,v) in the warped image.
- Repeat the steps 2-4 for all (u,v) pair in the warped image.
I have also attached a file “custom_interpolation.m” that illustrates an example on how to warp an image using a custom interpolation method.
Hope this helps!