示例#1
0
            try:
                seg_lesion_arr[k, h1:h2, w1:w2] = seg_lesion
            except:
                cv2.imshow(
                    'Image',
                    utils.array_to_img(seg_lesion, clip=True).astype('uint8'))

            # lesion
            ########
            seg_lesion_final = np.copy(seg_lesion_arr[k])

            y_true_lesion = np.where(mask == 2, 1., 0.)
            seg_lesion_tmp = np.where(seg_lesion_final == 2, 1., 0.)

            dice_lesion[n] = metric.dc(seg_lesion_tmp, y_true_lesion)
            precision_lesion[n] = metric.sensitivity(seg_lesion_tmp,
                                                     y_true_lesion)
            sensitivity_lesion[n] = metric.precision(seg_lesion_tmp,
                                                     y_true_lesion)

            #############################################################################################
            print('dice=', dice_lesion[n], ' ;  precision=',
                  precision_lesion[n], ' ;  sensitivity=',
                  sensitivity_lesion[n])
            if isDbg:
                if (n % dbg_step == 0) or dice_lesion[n] < min_dice_dbg:
                    # Original Image
                    img = utils.dbg_orig_img(data_path, filename)
                    cv2.waitKey(0)
                    # cv2.destroyAllWindows()

                    # liver
def calculate_metrics(pred, target):
    sens = metric.sensitivity(pred, target)
    spec = metric.specificity(pred, target)
    dice = metric.dc(pred, target)
示例#3
0
    sum_intersection = 0

    j = begin_idx
    for k in range(len(val_img_paths)):
        curr_sum_ground_truth = np.sum(y_true_liver[k])  # float 64
        curr_sum_prediction = np.sum(pred_liver[k])
        curr_sum_intersection = np.sum((pred_liver[k] * y_true_liver[k]))

        # GLOBAL
        sum_ground_truth += curr_sum_ground_truth
        sum_prediction += curr_sum_prediction
        sum_intersection += curr_sum_intersection

        # LOCAL
        dice_liver_local[j] = metric.dc(pred_liver[k], y_true_liver[k])
        precision_liver_local[j] = metric.sensitivity(pred_liver[k],
                                                      y_true_liver[k])
        sensitivity_liver_local[j] = metric.precision(pred_liver[k],
                                                      y_true_liver[k])

        if isDbg:
            # Original
            if (j % dbg_step == 0) or dice_liver_local[j] < min_dice_dbg:
                img = utils.dbg_orig_img(data_path, val_img_paths[k])
                cv2.waitKey(0)
                cv2.destroyAllWindows()
                # Liver - gt
                img = utils.apply_mask(img,
                                       mask_arr[k], (0, 0, 255),
                                       mask_idx=1)
                img = utils.apply_mask(img,
                                       mask_arr[k], (0, 0, 255),