# 1. IoU (Intersection over Union)

``````def calculate_iou(mask_true, mask_pred):
iou = np.sum(intersection) / np.sum(union)
return iou

#e.g.

import cv2
import numpy as np

iou = np.sum(intersection) / np.sum(union)
return iou

#结果0.6660``````

# 2. Dice Coefficient

``````def calculate_dice_coefficient(mask_true, mask_pred):
return dice_coeff

#e.g.

import cv2
import numpy as np

return dice_coeff

#结果是 0.7995
``````

# 3. Pixel Accuracy：

``````def calculate_pixel_accuracy(mask_true, mask_pred):
pixel_accuracy = correct_pixels / total_pixels
return pixel_accuracy

#e.g.

import cv2
import numpy as np

pixel_accuracy = correct_pixels / total_pixels
return pixel_accuracy

#结果是 0.9914``````

# 4. Mean Intersection over Union (mIoU)

``````def calculate_miou(class_iou_list):
return np.mean(class_iou_list)
``````

# 5. Boundary F1-score：

``````def calculate_boundary_f1(mask_true, mask_pred):
# Calculate true positive, false positive, and false negative boundary pixels

precision = true_positive / (true_positive + false_positive)
recall = true_positive / (true_positive + false_negative)
f1_score = 2 * (precision * recall) / (precision + recall)
return f1_score

#e.g.

import cv2
import numpy as np

# Calculate true positive, false positive, and false negative boundary pixels

precision = true_positive / (true_positive + false_positive)
recall = true_positive / (true_positive + false_negative)
f1_score = 2 * (precision * recall) / (precision + recall)
return f1_score

#结果是 0.7995``````