话不多说,直接上代码
#计算IOU,本代码只适用于单通道图片,单类型分割,且分割出来物体的为白色,背景为黑色。
from PIL import Image
import numpy as np
import glob
def get_array(path):
img = Image.open(path)
img = img.getdata()
img = np.array(img)
return img
def get_IOU(maskpath,resultpath):
mask = get_array(maskpath)
result = get_array(resultpath)
#计算iou
S1 = 0 #交集
S2 = 0 #并集