How to interpolate in a 3D lookup table in MATLAB script?

35 views (last 30 days)
Hi, I have a 3D lookup table Cost_map which is 52x21x426 matrix. it is in fact a function of three variable x, y, and z. I have three vector x which is 52x1 and y which is 21x1 and z which is 426x1 (lookup table axes) how can I interpolate for the point x_d,y_d,z_d ? something like interp2 but 3D. I have tried to use interp3 or meshgrid and .. but all of them gave me "inconsistent dimension" or other dimension related errors. I prefer to don't use interp3 because I know interp2 is very slow. what is the best option for me?
Thank you,

Answers (2)

John D'Errico
John D'Errico on 31 Dec 2014
Edited: John D'Errico on 31 Dec 2014
interp3 is the simple answer. That you got errors merely says you did not know how to call it, nor can we know your error since you have not given us a hint.
It is simply not true that interp2 is very slow. But the fact is, any interpolation on a huge set of points will take some time. That you want something to be faster is not relevant. We all want computers that do incredible amounts of work in no time at all. If, for example, you try to do a 3-d tensor product spline interpolation, it will be slower than a linear interpolant, of any ilk.
Yes, it is true that explicit code CAN be written to do pretty fast evaluation of a simple interpolant in n-dimensions. For example, 3-d LUT interpolation for color tables in color management applications can process a huge number of pixels per second. But the fact is, those interpolants are very simple linear ones, and there will be some interpolation error issues, ones that are considered acceptable in the application I have mentioned.
So, unless you know enough to write a faster interpolant than interp3, it is the best option. If you are willing to accept a linear interpolant, you may be able to do marginally better, if you can find something well written for this on the File Exchange. I've not seen anything that does better than a tensor product linear interpolation on the FEX though. (That is, in 3-d, I mean trilinear interpolation. It is not the most efficient scheme one can use, not by a long shot. I would also point out that trilinear interpolation has its own interesting quirks. For example, it is not truly a linear interpolant.)

Image Analyst
Image Analyst on 31 Dec 2014
Which of the 3D points in your 3D lookup table called Cost_map do you have already and which do you need to estimate by interpolation?
  1. Does Cost_map have only some locations populated, and the rest are zero, and you need values for those unassigned locations?
  2. Or do all 52x21x426 elements have values but you want some in-between value, like you want the value for the element located at some non-integer location like (20.5, 13.482, 329.149)? If so, how many of these values do you need? (Don't say "all of them" because there are an infinite number of fractional locations).
  6 Comments
Image Analyst
Image Analyst on 1 Jan 2015
hadi, you didn't answer the question of "how many of these values do you need?" Are we talking a few dozen, or millions of locations that you need estimates for?
Sivateja Maturu
Sivateja Maturu on 9 Apr 2019
To Image Analyst: May I know, if I have a same problem with 3D lookup table. I have 16x40x3 table, all populated. But The values I will be looking up will have 16x79x9 values which all exists in the limits. And I am using interp3(x,y,z,V,x',y',z'). And the sizes are
x: 16 valued array
y: 40 valued array
z: 3 valued array
V : 16x40x3 matrix
x',y',z' are scalars
May I know what is wrong here. I finding the error.
Error using griddedInterpolant
The grid vectors do not define a grid of points that match the given values.
Please help

Sign in to comment.

Categories

Find more on Interpolation in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!