someting wrong using interp2

I would like to interpolate the values of an image I. The pixels of I have a specified position in point_seabed_e and point_seabed_n wich are not regularly spaced. I get: Error using griddedInterpolant Grid arrays must have NDGRID structure. How coul I fix it? Thanks
figure(20)
x=[-20:0.01:20];
y=[0:-0.05:-20];
[Xq,Yq] = meshgrid(x,y);
I=[SSS_ground_left SSS_ground_right];
Tq = interp2(point_seabed_e,point_seabed_n,I,Xq,Yq,'nearest');
surf(Xq,Yq,Tq)
view(2)

3 Kommentare

KSSV
KSSV am 6 Jul. 2021
Can you tell us the dimensions of point_seabed_e,point_seabed_n,I ? I suspect the problem is in here.
Share your data.
Valeria Leto
Valeria Leto am 6 Jul. 2021
Hi! they are 318x2000
Valeria Leto
Valeria Leto am 6 Jul. 2021
I

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 6 Jul. 2021

2 Stimmen

You can use scatteredInterpolant instead of griddedInterpolant. I'm attaching a demo.

5 Kommentare

Valeria Leto
Valeria Leto am 7 Jul. 2021
nice demo! I'll try to adapt it to my code. I'll let you know
Image Analyst
Image Analyst am 8 Jul. 2021
So how did it work out? If it worked, please "Accept this answer".
Valeria Leto
Valeria Leto am 8 Jul. 2021
Hi, no it didn't :( The problem is that my image is georeferenced. What I mean is that I have east and north coordinates in two different matrices and I with is my image in which there are gray values. I use surf to visualize it and it is not saved as .png. Maybe I shoud convert it into a .png format but I must respect the pixel location expressed in east and north and I don't know how to do that....If you have any ideas...
Image Analyst
Image Analyst am 8 Jul. 2021
No. Sounds like it might need the Mapping Toolbox, which I don't have. Do you have that, and is it using that?
An image is an array in memory. It makes no difference where it came from - a PNG file on disk, or created by your program or whatever. Once it's in an array, all that is forgotten and all you need is the array.
Meshgrid can take floating point numbers - they don't have to be pixel coordinates.
I have the Mapping Toolbox, but I don't have the knowledge to use it. Anyway this is what I have done reading your demo. The problem is that I get negavite values in vq which shoud vary from 0 to 255.
%east coordinate
x=zeros(1,318*2000);
for i=1:1:318
x(1,1+(i-1)*2000:1+(i-1)*2000+1999)=point_seabed_e(i,:);
end
%north
y=zeros(1,318*2000);
for i=1:1:318
y(1,1+(i-1)*2000:1+(i-1)*2000+1999)=point_seabed_n(i,:);
end
%image gray level
C=zeros(1,318*2000);
for i=1:1:318
C(1,1+(i-1)*2000:1+(i-1)*2000+1999)=I(i,:);
end
x=x';
y=y';
C=C';
F = scatteredInterpolant(x,y,C);
%query points
u=[-20:0.01 :20];%1 cm
v=[0:-0.01:-20];
[Xq,Yq] = meshgrid(u,v);
Zq=zeros(2001,4001);
figure(20)
mesh(Xq,Yq,Zq)
xq = Xq(:);
yq =Yq (:);
% Evaluate the interpolant at query locations (xq,yq).
vq = F(xq, yq);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interpolation finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 5 Jul. 2021

Kommentiert:

am 8 Jul. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by