MATLAB: How to find 26 neighbors of point with coordinates of (i,j,k) digital image processingimage analysisimage segmentationmatrix arraymatrix manipulation I have a stack of images in a 3D matrix. How can I find 26 neighbors of a specific voxel with coordinates of (i,j,k) in Matlab? Your help is appreciated. Best Answer To get a 27 element cube around the voxel, do this:neighbors = matrix3d(i-1:i+1, j-1:j+1, k-1:k+1);Then turn it into a column vector like this:neighbors = neighbors(:);Then delete the i,j,k element to get the final 26 neighbors, by deleting the middle element of the column vector:neighbors[14] = []; % Now we're done! We have a list of 26 voxel values. Related SolutionsMATLAB: What is matrix3d matrix3D is the variable 3D matrix you have. You have not defined it.matrix3d = rand(10,10,10) ;% say i = 1, j = 1i = 2 ; j=3, k = 2neighbors = matrix3d(i-1:i+1, j-1:j+1, k-1:k+1) MATLAB: How to find neighbor voxels of a given voxel You may use knnsearch to get the nearest neighbors. Read about knnsearch Related QuestionHow can k set the initial variable of the vectorAre the inequality expressions not evaluated correctlyHow to vectorize this loop? Subsequental subtraction of columns within a matrixHow can I output different array size than input by GPU arrayfun
Best Answer