# Path: MEHI/utils/tool.py
# def exeTime(func):
#     '''
#     Usage:
#      - just put '@exeTime'(with out quotation) before your function
#      - will show the running time
#     '''
#     import time
#     def wraper(*args, **args2):
#         s = time.time()
#         ret = func(*args, **args2)
#         e = time.time()
#         msg = "%3.3fs taken for {%s}" % (e-s, func.__name__)
#         log('time')(msg)
#         return ret
#     return wraper


import numpy as np
import math
    import scipy.optimize as sciop
    import scipy.optimize as sciop
from MEHI.utils.tool import exeTime
    from MEHI.udf._trans import trans
    from MEHI.udf._update import update
    from skimage.feature import register_translation
    from scipy.ndimage import fourier_shift

    _X, _Y = imgA.shape
    U = _get_trans(vec)
    for i in range(_X):
        for j in range(_Y):
            p = np.array([i,j,1])
            q = np.dot(U, p)
            p = (p[0],p[1])
            q = (q[0],q[1])
            _PV_interpolation(_H, p, q, imgA, imgB)
    return _mutual_info(_H)

def _trans(frame, vec):
    frame = frame.copy(order='C')
    ret = np.zeros_like(frame)
    U = _get_trans(vec)
    trans(frame, U, ret)
    return ret  

@exeTime
def p_powell(imgA, imgB ,vec0):
    '''
    Usage:
     - calc the best vector
    '''
    def cb(xk):
        print xk
    ret = sciop.fmin_powell(_update, vec0, args=(imgA,imgB), callback=cb)
    return ret



# Path: MEHI/utils/tool.py
# def exeTime(func):
#     '''
#     Usage:
#      - just put '@exeTime'(with out quotation) before your function
#      - will show the running time
#     '''
#     import time
#     def wraper(*args, **args2):
#         s = time.time()
#         ret = func(*args, **args2)
#         e = time.time()
#         msg = "%3.3fs taken for {%s}" % (e-s, func.__name__)
#         log('time')(msg)
#         return ret
#     return wraper


# Path: MEHI/paralleled/registration.py
import numpy as np
import math
    import scipy.optimize as sciop
    import scipy.optimize as sciop
from MEHI.utils.tool import exeTime
    from MEHI.udf._trans import trans
    from MEHI.udf._update import update
    from skimage.feature import register_translation
    from scipy.ndimage import fourier_shift

    _X, _Y = imgA.shape
    U = _get_trans(vec)
    for i in range(_X):
        for j in range(_Y):
            p = np.array([i,j,1])
            q = np.dot(U, p)
            p = (p[0],p[1])
            q = (q[0],q[1])
            _PV_interpolation(_H, p, q, imgA, imgB)
    return _mutual_info(_H)

def _trans(frame, vec):
    frame = frame.copy(order='C')
    ret = np.zeros_like(frame)
    U = _get_trans(vec)
    trans(frame, U, ret)
    return ret  

@exeTime
def p_powell(imgA, imgB ,vec0):
    '''
    Usage:
     - calc the best vector
    '''
    def cb(xk):
        print xk
    ret = sciop.fmin_powell(_update, vec0, args=(imgA,imgB), callback=cb)
    return ret



@exeTime
