import torch


def get_recall(SR, GT, threshold=0.5):
    """

    Args:
        SR: tensor  Segmentation Results
        GT: tensor  Ground Truth
        threshold: the threshold of segmentation

    Returns:
        RC: Recall rate
    """
    # Sensitivity == Recall
    SR = SR > threshold
    GT = GT == torch.max(GT)

    # TP : True Positive
    # FN : False Negative
    TP = (SR == True) & (GT == True)
    FN = (SR == False) & (GT == True)

    RC = float(torch.sum(TP)) / (float(torch.sum(TP + FN)) + 1e-6)

    return RC