Interpolation / nearest vs. linear or cubic - speed advantage

14 visualizzazioni (ultimi 30 giorni)
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 Commento
dpb
dpb il 13 Gen 2016
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)?

Accedi per commentare.

Risposte (1)

Matt J
Matt J il 13 Gen 2016
Modificato: Matt J il 13 Gen 2016
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.

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by