Azzera filtri
Azzera filtri

How to interpolate a series of 3D coordinates into 3D array of specific size

2 visualizzazioni (ultimi 30 giorni)
Hi,
I have a 3D array (sz: 400x400x160) with binary mask of a bone inside it. Additionally I have a transformation matrix obtained using affine3d fnc. I want to rotate the binary mask without rotating the array itself.
At first I tried to use imwarp to apply the rotation:
A = data.subMask{3,9};
TM = data.regOutput.LeftFem.Transform{8};
Arot = imwarp(A,TM);
whos A TM Arot;
Name Size Bytes Class Attributes
A 400x400x160 25600000 logical
Arot 405x402x170 27677700 logical
TM 1x1 136 affine3d
Arot has changed it's size, which is not what I require. I need the array to remain the same dimensions (in order to be able to to show it's rotated patch aside other bone masks of size 400x400x160). Therefore I figured that If I get the 3D coordinates of the locations of the points in a pointCloud of the same boneMask, then rotate those 3D coordinates
coords = data.bonePtCld{3,9}.Location;
coordsRot = transformPointsForward(TM, coords);
whos coords coordsRot;
Name Size Bytes Class Attributes
coords 65966x3 1583184 double
coordsRot 65966x3 1583184 double
Now getting to the problem I encountered. I don't know how to interpolate these 3D points into an array of the required size (400x400x160). If I understood correctly from the documentation, it has to be done using a combination of meshgrid and interp3 functions, but I have yet not succeeded. This is what I tried:
[X Y Z] = meshgrid(0:399,0:399, 0:159);
XI = [X(:), Y(:), Z(:)];
for cc = length(coordsRot)
V = interp3(X, Y, Z, XI, coordsRot(cc,1), coordsRot(cc,2), coordsRot(cc,3));
end
Error using griddedInterpolant
The number of input coordinate arrays does
not equal the number of dimensions (NDIMS)
of these arrays.
Error in interp3 (line 143)
F = griddedInterpolant(X, Y, Z, V, method,extrap);
I also tried:
V = interp3(X, Y, Z, XI, coordsRot(:,1), coordsRot(:,2), coordsRot(:,3));
but got the same error.
Any help would be greatly appreciated!
Thanks!
Andre

Risposte (0)

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by