after extracting the connected components from an image and find the start and end points of each connected components that are in order I want to merge these connected components if they are overlapped so I need to find the start and end points
for examples a is the extreme points of each connected components
a = [ 1.5000 95.5000; 82.5000 150.5000; 141.5000 197.5000; 191.5000 357.5000; 400.5000 438.5000; 415.5000 481.5000; 519.5000 667.5000];
and I need the result to be
1.5000 357.5000 400.5000 481.5000 519.5000 667.5000
b=arrayfun(@(x) a(x,1):a(x,2),1:size(a,1),'un',0); k=1; while k<numel(b) c=b(k+1:end); idx=cellfun(@(x) any(ismember(x,b{k})),c); if any(idx) b(logical([ zeros(1,numel(b)-numel(idx)-1) 1 idx]))=[]; else b(logical([ zeros(1,numel(b)-numel(idx)) idx]))=[]; end k=k+1; end out=cell2mat(cellfun(@(x) [x(1) x(end)],b','un',0))
but I got this overlapped points
141.5000 197.5000
191.5000 357.5000
519.5000 667.5000
how can I fix it ?
thanks