コード例 #1
0
def level_source(n1, n2, sigma, size, PSFT, Lens_op2, lensed, lvl):
    ns1, ns2 = n1 * size, n2 * size
    ones = np.ones((n1, n2))
    lensed[lensed == 0] = 1
    noise = ones * sigma
    Hnoise = noise * np.sqrt(np.sum(
        PSFT**
        2))  #np.sqrt(scp.fftconvolve(noise**2, PSFT**2, mode = 'same'))##
    FHnoise = Lens_op2(Hnoise)
    FHnoise[FHnoise == 0] = np.mean(FHnoise) * 10.
    dirac = np.zeros((ns1, ns2))
    dirac[ns1 / 2, ns2 / 2] = 1
    wave_dirac = mw.wave_transform(dirac, lvl)
    levels = np.zeros(wave_dirac.shape)
    for i in range(lvl):
        if np.size(noise.shape) > 2:
            lvlso = (scp.fftconvolve(FHnoise[i, :, :]**2,
                                     wave_dirac[i, :, :]**2,
                                     mode='same'))
        else:
            lvlso = scp.fftconvolve(FHnoise**2,
                                    wave_dirac[i, :, :]**2,
                                    mode='same')
        levels[i, :, :] = np.sqrt(np.abs(lvlso))

    return levels
コード例 #2
0
ファイル: MCA.py プロジェクト: EiffL/MuSCADeT
def MM(R,sigma,lvl = 6):
    n1,n2 = np.shape(R)
    
    noisetab = np.array([ 0.8907963 ,  0.20066385,  0.08550751,  0.04121745,  0.02042497,
                         0.01018976,  0.00504662,  0.00368314])
        
    wm = np.zeros((lvl))
    w = np.zeros((lvl,n1,n2))
                         
    w[:,:,:] = mw.wave_transform(R,lvl)
    for l in np.linspace(0,lvl-2,lvl-1):
        wm[l] = np.max(np.abs(w[l,:,:]))/noisetab[l]
    wmax = np.max(wm)/sigma

    k = (wmax)-(wmax)/100
    return k
コード例 #3
0
def level(n1, n2, lvl):
    ##DESCRIPTION:
    ##    Estimates the noise levels in starlet space in image plane.
    ##
    ##INPUTS:
    ##  -n1,n2: shape of the image for which to get noise levels
    ##
    ##OUTPUTS:
    ##  -levels: units of noise levels at each scale and location of a starlet transform
    dirac = np.zeros((n1, n2))
    #   lvl = np.int(np.log2(n1))
    dirac[n1 / 2, n2 / 2] = 1
    wave_dirac = mw.wave_transform(dirac, lvl, newwave=0)

    wave_sum = np.sqrt(np.sum(np.sum(wave_dirac**2, 1), 1))
    levels = np.multiply(np.ones((lvl, n1, n2)).T, wave_sum).T

    return levels
コード例 #4
0
def MAD(x, n=3):
    ##DESCRIPTION:
    ##  Estimates the noise standard deviation from Median Absolute Deviation
    ##
    ##INPUTS:
    ##  -x: a 2D image for which we look for the noise levels.
    ##
    ##OPTIONS:
    ##  -n: size of the median filter. Default is 3.
    ##
    ##OUTPUTS:
    ##  -S: the source light profile.
    ##  -FS: the lensed version of the estimated source light profile
    x = mw.wave_transform(x, np.int(np.log2(x.shape[0])))[0, :, :]
    meda = med.median_filter(x, size=(n, n))
    medfil = np.abs(x - meda)
    sh = np.shape(x)
    sigma = 1.48 * np.median((medfil))
    return sigma
