How does the voxels in a 3D image relate to the coordinate system used in volshow and orthosliceViewer?
6 次查看(过去 30 天)
显示 更早的评论
Could someone please explain how the voxels in a 3D image in Matlab relate to a normal (i.e. positive) coordinate system? I assumed that the 1st, 2nd and 3rd indices of the image matrix corresponded to x-, y- and z-coordinates respectively, but that is clearly not the case. The following example illustrates the issue I am having...
I have a 3D model of a right hand which is defined by the variables 'vertices' and 'faces':
p=patch('Vertices',vertices,'Faces',faces);
p.FaceColor = [0 1 0];
xlabel('X'); ylabel('Y'); zlabel('Z')
![MeshHand.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/269005/MeshHand.png)
With the following code I can create a 3D image of the hand simply by counting the number of vertices within a voxel:
xedges = 0:0.5:30;
yedges = 0:0.5:30;
zedges = 0:0.5:15;
Img = zeros(numel(xedges)-1, numel(yedges)-1, numel(zedges)-1);
for iZ = 1:numel(zedges)-1
bZ = vertices(:,3)>=zedges(iZ) & vertices(:,3)<zedges(iZ+1);
Img(:,:,iZ) = histcounts2(vertices(bZ,1),vertices(bZ,2),xedges,yedges);
end
When I plot this image with volshow I get a left hand!
volshow(double(Img>0))
![VolumeHand.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/269006/VolumeHand.png)
When I plot the image with orthosliceViewer the x and y dimensions are swapped:
![OrthoHand.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/269007/OrthoHand.png)
I cannot find any documentation on if the orthosliceViewer coordinate system is positive or negative, but if it is positive I am looking at a left hand again.
Is the solution simply to do permute(Img, [2 1 3])?
0 个评论
回答(1 个)
Ralf U.
2020-3-10
The coordinates are both right hand systems, but facing in other directions.
In a matrix, as your voxel volume, the origin is at the top left (spatial coordinate system). See Coordinate Systems.
In volshow, the origin is the typical mathematical coordinate system: x-axis right, y-axis up, z-axis towards you.
The relation is (x,y,z) = (-y,x,-z), so the correct solution is to also flip the x- and z-axis:
img = permute(img, [2 1 3]);
img = flip(img, 2); % former x-axis
img = flip(img, 3); % z-axis
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!