This research data contains the source code of the work "Ellipse fitting by spatial averaging of random ensembles": The method proposes a new ellipse parametrization based on the coordinates of both foci, and the distance between them and each point of the ellipse where the Euclidean norm is applied. Besides, a certain number of subsets are uniformly drawn without replacement from the overall training set which allows estimating the center of the distribution robustly by employing the L1 median of each estimated focus. An additional postprocessing stage is proposed to filter out the effect of bad fits. Several synthetic and real data tests were developed and confirmed the better outcomes. This folder contains the proposed ellipse fitting method as well as two demo codes for both synthetic and real data applications, created in MATLAB: - Run "DemoSAREfit.m" for fitting artificially generated samples. - Run "DemoSAREfit_RealData.m" for fitting samples extracted from real images. The points obtained from real images were extracted by Canny algorithm as described in the paper. Any other method can be used. Please, cite the paper as well as this research data in your work if you use the code. Thanks.