Replace unwanted voxels with nearest neighbor labeled values

1 回表示 (過去 30 日間)
banikr
banikr 2020 年 5 月 3 日
コメント済み: darova 2020 年 5 月 15 日
Hello Matlab experts,
I am trying to remove unwanted electrode voxels from 3D labeled images by replacing the electrodes with nearest skin, bone or other labeled tissue voxels. I experimented with the function here: https://www.mathworks.com/matlabcentral/fileexchange/24723-nearest_neighbour_3d
But that didn't generate the result I expected. The function takes given points(electrodes) and their minimum distant nearest candidate points(other tissue voxels). It considers Euclidean distance.
%sz is the size of the 3D label=> lab
[cxx, cyy, czz] = ind2sub(sz, find(lab==10|lab==4)); % candidate points from either skin(10) or bones(4) or other tissues
[gxx, gyy, gzz] = ind2sub(sz, find(lab==20)); % given poinst from electrodes(20)
[nxx, nyy, nzz] = ind2sub(sz, compute_nearest_neighbour([cxx,cyy,czz], [gxx,gyy,gzz])); % nearest points
lab(gxx,gyy,gzz) = lab(nxx,nyy,nzz);
Any other ways?
Thanks in advance.

採用された回答

darova
darova 2020 年 5 月 15 日
Solution
lab = lab_superior; % the data shared
elec = zeros(size(lab));
elec(lab==20)=1; % select electrodes
BB = lab;
BB(BB==20) = 0; % remove electrodes
nb = unique(BB); % unique regions
nb(nb==0) = []; % remove '0' from list of regions
[EE,ne] = bwlabeln(elec);
II = BB*0;
for i = 1:ne
E1 = EE == i;
E2 = imdilate(E1,strel('sphere', 4));
for j = nb(:)'
B1 = BB == j; % select one region
tmp = B1 & E2; % compare electrode and region
if any(tmp(:)) % if region and electrode are close
II = II+j*E1;
break
end
end
end
A = II + BB;
Original After processing

その他の回答 (1 件)

Image Analyst
Image Analyst 2020 年 5 月 3 日
The position of x and y are swapped, which makes a difference if the volume is not equal lengths in the x and y direction. Remember ind2sub() returns (row, column) which is NOT (x, y) -- it's (y, x).
  36 件のコメント
banikr
banikr 2020 年 5 月 15 日
@darova,
I think it worked.
The electrode voxels were replaced with mostly skin(brown) voxels.
Thanks for the support!
darova
darova 2020 年 5 月 15 日
Can you accept the answer?

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by