Interp2 - make resolution lower

I have a matrix 'I' representing a digital elevation model, with a pixel resolution of 90m. I need to lower the resolution to 250m and I've been advised to do this using interp2 but I'm unclear on how to do so from the help file?
I don't understand what I put as the X, Y, Z, Xi, Yi inputs.
Thank you

댓글 수: 8

Matt Kindig
Matt Kindig 2013년 3월 7일
In what form do you have the model? Is it an image? A matrix of vertices? etc. That will help us advise you further.
Grant
Grant 2013년 3월 7일
It is in a .tif file, which appears as a 4609 x 2737 matrix, each cell representing the z value. Thank you
Matt J's suggestion of griddedInterpolant would be good. If you must use interp2, the code would be this:
Values = imread('/your/tif/file/here.tif');
Xi = 1:4609; Yi = 1:2737; %original resolution
Xo = 1:(250/90):Xi(end);
Yo = 1:(250/90):Yi(end);
ValOut= interp2(Xi, Yi, Values,Xo, Yo); %do the interpolation
%note that this will not be an image anymore
mesh(Xo, Yo, ValOut); %illustrate new data
Grant
Grant 2013년 3월 7일
Thank you, but it tells me: ??? Error using ==> interp2 at 147 The lengths of X and Y must match the size of Z.
The maximum z value, by the way, is 2470.
Matt Kindig
Matt Kindig 2013년 3월 7일
편집: Matt Kindig 2013년 3월 7일
What is the output of:
>> size(Values)
?
Image Analyst
Image Analyst 2013년 3월 7일
You can use linspace(startValue, endingValue, numberOfSteps) instead of startValue:stepValue:endingValue to make sure arrays have exactly the size (number of elements) that you want them to have.
Hi, The output of size is:
ans =
4609 2737
Thanks
Grant
Grant 2013년 3월 8일
I think previous error was just me mixing x and y, but it still tells me ??? Error using ==> interp2 at 147 XI and YI must be the same size or vectors of different orientations.

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2013년 3월 8일

1 개 추천

XI and YI must be the same size or vectors of different orientations.
Xo must be a row vector and Yo must be a column vector. So just transpose Yo
ValOut= interp2(Xi, Yi, Values,Xo, Yo.'); %do the interpolation

댓글 수: 2

Grant
Grant 2013년 3월 8일
Ahhh. I think it worked but seems futile as out of memory. (Using 250/90 processed but did it the wrong way round, increasing the resolution rather than lowering).
Doing it with 90/250 returns ??? Out of memory. Type HELP MEMORY for your options.
Error in ==> interp2>linear at 317 s = 1 + (arg4-arg1(1))/(arg1(end)-arg1(1))*(ncols-1);
Error in ==> interp2 at 220 zi = linear(ExtrapVal,x,y,z,xi,yi);
So I expect there is nothing I can do.
Thank you for your help.
I assume you're using a 32-bit machine. Pre-converting your Values to type single would probably make it fit
ValOut= interp2(Xi, Yi, single(Values),Xo, Yo.');
Or, look for a 64-bit computer to work on.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Matt J
Matt J 2013년 3월 7일
편집: Matt J 2013년 3월 7일

1 개 추천

I would advise using griddedInterpolant instead
F=griddedInterpolant(I);
Now evaluate F at the sample locations that you want. So, for example, if you want the resulting image to be 100x250, you would do
x=linspace(1,size(I,1),100);
y=linspace(1,size(I,2),250);
I_new = F({x,y});
Grant
Grant 2013년 3월 8일

0 개 추천

Thanks, but it appears I don't have griddenInterpolant in my toolbox.
I'd also prefer to use interp2 to ensure I'm consistent with another person's method.

댓글 수: 2

Matt J
Matt J 2013년 3월 8일
편집: Matt J 2013년 3월 8일
Thanks, but it appears I don't have griddenInterpolant in my toolbox.
What MATLAB version are you using? It would have to be several years old. You've spelled griddedInterpolant incorrectly, so that might be why you couldn't find it.
I'd also prefer to use interp2 to ensure I'm consistent with another person's method.
INTERP2 calls griddedInterpolant to perform its interpolations. It would be the same method, just with a somewhat easier (IMO) interface.
Grant
Grant 2013년 3월 8일
I'm using R2010a. I typed it correctly into the command window and it can't find it - nor for the help file. The same on my university computer. :/

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2013년 3월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by