def process_image()

in mapillary_vistas/evaluation/evaluation.py [0:0]


def process_image(labels, files):
    """
    Calculate all metrics for the given files, using the given labels.
    """

    confusion_matrix = None
    instance_specific_instance_information = None
    instance_specific_pixel_information = {}
    try:
        ground_truth_path = files['ground_truth']
        prediction_path = files['prediction']
        instance_predictions_path = files['instances']

        ground_truth_image = Image.open(ground_truth_path)
        ground_truth_array = np.array(ground_truth_image)
        ground_truth_instance_array = None
        if ground_truth_array.dtype != np.uint8:
            # split labels and store separately
            ground_truth_label_array = np.array(ground_truth_array / 256, dtype=np.uint8)
            ground_truth_instance_array = ground_truth_array
        else:
            ground_truth_label_array = ground_truth_array
            warn_text = """You specified 8bit label files as ground truth.
It is not possible to derive instance specific metrics from these images.
Specify the 16bit instance files."""
            if instance_predictions_path is not None:
                raise RuntimeError(warn_text)
            else:
                warnings.warn(warn_text, RuntimeWarning)

        if prediction_path is not None:
            prediction_image = Image.open(prediction_path)
            prediction_array = np.array(prediction_image)
            assert prediction_array.dtype == np.uint8

            confusion_matrix = calculate_confusion_matrix_from_arrays(
                prediction_array,
                ground_truth_label_array,
                len(labels)
            )

            if ground_truth_instance_array is not None:
                instance_specific_pixel_information = calculate_instance_specific_pixel_accuracy_from_arrays(
                    prediction_array,
                    ground_truth_instance_array,
                    labels
                )

        if instance_predictions_path is not None and ground_truth_instance_array is not None:
            instance_specific_instance_information = calculate_instance_specific_instance_accuracy_from_arrays(
                instance_predictions_path,
                ground_truth_instance_array,
                labels
            )
    except:
        traceback.print_exc()
        print("problem in processing {}, {}".format(prediction_path, ground_truth_path))
        raise

    return (confusion_matrix, instance_specific_pixel_information, instance_specific_instance_information)