Looping scatteredInterpolant across each frame in 3D matrix

4 vues (au cours des 30 derniers jours)
Laura Szczyrba
Laura Szczyrba le 31 Mai 2023
Modifié(e) : Matt J le 1 Juin 2023
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 commentaires
Matt J
Matt J le 1 Juin 2023
Modifié(e) : Matt J le 1 Juin 2023
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 le 1 Juin 2023
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...)

Connectez-vous pour commenter.

Réponse acceptée

Steven Lord
Steven Lord le 1 Juin 2023
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.

Plus de réponses (1)

Matt J
Matt J le 1 Juin 2023
Modifié(e) : Matt J le 1 Juin 2023
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)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by