使用python计算两张图片的dice指数

使用python计算两张图片的dice指数

import cv2
import os
import numpy as np
def dice(x,y):
    
    s2 = cv2.imread(x, 0)# 模板
    row, col = s2.shape[0], s2.shape[1]
    d = []
    s1 = cv2.imread(y, 0)
    s = []
    for r in range(row - 10):
        for c in range(col - 10):
            if s1[r][c] == s2[r][c]: # 计算图像像素交集
                s.append(s1[r][c])
#                 print(s1[r][c])
    m1 = np.linalg.norm(s)
    m2 = np.linalg.norm(s1.flatten()) + np.linalg.norm(s2.flatten())
    d.append(2*m1/m2)
    return d
dice("C:\\Users\\Administrator\\Desktop\\T063935.jpg","C:\\Users\\Administrator\\Desktop\\T063934.jpg")

你可能感兴趣的:(使用python计算两张图片的dice指数)