Example #1
0
def vinterpolate(v,n=3,smoothing=1):
    from atrous import smooth
    L = len(v)
    if smoothing > 0:
        v = smooth(v, smoothing)
    sp2 = ip.UnivariateSpline(np.arange(L),v, s=0)
    xfit = np.linspace(0,L-1,L*n)
    return sp2(xfit)
Example #2
0
def vinterpolate(v, n=3, smoothing=1):
    from atrous import smooth
    L = len(v)
    if smoothing > 0:
        v = smooth(v, smoothing)
    sp2 = ip.UnivariateSpline(np.arange(L), v, s=0)
    xfit = np.linspace(0, L - 1, L * n)
    return sp2(xfit)
Example #3
0
def guess_seeds(seq, Nfirst=10, smoothing=4):
    """
    automatically guess starting seeds for vessel walls
    relies on the fact that vessel is the largest bright stripe
    """
    Nfirst = min(len(seq), Nfirst)
    d = seq[:Nfirst]
    try:
        from scipy.stats import skew
        s = np.sign(skew(np.ravel(d)))
        print 'Skewness sign:', s
    except:
        s = 1
    y = atrous.smooth(np.mean(s * d, axis=0), smoothing)
    (xfit, yfit), (mx, mn), (gups, gdowns) = lib.extrema2(y, sort_values=True)
    # highest gradient up to the left of the highest max
    gu1 = (g for g in gups if g < mx[0]).next()
    # highest gradient up to the right of the highest max
    gd1 = (g for g in gdowns if g > mx[0]).next()
    return (xfit[gu1], xfit[gd1])
Example #4
0
def guess_seeds(seq, Nfirst=10,smoothing=4):
    """
    automatically guess starting seeds for vessel walls
    relies on the fact that vessel is the largest bright stripe
    """
    Nfirst = min(len(seq), Nfirst)
    d = seq[:Nfirst]
    try:
        from scipy.stats import skew
        s = np.sign(skew(np.ravel(d)))
        print 'Skewness sign:', s
    except :
        s = 1
    y = atrous.smooth(np.mean(s*d,axis=0), smoothing)
    (xfit,yfit), (mx,mn), (gups,gdowns) = lib.extrema2(y, sort_values=True)
    # highest gradient up to the left of the highest max
    gu1 = (g for g in gups if g < mx[0]).next()
    # highest gradient up to the right of the highest max
    gd1 = (g for g in gdowns if g > mx[0]).next() 
    return (xfit[gu1], xfit[gd1])
Example #5
0
def locextr(v, x=None, mode='max', refine=10, output='xfit'):
    """Finds local extrema, type of extrema depends on parameter "mode"
   mode can be {'max' | 'min' | 'gup' | 'gdown' | 'gany'}"""

    if isinstance(x, str):
        mode = x

    if x is None or isinstance(x, str):
        x = np.arange(len(v))

    sp0 = ip.UnivariateSpline(x, atrous.smooth(v), s=0)
    if mode in ['max', 'min']:
        sp = sp0.derivative(1)
    elif mode in ['gup', 'gdown', 'gany']:
        sp = sp0.derivative(2)
    res = 0.05
    if refine > 1:
        xfit = np.linspace(0, x[-1], len(x) * refine)
    else:
        xfit = x
    di = sp(xfit)
    if mode in ['max', 'gup']:
        dersign = np.sign(di)
    elif mode in ['min', 'gdown']:
        dersign = -np.sign(di)
    locations = dersign[:-1] - dersign[1:] > 1.5

    if output is 'all':
        out = xfit[locations], sp0(xfit)[locations]
    elif output is 'yfit':
        out = di[locations]
    elif output is 'xfit':
        out = xfit[locations]
    else:
        print """unknown output code, should be one of  'xfit', 'yfit', 'all',
       returning 'x' locations"""
        out = xfit[locations]
    return out
Example #6
0
def locextr(v, x=None, mode = 'max', refine=10, output='xfit'):
   """Finds local extrema, type of extrema depends on parameter "mode"
   mode can be {'max' | 'min' | 'gup' | 'gdown' | 'gany'}"""

   if type(x) is str:
       mode = x

   if x is None or type(x) is str:
       x = np.arange(len(v))
       
   sp0 = ip.UnivariateSpline(x,atrous.smooth(v),s=0)
   if mode in ['max', 'min']:
       sp = sp0.derivative(1)
   elif mode in ['gup', 'gdown', 'gany']:
       sp = sp0.derivative(2)
   res = 0.05
   if refine > 1:
       xfit = np.linspace(0,x[-1], len(x)*refine)
   else:
       xfit = x
   di = sp(xfit)
   if mode in ['max', 'gup']:
       dersign = np.sign(di)
   elif mode in ['min', 'gdown']:
       dersign = -np.sign(di)
   locations = dersign[:-1] - dersign[1:] > 1.5
   
   if output is 'all':
       out =  xfit[locations], sp0(xfit)[locations]
   elif output is 'yfit':
       out = di[locations]
   elif output is 'xfit':
       out = xfit[locations]
   else:
       print """unknown output code, should be one of  'xfit', 'yfit', 'all',
       returning 'x' locations"""
       out = xfit[locations]
   return out
Example #7
0
def decompose_mwt(arr,level, s=2, tau=5, upto=2):
    """Median-Wavelet transform (up to level 'upto', then followed by starlet transform"""
    out = []
    cj = arr
    upto = min(level, upto)
    for j in range(upto):
        approxm = median_filter(cj, 2*s+1)
        wm = cj-approxm
        #th = tau*MAD(wm)/0.6745
        th = tau*MAD(wm[wm!=0])/0.6745
        wm[np.abs(wm) > th] = 0
        #wm *= np.abs(wm) <= th
        approx_dash = wm + approxm
        cjp1 = atrous.smooth(approx_dash, j+1)
        out.append(cj-cjp1)
        cj = cjp1
        s *= 2
    out.append(cj)
    if level > upto:
        wcoefs = atrous.decompose(cj, level)
        out[-1] = np.sum(wcoefs[:upto+1], axis=0)
        out = np.concatenate([out, wcoefs[upto+1:]])
    return out
Example #8
0
def decompose_mwt(arr, level, s=2, tau=5, upto=2):
    """Median-Wavelet transform (up to level 'upto', then followed by starlet transform"""
    out = []
    cj = arr
    upto = min(level, upto)
    for j in range(upto):
        approxm = median_filter(cj, 2 * s + 1)
        wm = cj - approxm
        # th = tau*MAD(wm)/0.6745
        th = tau * MAD(wm[wm != 0]) / 0.6745
        wm[np.abs(wm) > th] = 0
        # wm *= np.abs(wm) <= th
        approx_dash = wm + approxm
        cjp1 = atrous.smooth(approx_dash, j + 1)
        out.append(cj - cjp1)
        cj = cjp1
        s *= 2
    out.append(cj)
    if level > upto:
        wcoefs = atrous.decompose(cj, level)
        out[-1] = np.sum(wcoefs[: upto + 1], axis=0)
        out = np.concatenate([out, wcoefs[upto + 1 :]])
    return out
Example #9
0
def v2grads(v):
    L = len(v)
    sp2 = ip.UnivariateSpline(np.arange(L), atrous.smooth(v), s=0)
    xfit = np.arange(0, L, 0.1)
    return np.abs(sp2.derivative(1)(xfit))
Example #10
0
def v2grads(v):
    L = len(v)
    sp2 = ip.UnivariateSpline(np.arange(L),atrous.smooth(v), s=0)
    xfit = np.arange(0,L,0.1)
    return np.abs(sp2.derivative(1)(xfit))