local_max.m
923 Bytes
function Icenter = local_max(Ivote, conn, t)
range1 = -conn(1):conn(1); %create an array of values between -rmax and rmax
range2 = -conn(2):conn(2);
range3 = -conn(3):conn(3);
A = Ivote;
A(A<t) = 0;
ivote = A;
ivote(1:conn(1), :, :) = 0;
ivote(size(Ivote,1) - conn(1):size(Ivote,1), :,:) = 0;
ivote(:, 1:conn(2), :) = 0;
ivote(:, size(Ivote,2) - conn(2):size(Ivote,2),:) = 0;
ivote(:, :, 1:conn(3)) = 0;
ivote(:,:, size(Ivote,3) - conn(3):size(Ivote,2)) = 0;
nl = nnz(ivote);
[fx,fy,fz] = ind2sub(size(ivote), find(ivote>0));
ind_f = find(ivote>0);
Icenter = zeros(size(Ivote));
for li = 1: nl
lfx = fx(li) + range1;
lfy = fy(li) + range2;
lfz = fz(li) + range3;
[cx, cy, cz] = meshgrid(lfx, lfy, lfz);
ind_m = sub2ind(size(Ivote), cx, cy, cz);
lm_Ivote = A(ind_m);
[~, lm_indx] = max(lm_Ivote(:));
if ind_f(li) == ind_m(lm_indx);
Icenter(ind_f(li)) = 255;
end
end