import torch


def calculate_illuminance_invariance(target_rgb_image, projected_rgb_image):
    """
    Calculates the illuminance invariance scores between target and projected rgb images.
    We retrieve the mean illuminance of all non-black pixels and compare them

    :param target_rgb_image:
    :param projected_rgb_image:
    :return: target_illuminance, proj_illuminance, illuminance_difference
    """
    gt_mean_illuminance = target_rgb_image[target_rgb_image != 0].mean()
    proj_mean_illuminance = projected_rgb_image[projected_rgb_image != 0].mean()
    illuminance_difference = torch.abs(gt_mean_illuminance - proj_mean_illuminance)

    return gt_mean_illuminance.cpu().numpy().item(),\
           proj_mean_illuminance.cpu().numpy().item(),\
           illuminance_difference.cpu().numpy().item()