Looping scatteredInterpolant across each frame in 3D matrix

2 次查看(过去 30 天)
I am trying to perform a 2D interpolation across each frame in the 3rd dimension in a 3D matrix.
I have:
xgrid: 759x551
ygrid: 759x551
zgrid: 759x551x523
I am hoping to interpolate each frame of the zgrid but scatteredInterpolant does not allow indexing nor the use of cell arrays.
My first step is to use meshgrid to create the 2D resolution I desire, I end up with:
xgrid_q: 301x201
ygrid_q: 301x201
My question is, how do I interpolate the zgrid into 301x201x523?
  4 个评论
Matt J
Matt J 2023-6-1
编辑:Matt J 2023-6-1
My data is gridded but it is not a regular rectangular grid. I am hoping to interpolate it onto a regular grid. When I try to use griddedInterpolant, I get an error that the grid arrays must have NDGRID structure.
If your data is gridded, it should have NDGRID structure. That's what it means to be gridded.
Please shows us the plot you get when you do this,
scatter(xgrid(:),ygrid(:))
zooming in as necessary so we can see how the xgrid(i),ygrid(i) pairs are spaced apart.
Laura Szczyrba
Laura Szczyrba 2023-6-1
Yeah I think the image will help you see that it is gridded but not rectangular gridding. I am hoping to interpolate it onto a grid that is regular (y = 2 4 6 8....; x = 2, 4, 6, 8...)

请先登录,再进行评论。

采纳的回答

Steven Lord
Steven Lord 2023-6-1
Using the variable names given on the scatteredInterpolant documentation page, do you mean that your xgrid variable is the x input, ygrid is the y input, and zgrid is actually the v input, the values of the function you want to interpolate at the points in xgrid and ygrid? So you're not actually changing the grid each time, you're changing the values to try to interpolate 523 different data sets one at a time using the same object?
If that's what you're trying to do see the "Replacement of Sample Values" on the documentation page I linked above. Just change the Values property of the scatteredInterpolant object to reference a different page of the zgrid variable each time you want to interpolate. This allows the object to continue using the same triangulation it built when it was originally constructed, which is a lot of the work involved in creating the object.
Or if you're trying to do gridded interpolation, the griddedInterpolant object makes this even a little easier. As stated in the Version History section of that documentation page, as of release R2021a you can "specify a 2-D grid, a 3-D array of values at the grid points, and a 2-D collection of query points, then griddedInterpolant returns the interpolated values at the query points for each 2-D page in the 3-D array of values." See the "Interpolate Multiple Sets of Values on Same Grid" example on the griddedInterpolant documentation page I linked above.

更多回答(1 个)

Matt J
Matt J 2023-6-1
编辑:Matt J 2023-6-1
Since your grids are related by an affine warping, it might be best to use imwarp, assuming you have the appropriate toolbox.Example:
zgrid(:,:,1) = imread('cameraman.tif');
zgrid(:,:,2) = imresize(im2gray(imread('peppers.png')),[256,256]);
montage(zgrid)
tform = affine2d([1 0 0; .5 1 0; 0 0 1]);
Zgrid = imwarp(zgrid,tform);
montage(Zgrid)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by