Interpolation / nearest vs. linear or cubic - speed advantage

20 次查看(过去 30 天)
I want to speed up my code. Profiling indicates that a lot of time is spent in interp3 using linear interpolation.
I am benchmarking nearest interpolation right now. Is nearest worth using? Why don't I just calculate the index that is closest *myself*? Will it execute faster to build my own code to find the index or use nearest interpolation?
  1 个评论
dpb
dpb 2016-1-13
Only testing for your specific sizes of inputs and your implementation will answer that question...
If it makes no difference as to which result you obtain, why bother at all (rhetorical, yes, but to raise the point of what's the value of the end result)?

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2016-1-13
编辑:Matt J 2016-1-13
Whether nearest-neighbor is worth using depends on whether you personally like the the quality of the result that it gives. People will use smoother interpolation methods like linear and cubic when they desire/require smoother results.
As for accelerating things, I wouldn't expect that your own implementation would be faster, if done in MCode. INTERP3 uses optimized compiled C code specifically with the idea of helping things go fast. You could browse the File Exchange for customized interpolation code offered by other contributors,
As another suggestion, if you are making repeated calls to interp3 on the same volume array, it will be more optimal to pre-construct on interpolation operator using griddedInterpolant(). This lets you skip argument parsing and setup steps that interp3 might be repeating unnecessarily.

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by