MATLAB: How to unify curve segments in binary images

curve segmentsimage processingMATLABunify

I'd like to unite the curve segments of the binary image below to one single curve. Does anyone know, how to do this?

Best Answer

I = imread('img_curvesegments.jpg') ;
I1 = imbinarize(I);
[y,x] = find(~I1) ;
[z, a, b, alpha] = fitellipse([x y])
imshow(I1)
hold on
plot(x,y,'.r')
plotellipse(z,a,b,alpha)
Download the required functions from file exchange: https://in.mathworks.com/matlabcentral/fileexchange/15125-fitellipse-m