How can I find 26 neighbors of point with coordinates of (i,j,k)?
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Image Analyst
2016년 11월 3일
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.
댓글 수: 7
Image Analyst
2017년 3월 15일
What does "identify" mean to you? You have the indexes of a voxel and its neighbors, so what else do you need to "identify" them?
Sandhiya Prakash
2017년 3월 15일
Yes sir.I am having indexes of voxel and its neighbours,so totally i will have 27 scalar values.Now leaving the actual voxel consider only the neighbours(26) and identify its neighbouring voxel values.How to perform this?
추가 답변 (2개)
Walter Roberson
2017년 3월 15일
편집: Walter Roberson
2017년 3월 15일
function [idx3d, valid, linidx] = neighbour26(i, j, k, Your3DMatrix)
%returns the indices of the 26 3-D neighbors of location i, j, k within Your3DMatrix
%In the first output, indices are returned as a 26 x 3 matrix of row, column, page triples.
%Since on the border areas neighbours might be outside of the matrix, the
%second output is a vector indicating which of the rows are valid.
%The third output is the linear indices -- useful for extracting content
[rows, cols, pages] = size(Your3DMatrix);
[R, C, P] = ndgrid(R-1:R+1, C-1:C+1, P-1:P+1);
idx3d = [R(:), C(:), P(:)];
idx3d(14,:) = []; %remove center
valid = idx(:,1) >= 1 & idx(:,2) >= 1 & idx(:,3) >= 1 & idx(:,1) <= rows & idx(:,2) <= cols & idx(:,3) <= pages;
linidx = nan(size(valid));
linidx(valid) = sub2ind( [rows, cols, pages], idx3(valid,1), idx3d(valid,2), idx3d(valid,3) );
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!