当前位置: 首页>>代码示例>>Python>>正文


Python COCO.decodeMask方法代码示例

本文整理汇总了Python中pycocotools.coco.COCO.decodeMask方法的典型用法代码示例。如果您正苦于以下问题:Python COCO.decodeMask方法的具体用法?Python COCO.decodeMask怎么用?Python COCO.decodeMask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycocotools.coco.COCO的用法示例。


在下文中一共展示了COCO.decodeMask方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from pycocotools.coco import COCO [as 别名]
# 或者: from pycocotools.coco.COCO import decodeMask [as 别名]

#.........这里部分代码省略.........
        self.assign_value(factors)
        print('salient value computed.!')
        
        
        
            
    
    def factored_size(self,ann):
        im_sz = {}        
        for item in ann:
            sz = round(item['area']/self.size_norm,2)
            im_sz[item['id']] = sz
        return im_sz 
    
    def factored_loc(self,ann):
        im_loc = {}
        for item in ann:
            loc = item['bbox']
            loc = round(loc[0]+loc[2]/2)+640*(round(loc[1]+loc[3]/2)-1)
            loc = loc/self.size_norm
            im_loc[item['id']] = loc
        return im_loc
    
    def factored_den(self,ann):
        im_den = {}
        distmat = []
        for item in ann:
            coord = item['bbox']
            c_coord = [coord[0]+coord[2]/2,coord[1]+coord[3]/2]
            distmat.append(c_coord)
        for item1,item2 in zip(distmat,ann):
            xa = [item1]
            den = sp.distance.cdist(xa,distmat)
            den = den.mean()
            im_den[item2['id']] = den
        return im_den    
    def factored_dtc(self,ann):
        im_dtc = {}
        c = [320,240]
        for item in ann:
            coord = item['bbox']
            c_coord = [coord[0]+coord[2]/2,coord[1]+coord[3]/2]
            d = sp.distance.pdist([c,c_coord])
            d = d[0]
            d = d*2/self.loc_norm
            im_dtc[item['id']] = d
        return im_dtc
        
    def save_saldict_tomatfile(self,sal_dict_to_save,name):
        datalist = []
        for item in sal_dict_to_save.keys():
            im_sal = sal_dict_to_save[item]
            saveitem = []
            for im_item in im_sal.keys():
                saveitem.append([im_item,im_sal[im_item]])
            datalist.append(saveitem)        
        sio.savemat(name,{'sal_data':datalist})
        
        
        
    def plot_saliencymap(self,saliency_dict,image_id):
        im_id_indataset = self.SALICON['SALICON_id'][image_id]
        ann_IDlist = self.Ins_coco.getAnnIds(im_id_indataset)
        ann_list = self.Ins_coco.loadAnns(ann_IDlist)
        
        sal_dict = saliency_dict[image_id]
        maxv = max(sal_dict.values())
        
        blankim = np.zeros((480,640,3),np.uint8)
        plt.imshow(blankim)
        ax = plt.gca()
        polygons = []
        color = []
        for item in ann_list:
            c =sal_dict[item['id']]/(maxv)
            c = [c,c,c]
            if type(item['segmentation']) == list:
                # polygon
                for seg in item['segmentation']:
                    poly = np.array(seg).reshape((len(seg)/2, 2))
                    polygons.append(Polygon(poly, True,alpha=0.4))
                    color.append(c)
            else:
                # mask
                mask = self.Ins_coco.decodeMask(item['segmentation'])
                img = np.ones( (mask.shape[0], mask.shape[1], 3) )
                color_mask = c
                #         if ann['iscrowd'] == 1:
                #             color_mask = np.array([2.0,166.0,101.0])/255
                #         if ann['iscrowd'] == 0:             
                for i in range(3): 
                    img[:,:,i] = color_mask[i]
                ax.imshow(np.dstack( (img, mask*0.5) ))
            p = PatchCollection(polygons, facecolors=color, edgecolors=(0,0,0,1), linewidths=0.5, alpha=0.9)
            ax.add_collection(p)


        

            
开发者ID:Yanakz,项目名称:Caption,代码行数:99,代码来源:CaptionSaliency.py


注:本文中的pycocotools.coco.COCO.decodeMask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。