Пример #1
0
def run(template, subject, opts):
    # lazy import so no imports before run() is really called
    from imreg_dft import imreg

    fnames = (template, subject)
    loaders = opts["loaders"]
    loader_img = loaders[1]
    imgs = [loa.load2reg(fname) for fname, loa in zip(fnames, loaders)]

    # The array where the result should be placed
    tosa = None
    saver = None
    outname = opts["output"]
    if outname is not None:
        tosa = loader_img.get2save()
        saver = loader.LOADERS.get_loader(outname)
        tosa = utils.extend_to_3D(tosa, imgs[0].shape[:3])

    resdict = _get_resdict(imgs, opts, tosa)
    im0, im1, im2 = resdict['unextended']

    if opts["print_format"] is not None:
        msg = opts["print_format"] % resdict
        msg = msg.encode("utf-8")
        msg = msg.decode('unicode_escape')
        sys.stdout.write(msg)

    if outname is not None:
        saver.save(outname, tosa, loader_img)

    if opts["show"]:
        import pylab as pyl
        fig = pyl.figure()
        imreg.imshow(im0, im1, im2, fig=fig)
        pyl.show()
Пример #2
0
def run(template, subject, opts):
    # lazy import so no imports before run() is really called
    from imreg_dft import imreg

    fnames = (template, subject)
    loaders = opts["loaders"]
    loader_img = loaders[1]
    imgs = [loa.load2reg(fname) for fname, loa in zip(fnames, loaders)]

    # The array where the result should be placed
    tosa = None
    saver = None
    outname = opts["output"]
    if outname is not None:
        tosa = loader_img.get2save()
        saver = loader.LOADERS.get_loader(outname)
        tosa = utils.extend_to_3D(tosa, imgs[0].shape[:3])

    resdict = _get_resdict(imgs, opts, tosa)
    im0, im1, im2 = resdict['unextended']

    if opts["print_format"] is not None:
        msg = opts["print_format"] % resdict
        msg = msg.encode("utf-8")
        msg = msg.decode('unicode_escape')
        sys.stdout.write(msg)

    if outname is not None:
        saver.save(outname, tosa, loader_img)

    if opts["show"]:
        import pylab as pyl
        fig = pyl.figure()
        imreg.imshow(im0, im1, im2, fig=fig)
        pyl.show()