Exemplo n.º 1
0
def main_2():
    def make_outdir(img_filename):
        # split a png filename into an appropriate output path
        pathname, filename = os.path.split(img_filename)
        #        print pathname
        #        print filename
        dirlist = pathname.split(os.sep)
        #        print dirlist, dirlist[1:]
        outdir = os.path.join(*dirlist[1:])
        #        print outdir
        return outdir

    output_dir_base = "600_winder_{0}".format(runseg.segmentation_algorithm)
    input_dirname = "600_winder"

    img_filelist, xml_filelist = load_image_and_xml_list(input_dirname)

    output_dir_hash = {}
    for i, x in zip(img_filelist, xml_filelist):
        od = make_outdir(i)
        if not od in output_dir_hash:
            output_dir_hash[od] = []

        output_dir_hash[od].append(get_basename(i))

    pklname = "{0}_output_dir_hash.pkl".format(input_dirname)
    f = open(pklname, "wb")
    pickle.dump(output_dir_hash, f)
    f.close()
    #    print "wrote",pklname

    #    fname_fmt = "{0}_{1}".format( input_dirname
    for dirname in output_dir_hash.keys():

        filelist = [
            os.path.join(input_dirname, dirname, f)
            for f in output_dir_hash[dirname]
        ]
        img_filelist = [s + ".png" for s in filelist]
        xml_filelist = [s + ".xml" for s in filelist]

        output_basename = os.path.split(dirname)[-1]
        print img_filelist[0]
        print xml_filelist[0]

        output_dir = os.path.join(output_dir_base, dirname)
        print "outputdir=", output_dir
        print output_basename

        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        runseg.run_file_list(img_filelist, xml_filelist, output_dir,
                             output_basename)

        sys.exit(0)
Exemplo n.º 2
0
def main_2() :
    def make_outdir(img_filename) :
        # split a png filename into an appropriate output path
        pathname,filename = os.path.split(img_filename)
#        print pathname
#        print filename
        dirlist = pathname.split(os.sep)
#        print dirlist, dirlist[1:]
        outdir = os.path.join(*dirlist[1:])
#        print outdir
        return outdir

    output_dir_base = "600_winder_{0}".format(runseg.segmentation_algorithm)
    input_dirname = "600_winder"

    img_filelist, xml_filelist = load_image_and_xml_list( input_dirname )

    output_dir_hash = {}
    for i,x in zip(img_filelist,xml_filelist) : 
        od = make_outdir(i)
        if not od in output_dir_hash : 
            output_dir_hash[od] = []

        output_dir_hash[od].append( get_basename(i) )

    pklname = "{0}_output_dir_hash.pkl".format(input_dirname)
    f = open( pklname, "wb" )
    pickle.dump(output_dir_hash,f)
    f.close()
#    print "wrote",pklname

#    fname_fmt = "{0}_{1}".format( input_dirname
    for dirname in output_dir_hash.keys() : 

        filelist = [ os.path.join(input_dirname,dirname,f) for f in
                            output_dir_hash[dirname] ]
        img_filelist = [ s+".png" for s in filelist ] 
        xml_filelist = [ s+".xml" for s in filelist ] 

        output_basename = os.path.split(dirname)[-1]
        print img_filelist[0]
        print xml_filelist[0]

        output_dir = os.path.join(output_dir_base,dirname)
        print "outputdir=",output_dir
        print output_basename

        if not os.path.exists(output_dir) :
            os.makedirs(output_dir)

        runseg.run_file_list( img_filelist, xml_filelist, output_dir, output_basename )

        sys.exit(0)
Exemplo n.º 3
0
def foo():
    for imgdir in image_dirs:
        print "imgdir=", imgdir
        # did we land in a dir with png files?
        if "png" not in imgdir:
            continue

        print root, rdir, imgdir
        imgpath = os.path.join(root, rdir, "300dpi", imgdir)
        print "imgpath=", imgpath

        # subversion metadata keeps messing with me
        assert ".svn" not in rdir, rdir
        assert ".svn" not in imgdir, imgdir
        assert ".svn" not in root, root
        assert ".svn" not in imgpath, imgpath

        # did we land in a dir with png files?
        pngfiles = glob.glob(os.path.join(imgpath, "*.png"))
        assert len(pngfiles)

        # write the results to a path different than the source
        output_dir = os.path.join(imgpath)
        #            output_dir = output_dir.replace( "300_winder/", "300_winder_vor/" )
        #            output_dir = output_dir.replace( "300_winder/", "300_winder_rast/" )
        #            output_dir = os.path.join( "300_winder_fullpage_vor", output_dir )
        output_dir = os.path.join("300_winder_fullpage_rast", output_dir)

        # destination doesn't exist, make it
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        img_filelist = pngfiles
        xml_filelist = [s.replace(".png", ".xml") for s in img_filelist]

        # output data file name is based on the last dir in the tree
        #            print "imgpath=",imgpath
        output_basename = os.path.split(imgpath)[-1]

        #            print "output_dir=",output_dir
        #            print "output_basename=",output_basename

        runseg.run_file_list(img_filelist, xml_filelist, output_dir,
                             output_basename)
Exemplo n.º 4
0
def foo() :
        for imgdir in image_dirs : 
            print "imgdir=",imgdir
            # did we land in a dir with png files? 
            if "png" not in imgdir : 
                continue

            print root,rdir,imgdir
            imgpath = os.path.join(root,rdir,"300dpi",imgdir)
            print "imgpath=",imgpath

            # subversion metadata keeps messing with me
            assert ".svn" not in rdir, rdir
            assert ".svn" not in imgdir, imgdir
            assert ".svn" not in root, root
            assert ".svn" not in imgpath, imgpath

            # did we land in a dir with png files? 
            pngfiles = glob.glob(os.path.join(imgpath,"*.png"))
            assert len(pngfiles)

            # write the results to a path different than the source
            output_dir = os.path.join(imgpath)
#            output_dir = output_dir.replace( "300_winder/", "300_winder_vor/" )
#            output_dir = output_dir.replace( "300_winder/", "300_winder_rast/" )
#            output_dir = os.path.join( "300_winder_fullpage_vor", output_dir )
            output_dir = os.path.join( "300_winder_fullpage_rast", output_dir )

            # destination doesn't exist, make it
            if not os.path.exists(output_dir) : 
                os.makedirs( output_dir )

            img_filelist = pngfiles
            xml_filelist = [ s.replace(".png",".xml") for s in img_filelist ]

            # output data file name is based on the last dir in the tree
#            print "imgpath=",imgpath
            output_basename = os.path.split(imgpath)[-1]
            
#            print "output_dir=",output_dir
#            print "output_basename=",output_basename

            runseg.run_file_list( img_filelist, xml_filelist, output_dir, output_basename )