def save_ellipse_features2file(num_regions, features, filename):
    """ Saving the ellipse features (polynomial or standard) to file.

    Parameters
    ----------
    num_regions: dict
        The number of saleint regions for each saliency type
    features: dict
        dictionary with ellipse features for each of the ellipses
    filename: str
        the filename where to save the features

    Returns
    --------
    total_num_regions: int
        the total number of salient regions of saliency types

    NOTES
    -------
    see load_ellipse_features_from_file

    """
    total_num_regions = 0
    f = open(filename, 'w')
    for saltype in num_regions.keys():
        total_num_regions += num_regions[saltype]
    f.write('0 \n')
    f.write(str(total_num_regions))
    f.write('\n')
    for saltype in num_regions.keys():
        features_s = features[saltype]
        for n in range(num_regions[saltype]):
            ellipse_entry = features_s[(n), :]
            for e in ellipse_entry:
                f.write(str(e))
                f.write(' ')
            f.write('\n')
    f.close()
    return total_num_regions
