def calIOU(binary_GT, binary_R): row, col = binary_GT.shape # 矩阵的行与列 TP,FP,FN = 0,0,0 for i in range(row): for j in range(col): if binary_GT[i][j] == 255 and binary_R[i][j] == 255: TP = 1 if binary_GT[i][j] == 255 and binary_R[i][j] == 0: FP = 1 if binary_GT[i][j] == 0 and binary_R[i][j] == 255: FN = 1 IOU = TP / (TP FP FN)