# 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


from MEHI.utils.tool import exeTime
    from skimage.filters import threshold_otsu, threshold_adaptive
    from skimage.morphology import disk, binary_opening
    from skimage.feature import peak_local_max
    from skimage.morphology import watershed, remove_small_objects
    from scipy import ndimage
    from MEHI.udf._moment import moment
    from scipy import ndimage as ndi
import numpy as np
    import scipy.ndimage as ndi
    import pandas as pd
        return binary
    def otsu(frame):
        threshold = threshold_otsu(frame)
        binary = frame > threshold
        return binary
    def duel(frame):
        threshold = threshold_otsu(frame)
        binary1 = frame > threshold
        frame = frame - binary1 * frame
        threshold = threshold_otsu(frame)
        binary2 = frame > threshold
        binary = binary1 & binary2
        return binary
    if method=='adaptive':
        block_size = args[0]
        return np.array(map(adaptive, img_stack))
    elif method == 'otsu':
        return np.array(map(otsu, img_stack))
    elif method == 'duel':
        return np.array(map(duel, img_stack))
    else:
        raise "Bad Threshold Method", method

def peak_filter(image_stack, smooth_size):
    def func(frame):
        opened = binary_opening(frame, disk(smooth_size))
        opened = opened & frame
        return opened
    return np.array(map(func, img_stack))


# 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/serial/segmentation.py
from MEHI.utils.tool import exeTime
    from skimage.filters import threshold_otsu, threshold_adaptive
    from skimage.morphology import disk, binary_opening
    from skimage.feature import peak_local_max
    from skimage.morphology import watershed, remove_small_objects
    from scipy import ndimage
    from MEHI.udf._moment import moment
    from scipy import ndimage as ndi
import numpy as np
    import scipy.ndimage as ndi
    import pandas as pd

        return binary
    def otsu(frame):
        threshold = threshold_otsu(frame)
        binary = frame > threshold
        return binary
    def duel(frame):
        threshold = threshold_otsu(frame)
        binary1 = frame > threshold
        frame = frame - binary1 * frame
        threshold = threshold_otsu(frame)
        binary2 = frame > threshold
        binary = binary1 & binary2
        return binary
    if method=='adaptive':
        block_size = args[0]
        return np.array(map(adaptive, img_stack))
    elif method == 'otsu':
        return np.array(map(otsu, img_stack))
    elif method == 'duel':
        return np.array(map(duel, img_stack))
    else:
        raise "Bad Threshold Method", method

def peak_filter(image_stack, smooth_size):
    def func(frame):
        opened = binary_opening(frame, disk(smooth_size))
        opened = opened & frame
        return opened
    return np.array(map(func, img_stack))


@exeTime