#!/usr/bin/env python # -*- coding: utf-8 -*- """ Usage: db_prep.py -d <data> -l <label> -n <ndim> -o <outfile> Options: -h --help show this message """ def parse_args(): args = docopt(__doc__) data = args['<data>'] label = args['<label>'] ndim = int(args['<ndim>']) outfile = args['<outfile>'] return data, label, ndim, outfile if __name__ == '__main__': from docopt import docopt from numpy import load from mscr.bovw import BoVW data, label, ndim, outfile = parse_args() X, y = load(data), load(label) bbb = BoVW() bbb.fit(X, y, ndim) bbb.save_prep(outfile)
from docopt import docopt from mscr.util import load_gray, imshow, AddSuffix, MyKNN from mscr.bovw import BoVW from mscr.blocks import RandBlockIter from mscr.blockVote import Vote, BlockVote, Votes2Img from mscr.grid import Grid, GridClassifier imfile, model, nblock, nneigh, display, save = parse_args() img = load_gray(imfile) print '#------------------' print imfile # random block voting bvw = BoVW() bvw.load(model) rbv = BlockVote( Vote(bvw), RandBlockIter(nblock, pdiv, sdiv, md, Md)) votes = rbv.run(img) if display: rbv.show() # corase segmentation coarse = Votes2Img(img.shape[:2]).run(votes) # final segmentation grid = GridClassifier(MyKNN(labels, nn=nneigh), Grid(microsize)) grid.run(img, coarse) grid.finalize()
from docopt import docopt from os.path import join as pjoin from os.path import basename as pbase from mscr.util import load_gray, MyKNN, imshow, AddSuffix from mscr.bovw import BoVW from mscr.blocks import TrivialBlockIter from mscr.blockVote import Vote, BlockVote, Votes2Img from mscr.grid import Grid, GridClassifier imgf, model, w, h, nn, display, save = parse_args() img = load_gray(imgf) print '#-----------------------' print imgf bvw = BoVW() bvw.load(model) ubv = BlockVote(Vote(bvw), TrivialBlockIter(w, h)) votes = ubv.run(img) coarse = Votes2Img(img.shape[:2]).run(votes) grid = GridClassifier(MyKNN(labels, nn=nn), Grid(microsize)) grid.run(img, coarse) grid.finalize() res = grid.show() if display: imshow(res)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Usage: fit_bovw.py -i <prep_data> -o <out> Options: -h --help """ def parse_args(): args = docopt(__doc__) infile = args['<prep_data>'] outfile = args['<out>'] return infile, outfile if __name__ == '__main__': from os.path import exists as pex from docopt import docopt from mscr.bovw import BoVW infile, outfile = parse_args() assert pex(infile), "file %s dosen't exist" % infile bbb = BoVW() bbb.fit_from_prep(infile) bbb.save(outfile)
if __name__ == '__main__': from docopt import docopt from os.path import basename as pbase from os.path import join as pjoin from mscr.util import load_gray, AddSuffix from mscr.bovw import BoVW from mscr.blocks import RandBlockIter from mscr.blockVote import Vote, BlockVote, Votes2Img imfile, nblock, model, display, save = parse_args() print '#----------------------------' print imfile img = load_gray(imfile) bbb = BoVW() bbb.load(model) rbv = BlockVote(Vote(bbb), RandBlockIter(nblock, pdiv, sdiv, md, Md)) asd = rbv.run(img) if display: rbv.show() vimg = Votes2Img(img.shape[:2]) vimg.run(asd) vimg.get_bounding_box() if save: base = pbase(imfile) outfile = pjoin(save, AddSuffix('out', 'pck').run(base))
if __name__ == '__main__': from docopt import docopt from os.path import basename as pbase from os.path import join as pjoin from mscr.util import load_gray, AddSuffix from mscr.bovw import BoVW from mscr.blocks import RandBlockIter from mscr.blockVote import Vote, BlockVote, Votes2Img imfile, nblock, model, display, save = parse_args() print '#----------------------------' print imfile img = load_gray(imfile) bbb = BoVW() bbb.load(model) rbv = BlockVote( Vote(bbb), RandBlockIter(nblock, pdiv, sdiv, md, Md)) asd = rbv.run(img) if display: rbv.show() vimg = Votes2Img(img.shape[:2]) vimg.run(asd) vimg.get_bounding_box() if save: base = pbase(imfile)