rrcmetrics.py 文件源码

python
阅读 39 收藏 0 点赞 0 评论 0

项目:pe 作者: anguelos 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号