[FieldTrip] extracting a continuous patch on a mesh

Maximilien Chaumon maximilien.chaumon at gmail.com
Mon Apr 23 14:15:19 CEST 2018


Hi all,

So I coded something that could perhaps be useful to others. It grows a
patch around a seed up to a certain distance. See below

function [list] = mesh_patch(mesh,seed,dmax)

% [list] = mesh_patch(mesh,seed,d)
%
% return the list of connected vertices that are at most d mesh.unit away
% from seed.
%
% Maximilien Chaumon 2018

% measure distance to seed
seedpos = mesh.pos(seed,:);
distances = sqrt(sum(bsxfun(@minus,mesh.pos,seedpos).^2,2));

% crawl starting from seed
list = crawl(mesh.tri,distances,dmax,seed);


function final = crawl(tri,d,dmax,vert)

% bookkeeping: the list of vertices
persistent listi
st = dbstack;
level = sum(strcmp({st.name},'crawl'));
if level == 1
    listi = [];
end
%

listi(end+1) = vert; % append this vertex to the list

conn = tri(any(tri==vert,2),:);% connected vertices
conn = unique(conn);
conn(d(conn) > dmax) = []; % remove those that are too far.
conn(ismember(conn,listi)) = [];%keep only vertices that have not been
crawled yet
for i = 1:numel(conn)
    crawl(tri,d,dmax,conn(i));% move to next
end

% bookkeeping: return the list at last
if level == 1
    final = listi; % return list if it's last call
end








Le ven. 13 avr. 2018 à 16:16, Maximilien Chaumon <
maximilien.chaumon at gmail.com> a écrit :

> Dear all,
>
> I'm trying to extract a connected patch of vertices at most say 2 cm away
> from a given seed.
> Is there an easy way to do this in FieldTrip?
>
> Many thanks,
> Max
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20180423/0fbc8010/attachment-0002.html>


More information about the fieldtrip mailing list