How does the voxels in a 3D image relate to the coordinate system used in volshow and orthosliceViewer?
8 views (last 30 days)
Show older comments
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')

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))

When I plot the image with orthosliceViewer the x and y dimensions are swapped:

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 Comments
Answers (1)
Ralf U.
on 10 Mar 2020
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 Comments
See Also
Categories
Find more on Basic Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!