def gene_change_map(image_diff, feature_vectors, cluster_center):
    """
    Generate change map.
    :param image_diff: the difference image
    :param feature_vectors: feature vectors
    :param cluster_center: cluster centers generated by k-means algorithm
    :return: change map
    """
    img_height, img_width = image_diff.shape
    f_dis = np.linalg.norm(feature_vectors - cluster_center[:, 0].reshape(-1, 1), axis=0,
                           keepdims=True)  # the dis between the first cluster center and every pixel

    s_dis = np.linalg.norm(feature_vectors - cluster_center[:, 1].reshape(-1, 1), axis=0,
                           keepdims=True)  # the dis between the second cluster center and every pixel

    f_mask = f_dis < s_dis  # the pixel is closer to the first cluster center
    f_mask = f_mask.reshape([img_height, img_width])

    f_mean = image_diff[f_mask].mean()  # average of first class's pixel
    s_mean = image_diff[f_mask == False].mean()  # average of second class's pixel

    # the cluster whose pixels have higher average value in the difference image is assigned as the wc class
    if f_mean > s_mean:
        image_diff[f_mask] = 255
        image_diff[f_mask == False] = 0
    else:
        image_diff[f_mask] = 0
        image_diff[f_mask == False] = 255
    return image_diff

    Generate change map.
    :param image_diff: the difference image
    :param feature_vectors: feature vectors
    :param cluster_center: cluster centers generated by k-means algorithm
    :return: change map
    
Methodology/Traditional/PCAKmeans/algorithm.py