% The following assumes you have read the help sections on voronoi and % delaunay. Start with vectors x,y giving the contour a 2D shape: get % their full voronoi diagram of edges vx(1,i),vy(1,i) to vx(2,i), vy(2,i). [vx,vy] = voronoi(x,y); % To cull the voronoi edges which are partly outside the curve, % first find all Delaunay triangles, making their vertices increase: TRI = sort(delaunay(x,y)')'; % The signed areas of the triangles, pos if inside, negative if outside: s = [(-(x(TRI(:,1))-x(TRI(:,3))).*(y(TRI(:,2))-y(TRI(:,3))) + ... (x(TRI(:,2))-x(TRI(:,3))).*(y(TRI(:,1))-y(TRI(:,3)))) -1]; % Find the triangles containing the ends of each voronoi segment and % determine those segments for which both ends are inside the contour. t1 = tsearch(x,y,TRI,vx,vy); t1(isnan(t1))=size(s,2); ind = s(t1(1,:))>0 & s(t1(2,:))>0; % The medial axis is drawn by: plot(vx(:,ind),vy(:,ind),'-k')