def compute_majority_vote_mean_seg(seg_data_set, threshold=0.5, weights=None, type='binary'):
    """
    Compute the mean segmentation image for a given segmentation data set seg_data_set by Majority Vote

    :param seg_data_set: data set of segmentation slices (2D)

    :param threshold: threshold to select the value of a pixel
    :return:
    """
    if weights is None:
        average = np.sum(seg_data_set, axis=0) / float(len(seg_data_set))
    else:
        average = np.sum(np.einsum('ijk,i->ijk', seg_data_set, weights), axis=0)
    # average[average > 1] = 1
    if type == 'binary':
        return (threshold >= average).astype(int)
    else:
        return average.astype(float)


# ------------------------------------------------------------------------------------------------------------------
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/scripts/msct_gmseg_utils.py/compute_majority_vote_mean_seg/swapped operands of `>=`