def getPixelIoU(gtImg,submImg):
#TODO TEST THOROUGHLY
def compress(img):
intImg=np.empty(img.shape[:2],dtype='int32')
if len(img.shape)==3:
intImg[:,:]=img[:,:,0]
intImg[:,:]+=(256*img[:,:,1])
intImg[:,:]+=((256**2)*img[:,:,1])
else:
intImg[:,:]=img[:,:]
un=np.unique(intImg)
idx=np.zeros(un.max()+1)
idx[un]=np.arange(un.shape[0],dtype='int32')
return idx[intImg],un.max()+1
if gtImg.shape[:2]!=submImg[:2]:
raise Exception("gtImg and submImg must have the same size")
gt,maxGt=compress(gtImg)
subm,maxSubm=compress(gtImg)
comb=gt*maxSubm+subm
intMatrix=np.bincount(comb.reshape(-1)).reshape([maxSubm,maxGt])
uMatrix=np.zeros(intMatrix.shape)
uMatrix[:,:]+=intMatrix.sum(axis=0)[None,:]
uMatrix[:,:]+=intMatrix.sum(axis=1)[:,None]
uMatrix-=intMatrix
return intMatrix/uMatrix.astype('float64'),intMatrix,uMatrix
评论列表
文章目录