Esempio n. 1
0
def draw_qualitative() : 
    print "drawing qualitative"
    # draw 300, 600, full mean accuracy for both winder and uwiii

    for p in itertools.product(dataset_list,stripsize_list) : 
        print p

    # populate a hash keyed by dataset_algo, e.g., "winder_rast"
    # values will be arrays of npdata (300,600,fullpage) of the metrics 
    qual_data = {}
    for dataset in dataset_list : 
        for algo in algorithm_list : 
            key = "{0}_{1}".format( dataset, algo )
            qual_data[key] = []
            for stripsize in stripsize_list : 
                data_list = datfile.loaddb( dataset=dataset, stripsize=stripsize, algorithm=algo )
                # join all the metrics together
                all_metric = np.concatenate( [ d["metrics"] for d in data_list ] )
                # array, in order 300,600,1200
                # this is the data we will plot
                qual_data[key].append( all_metric )
                # break the reference
                all_metric = None

    fig = Figure()
    ax = fig.add_subplot(111)
    ax.grid()
    ax.set_ylim(0,1.0)
    line_fmt_list = ( '-', '--', '-.', ':' )
    line_fmt = iter(line_fmt_list)
    key_list = sorted(qual_data.keys()) 
    for key in key_list : 
        # plot the 300,600,fullpage
        print key
        metric_means = [np.mean(m) for m in qual_data[key]]
        metric_errs = [np.std(m) for m in qual_data[key]]
        print metric_means, metric_errs
#        ax.errorbar( (0,1,2), metric_means, yerr=metric_errs, fmt="o-" )
        ax.plot( metric_means, "kx"+line_fmt.next(), linewidth=2.0 )

    # draw legend in upper left
    ax.legend(key_list,loc=2)
    ax.set_xticklabels( ("300","","600","","full"))
    ax.set_xlabel( "Image Size" )
    ax.set_ylabel( "Match Metric" )

    outfilename = "all_qual.png"
    canvas = FigureCanvasAgg(fig)
    canvas.print_figure(outfilename)
    print "wrote", outfilename
Esempio n. 2
0
def graph_all_results() : 
    result_list = [ 
        { "dir" :   "winder_fullpage_rast",
          "outfile": "winder_fullpage_rast.png",
          "title" : "Winder Full Page RAST" },
        { "dir" :   "winder_fullpage_vor",
          "outfile": "winder_fullpage_vor.png",
          "title" : "Winder Full Page Voronoi" },

        { "dir" :   "300_winder_rast",
          "outfile": "300_winder_rast.png",
          "title" : "Winder 300 RAST" },

        { "dir" :   "300_winder_rast",
          "outfile": "300_winder_rast.png",
          "title" : "Winder 300 RAST" },
        { "dir" :   "300_winder_vor",
          "outfile": "300_winder_vor.png",
          "title" : "Winder 300 Voronoi" },

        { "dir" :   "300_vor",
          "outfile": "300_uwiii_vor.png",
          "title" : "UW-III 300 Voronoi" },
        { "dir" :   "300_rast",
          "outfile": "300_uwiii_rast.png",
          "title" : "UW-III 300 RAST" },
    ]

    # add each image class of Amy Winder's data set
    for c in winder_imgclass_list : 
        result_list.append({"dir": os.path.join("winder_fullpage_rast", c),
                            "outfile" : "winder_"+c+"_rast.png",
                            "title": "Winder " + c.replace("_"," " ) + " RAST"})
    for c in winder_imgclass_list : 
        result_list.append({"dir": os.path.join("winder_fullpage_vor", c),
                            "outfile" : "winder_"+c+"_vor.png",
                            "title": "Winder " + c.replace("_"," " ) + " Voronoi"})

    for result in result_list : 
        print "result=",result
        if not os.path.exists( result["outfile"] ) :
            print result["dir"]
            ndata = load_all_datfiles(result["dir"]) 
            np.save('metrics.npy',ndata)
            make_histogram( ndata, result["outfile"], title=result["title"] )

    # UW-III Full Page Histograms
    uwiii_fullpage_rast = datfile.loaddb( dataset="uwiii", stripsize="fullpage", algorithm="rast" )
    ndata = np.concatenate( [ d["metrics"] for d in uwiii_fullpage_rast ] )
    make_histogram( ndata, "uwiii_fullpage_rast.png", title="UW-III Full Page RAST" )
    nz = np.where( ndata != 0 )
    make_histogram( ndata[nz], "uwiii_fullpage_rast_nonzero.png", 
                        title="UW-III Full Page RAST (No Zeros)" )

    # UW-III Full Page with Zeros removed (shows better histogram detail)
    uwiii_fullpage_vor = datfile.loaddb( dataset="uwiii", stripsize="fullpage", algorithm="vor" )
    ndata = np.concatenate( [ d["metrics"] for d in uwiii_fullpage_vor ] )
    make_histogram( ndata, "uwiii_fullpage_vor.png", title="UW-III Full Page Voronoi" )
    nz = np.where( ndata != 0 )
    make_histogram( ndata[nz], "uwiii_fullpage_vor_nonzero.png", 
                        title="UW-III Full Page Voronoi (No Zeros)" )

    uwiii_300_rast = datfile.loaddb( dataset="uwiii", stripsize="300", algorithm="rast" )
    ndata = np.concatenate( [ d["metrics"] for d in uwiii_300_rast ] )
    make_histogram( ndata, "uwiii_300_rast.png", title="UW-III 300 RAST" )
    nz = np.where( ndata != 0 )
    make_histogram( ndata[nz], "uwiii_300_rast_nonzero.png", 
                            title="UW-III 300 RAST (No Zeros)" )
    uwiii_300_vor = datfile.loaddb( dataset="uwiii", stripsize="300", algorithm="vor" )
    ndata = np.concatenate( [ d["metrics"] for d in uwiii_300_vor ] )
    make_histogram( ndata, "uwiii_300_vor.png", title="UW-III 300 Voronoi" )
    nz = np.where( ndata != 0 )
    make_histogram( ndata[nz], "uwiii_300_vor_nonzero.png", 
                        title="UW-III 300 Voronoi (No Zeros)" )

    # draw a few single page graphs
    draw_single_pages()

    # draw a graph of each class of the winder dataset
    draw_winder_class_results()

    # draw ALL THE RESULTS on one graph
    draw_qualitative()

    draw_class_results_barchart("uwiii","UW-III")
    draw_class_results_barchart("winder","Winder")

    draw_four_up_histogram("winder")
    draw_four_up_histogram("uwiii")
