def compute_score(segment, ebsd):
    """
    Compute Dice measure (or f1 score) on the segmented pixels

    :param segment: segmented electron image (uint8 format)
    :param ebsd:  speckle segmented out of the ebsd file (uint8 format)
    :return: Dice score
    """

    segmented_ebsd = ebsd >= 128
    segmented_segment = segment >= 128

    co_segmented = (segmented_ebsd & segmented_segment).sum()
    normalization = segmented_segment.sum() + segmented_ebsd.sum()

    score = 2 * co_segmented / normalization

    return score