Neighbour voxels of a list of voxels

조회 수: 14 (최근 30일)
Razakamandimby Tiana
Razakamandimby Tiana 2021년 5월 18일
댓글: Razakamandimby Tiana 2021년 5월 20일
I am trying to find all the neighbours voxels of a list of voxels. I already used a function findNeigbours that I downloaded (https://www.mathworks.com/matlabcentral/fileexchange/68549-findneighbours) but it only works for a single voxel and I need to apply the function to a vector.
In my code, I used for loop but it's takiing too long time since the vector list is large. Any solution?
These are the lines I used in my code:
for i = 1:size(vector,1)
surrounding{i} = findNeighbours(vector(i), [[pxl_x, pxl_y, pxl_z], 26)
end
  댓글 수: 2
KSSV
KSSV 2021년 5월 18일
You can use inbuilt functions to achieve this fast. Show us how your voxels are.
Razakamandimby Tiana
Razakamandimby Tiana 2021년 5월 19일
The vector is in the excel file and the size of array in 3dimension is 60 x 60 x 67

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2021년 5월 18일
편집: Matt J 2021년 5월 18일
If you have lists of xCoordinates, yCoordinates, and zCoordinates of the voxels, you may simply do,
[dx,dy,dz]=ndgrid([-1,0,1]);
dx=dx(:).'; dy=dy(:).'; dz=dz(:).';
X=xCoordinates(:)+dx; Y=yCoordinates(:)+dy; Z=zCoordinates(:)+dz; %neighbor coordinates
and if the voxel grid has dimensions MxNxP, you might then discard out-of-bounds voxel coordinates by doing,
X(X<1 | X>M)=nan;
Y(Y<1 | Y>N)=nan;
Z(Z<1 | Z>P)=nan;
  댓글 수: 2
Razakamandimby Tiana
Razakamandimby Tiana 2021년 5월 19일
Thanks but I have the voxels indexes not their coordinates. But I will try to get the coordinates from the inndexes and see if I get results faster
Matt J
Matt J 2021년 5월 19일
Just use ind2sub().

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Razakamandimby Tiana
Razakamandimby Tiana 2021년 5월 20일
I could solve this issue. The following code gives all the neighbour voxels (connectivity 26 in 3D) of each voxels in the vector list.
vector % The attached excel file
matrix = [121 121 117];
conn = 26;
neighbor = arrayfun(@(vector) findNeighbours(vector,matrix,conn), vector,'UniformOutput', false)
  댓글 수: 2
Matt J
Matt J 2021년 5월 20일
But you are using arrayfun. I don't think you could be getting faster speed from arrayfun than with a loop.
Razakamandimby Tiana
Razakamandimby Tiana 2021년 5월 20일
you are right, finding the coordinates was faster. Thank you

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile 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!

Translated by