Esempio n. 3
0
def draw_class_results_barchart(dataset,dataset_title) : 
    outfilename = "{0}_class_rast_vs_vor.png".format(dataset)

    if dataset=="uwiii" : 
        imgclass_list = uwiii_imgclass_list
        label_list = uwiii_imgclass_list
    elif dataset=="winder" :
        imgclass_list = winder_imgclass_list
        label_list = winder_imgclass_list_shorthand
    else:
        assert 0, dataset

    fig = Figure()
    ax = fig.add_subplot(111)
    fig.suptitle( "{0} RAST vs Voronoi Class Performance".format(dataset_title) )

    ind = np.arange(len(imgclass_list),dtype="float")
    width = .20

    means_hash = { "rast_fullpage": [], 
                   "vor_fullpage": [] ,
                   "rast_300": [], 
                   "vor_300": [] 
                 }

    for algo in algorithm_list : 
        for imgclass in imgclass_list : 
            for stripsize in ("300","fullpage") : 
                data_list = datfile.loaddb( dataset=dataset, stripsize=stripsize, 
                                algorithm=algo, imgclass=imgclass )
                all_metric = np.concatenate( [ d["metrics"] for d in data_list ] )

                key = "{0}_{1}".format( algo, stripsize )

                means_hash[key].append( np.mean(all_metric) )

                # break the ref
                all_metric = None
        
    print means_hash 

    ax.set_ylim(0,1.0)
    ax.set_ylabel( "Match Metric" )
    ax.set_xlabel( "Image Class" )

    rects = []
#    citer = iter( ("r","g","y","b"))
    # copied the hatch list from http://matplotlib.org/api/axes_api.html
    hiter = iter( ("/" , "\\" , "x" , "o" , "O" , "." , "*") )
    for key in ("rast_fullpage","vor_fullpage","rast_300","vor_300") :     
        print ind
        r = ax.bar( ind, means_hash[key], width, hatch=hiter.next(), color="w" )
#        r = ax.bar( ind, means_hash[key], width, color=citer.next() )
        ind += 0.2
        rects.append( r ) 
        # break the ref
        r = None

#    rects2 = ax.bar( ind, means_hash["vor_fullpage"], width, color='y' )
#    ind += width
#    rects3 = ax.bar( ind, means_hash["rast_300"], width, color='r' )
#    ind += width
#    rects4 = ax.bar( ind, means_hash["vor_300"], width, color='y' )

    # http://stackoverflow.com/questions/13515471/matplotlib-how-to-prevent-x-axis-labels-from-overlapping-each-other
    ax.set_xticks( range(len(imgclass_list)) )
    tlist = ax.set_xticklabels( label_list, ha='left' )
    for t in tlist :
#        t.set_horizontalalignment('center')
#        t.set_bbox(dict(facecolor="white", alpha=0.5))
#        print t.get_position()
        pass

#    ax.set( xticks=range(len(imgclass_list)), xticklabels=label_list )
#    ax.set_xticklabels( imgclass_list )

    leg = ax.legend( rects, ('RAST full','Vor full', 'RAST 300', 'Vor 300'), 
                    frameon=False )
    print leg, ax.get_legend()

    canvas = FigureCanvasAgg(fig)
    canvas.print_figure(outfilename)
    print "wrote", outfilename

    stretch_width(outfilename)
#    # load the image we just wrote, resize 50% wider
#    img = Image.open(outfilename)
#    img.load()
#    print img.size
#    img.resize( (img.size[0]+img.size[0]/2,img.size[1]), Image.BILINEAR ).save(outfilename)
##    print img.size
##    img.save(outfilename)
    print "wrote", outfilename