コード例 #5
0
ファイル: MCA.py プロジェクト: EiffL/MuSCADeT
def MOM(R,sigma,lvl = 6):
    """
    Estimates the best for a threshold from method of moments

      INPUTS:
          R: multi-sources cube with size nsxn1xn2 where ns is the number of sources
          and n1xn2, the size of an image
          sigma: noise standard deviation

      OUTPUTS:
          k: threshold level

      OPTIONS:
          lvl: number of wavelet levels used in the decomposition, default is 6.

      EXAMPLES
    """

    ns,n1,n2 = np.shape(R)
    
    noisetab = np.array([ 0.8907963 ,  0.20066385,  0.08550751,  0.04121745,  0.02042497,
        0.01018976,  0.00504662,  0.00368314])
    wmax = np.zeros((ns))
    wm = np.zeros((ns,lvl))
    w = np.zeros((ns,lvl,n1,n2))
    
    for j in np.linspace(0, ns-1, ns):
                w[j,:,:,:] = mw.wave_transform(R[j,:,:],lvl)
    for j in np.linspace(0, ns-1, ns):
                for l in np.linspace(0,lvl-2,lvl-1):
                        wm[j,l] = np.max(np.abs(w[j,l,:,:]))/noisetab[l]
                wmax[j] = np.max(wm[j,:])
                wmax[j] = wmax[j]/sigma[j]
                
    k = np.min(wmax)+(max(wmax)-min(wmax))/100
    return k
コード例 #6
0
ファイル: MCA.py プロジェクト: EiffL/MuSCADeT
def mr_filter(img, niter, k, sigma,lvl = 6, pos = False, harder = 0,mulweight = 1, subweight = 0, addweight = 0, soft = False):
    """
      Computes wavelet iterative filtering on an image.

      INPUTS:
          img: image to be filtered
          niter: number of iterations (10 is usually recommended)
          k: threshold level in units of sigma
          sigma: noise standard deviation

      OUTPUTS:
          imnew: filtered image
          wmap: weight map

      OPTIONS:
          lvl: number of wavelet levels used in the decomposition, default is 6.
          pos: if set to True, positivity constrain is applied to the output image
          harder: if set to one, threshold levels are risen. This is used to compensate for correlated noise
          for instance
          mulweight: multiplicative weight (default is 1)
          subweight: weight map derived from other sources applied to diminish the impact of a given set of coefficient (default is 0)
          addweight: weight map used to enhance previously detected features in an iterative process (default is 0)
          soft: if set to True, soft thresholding is used
          
      EXAMPLES
    """


    levels = np.array([ 0.8907963 ,  0.20066385,  0.08550751,  0.04121745,  0.02042497,
        0.01018976,  0.00504662,  0.00368314])
    levels2g = np.array([ 0.94288346,  0.22998949,  0.10029194,  0.04860995,  0.02412084,
        0.01498695])

    shim = np.shape(img)
    n1 = shim[0]
    n2 = shim[1]
    M = np.zeros((lvl,n1,n2))
    M[:,:,:] = 0
    M[-1,:,:] = 1
#    M[:,140:270,300:420] = 1
#    M[:,450:545,500:590] = 1
#    M[:,120:220,630:720] = 1

    sh = np.shape(M)
    th = np.ones(sh)*(k)
    ##A garder
    th[0,:,:] = th[0,0,0]+1+5*harder
    th[1,:,:] = th[1,:,:]+5*harder
    th[2,:,:] = th[2,:,:]+4*harder
    th[3,:,:] = th[3,:,:]+3*harder
    th[4,:,:] = th[4,:,:]+2*harder
    
####################

    th =np.multiply(th.T,levels[:sh[0]]).T*sigma
    th[np.where(th<0)] = 0
    th[-1,:,:] = 0
    imnew = 0
    i =0

    R= img

 #   R[140:270,300:420] = 0.0
#    R[450:545,500:590] = 0.0
#    R[120:220,630:720] = 0.0
    alpha = mw.wave_transform(R,lvl, newwave = 0)
    
    if pos == True :
         M[np.where(alpha-np.abs(addweight)+np.abs(subweight)-np.abs(th)*mulweight > 0)] = 1
    else:

         M[np.where(np.abs(alpha)-np.abs(addweight)+np.abs(subweight)-np.abs(th)*mulweight > 0)] = 1


    while i < niter:
        R = img-imnew
 #       R[140:270,300:420] = 0.0
#        R[450:545,500:590] = 0.0
#        R[120:220,630:720] = 0.0
        alpha = mw.wave_transform(R,lvl,newwave = 1)
 #       plt.imshow(R); plt.show()
        if soft == True and i>0:
            alpha= np.sign(alpha)*(np.abs(alpha)-np.abs(addweight)+np.abs(subweight)-(th*mulweight))   

        Rnew = mw.iuwt(M*alpha)
        imnew = imnew+Rnew
        
        i = i+1
        
        
        imnew[np.where(imnew<0)]=0
        wmap = mw.wave_transform(imnew,lvl)
    return imnew,wmap