예제 #1
0
 def VizGrayFlows(self, key, flowList):
     imGrayList = self.flowVizsGray[key + 'Vizg']
     assert len(flowList) == len(imGrayList)
     if (len(flowList) == 0):
         print('WARRING VizGrayFlows: Not find any flowfiles')
     for flowName, imGrayName in zip(flowList, imGrayList):
         flow = read_gen(flowName)
         flow_g = abs_flow(flow)
         imsave(imGrayName, flow_g / np.max(flow_g))
# -*- coding: utf-8 -*-
"""
Created on Tue Dec  4 16:31:24 2018

@author: Administrator
"""
import sys
from os.path import join
from scipy.misc import imsave,imread
from PIL import Image
import numpy as np

sys.path.append("../Server_EasyTest")
from myflowlib import read_gen,abs_flow


path= 'E:\我的文档\任务\配准1\测试图片\展示在文档中的\z3'
name = 'z3res.flo'
save_name ='z3res_gray.jpg'

name = join(path,name)
save_name = join(path,save_name)

res = read_gen(name)
res = abs_flow(res)
imsave(save_name,res/np.max(res))
예제 #3
0
    def SparplotSimple(self, ids, netout_flow, uncertainty_flow,
                       groundtruth_flow):
        gt = groundtruth_flow
        res = abs_flow(uncertainty_flow)
        flow = netout_flow
        assert flow.shape == uncertainty_flow.shape == gt.shape
        best = abs_flow(gt - flow)
        total_steps = self.spar_steps

        aepe0 = EPE(flow, gt)
        print('AEPE:' + str(aepe0))
        totalpixels = int(flow.size / 2)
        remainpixels = np.linspace(totalpixels,
                                   0,
                                   total_steps,
                                   endpoint=False,
                                   dtype='int')
        res_sort = res.flatten()
        best_sort = best.flatten()
        res_sort_index = np.argsort(res_sort)
        best_sort_index = np.argsort(best_sort)

        res_aepe = []
        res_threshold = []
        for p in remainpixels:
            threshold_id = res_sort_index[p - 1]
            threshold = res_sort[threshold_id]
            aepe = EPE_usingmask(flow, gt, res < threshold)
            res_aepe.append(aepe)
            res_threshold.append(threshold)
            print(u"\rFinish" + str(int(len(res_aepe) / total_steps * 50)) +
                  '%',
                  end='')

        best_aepe = []
        best_threshold = []
        for p in remainpixels:
            threshold_id = best_sort_index[p - 1]
            threshold = best_sort[threshold_id]
            aepe = EPE_usingmask(flow, gt, best < threshold)
            best_aepe.append(aepe)
            best_threshold.append(threshold)
            print(u"\rFinish" +
                  str(int(len(best_aepe) / total_steps * 50 + 50)) + '%',
                  end='')

        x = (totalpixels - remainpixels) / totalpixels
        y1 = res_aepe / aepe0
        y2 = best_aepe / aepe0

        plt.plot(x, y1, mec='r', mfc='w', label='Our-Net')
        plt.plot(x, y2, ms=10, label='Oracle')
        plt.legend()  # 让图例生效
        plt.margins(0)
        plt.xlabel('Fraction of Removed Pixels')  #X轴标签
        plt.ylabel('Average EPE (Normalized)')  #Y轴标签
        plt.title('Sparsification Plots')  #标题

        plt.savefig(self.spars['sparPlot'][ids])
        plt.close()
        save_3ziplist(self.spars['sparData'][ids],zip(x,y1,y2),\
                      'aepe0:'+str(aepe0)+'\nRemoved\tPreAEPE\tOraAEPE\n')
        flow_write(self.flows['bestFlow'][ids], gt - flow)
        print('\t\tSave fig, data, imgs and bestFlow!')
        return (remainpixels, res_aepe, best_aepe, aepe0)
    def SparplotSimple(self,ids,netout_flow,uncertainty_flow,groundtruth_flow):

        gt = groundtruth_flow
        res = abs_flow(uncertainty_flow)
        flow = netout_flow
        assert flow.shape==uncertainty_flow.shape==gt.shape
        best = abs_flow(gt - flow)
        total_steps=self.spar_steps

        aepe0=EPE(flow,gt)
        print('AEPE:'+str(aepe0))
        totalpixels=int(flow.size/2)
        remainpixels=np.linspace(totalpixels,0,total_steps,endpoint=False,dtype='int')
        res_sort=res.flatten()
        best_sort=best.flatten()
        res_sort_index=np.argsort(res_sort)
        best_sort_index=np.argsort(best_sort)

        res_aepe=[]
        res_threshold=[]
        for p in remainpixels:
            threshold_id=res_sort_index[p-1]
            threshold=res_sort[threshold_id]
            aepe=EPE_usingmask(flow,gt,res<threshold)
            res_aepe.append(aepe)
            res_threshold.append(threshold)
            print( u"\rFinish"+str(int(len(res_aepe)/total_steps*50))+'%',end = '')

        best_aepe=[]
        best_threshold=[]
        for p in remainpixels:
            threshold_id=best_sort_index[p-1]
            threshold=best_sort[threshold_id]
            aepe=EPE_usingmask(flow,gt,best<threshold)
            best_aepe.append(aepe)
            best_threshold.append(threshold)
            print( u"\rFinish"+str(int(len(best_aepe)/total_steps*50+50))+'%',end = '')

        x=(totalpixels-remainpixels)/totalpixels
        y1=res_aepe/aepe0
        y2=best_aepe/aepe0

        plt.plot(x, y1, mec='r', mfc='w',label='Pred-Merged')
        plt.plot(x, y2, ms=10,label='Oracle')
        plt.legend()  # 让图例生效
        plt.margins(0)
        plt.xlabel('Fraction of Removed Pixels') #X轴标签
        plt.ylabel('Average EPE (Normalized)') #Y轴标签
        plt.title('Sparsification Plots') #标题
        plt.savefig(self.spar_plotlist[ids])
        plt.close() 
        save_3ziplist(self.spar_datalist[ids],zip(x,y1,y2),\
                      'aepe0:'+str(aepe0)+'\nRemoved\tPreAEPE\tOraAEPE\n')
        print('\t\tSave fig, data and imgs !')
        if(self.spar_style=='gray' or self.spar_style=='default'):
            # 1 通道
            absgt=abs_flow(gt)
            imsave(self.spar_grayreslist[ids], res/np.max(res))
            imsave(self.spar_graybestlist[ids], best/np.max(best))
            imsave(self.spar_graygtlist[ids], absgt/np.max(absgt))
        if(self.spar_style=='color' or self.spar_style=='default'):
            # 2通道
            bestflow=Image.fromarray(viz_flow(gt - flow))
            imsave(self.spar_bestlist[ids], bestflow)

        return (remainpixels,res_aepe,best_aepe,aepe0)