function trace_boundary(K,BW) figure; imshow(K,[]); hold on; % Trace the boundaries [B,L,N] = bwboundaries(BW); for k=1:length(B), boundary = B{k}; plot(boundary(:,2),boundary(:,1),'r','LineWidth',1); end