Example #1
0
def IHS(pan, hs):

    M, N, c = pan.shape
    m, n, C = hs.shape

    ratio = int(np.round(M / m))

    print('get sharpening ratio: ', ratio)
    assert int(np.round(M / m)) == int(np.round(N / n))

    #upsample
    u_hs = upsample_interp23(hs, ratio)

    I = np.mean(u_hs, axis=-1, keepdims=True)

    P = (pan - np.mean(pan)) * np.std(I, ddof=1) / np.std(pan,
                                                          ddof=1) + np.mean(I)

    I_IHS = u_hs + np.tile(P - I, (1, 1, C))

    #adjustment
    I_IHS[I_IHS < 0] = 0
    I_IHS[I_IHS > 1] = 1

    return I_IHS
Example #2
0
def Brovey(pan, hs):

    M, N, c = pan.shape
    m, n, C = hs.shape

    ratio = int(np.round(M / m))

    print('get sharpening ratio: ', ratio)
    assert int(np.round(M / m)) == int(np.round(N / n))

    #upsample
    u_hs = upsample_interp23(hs, ratio)

    I = np.mean(u_hs, axis=-1)

    image_hr = (pan - np.mean(pan)) * (np.std(I, ddof=1) /
                                       np.std(pan, ddof=1)) + np.mean(I)
    image_hr = np.squeeze(image_hr)

    I_Brovey = []
    for i in range(C):
        temp = image_hr * u_hs[:, :, i] / (I + 1e-8)
        temp = np.expand_dims(temp, axis=-1)
        I_Brovey.append(temp)

    I_Brovey = np.concatenate(I_Brovey, axis=-1)

    #adjustment
    I_Brovey[I_Brovey < 0] = 0
    I_Brovey[I_Brovey > 1] = 1

    return I_Brovey
Example #3
0
def GFPCA(pan, hs):

    M, N, c = pan.shape
    m, n, C = hs.shape

    ratio = int(np.round(M / m))

    print('get sharpening ratio: ', ratio)
    assert int(np.round(M / m)) == int(np.round(N / n))

    p = princomp(n_components=C)
    pca_hs = p.fit_transform(np.reshape(hs, (m * n, C)))

    pca_hs = np.reshape(pca_hs, (m, n, C))

    pca_hs = upsample_interp23(pca_hs, ratio)

    gp_hs = []
    for i in range(C):
        temp = guidedFilter(np.float32(pan),
                            np.float32(np.expand_dims(pca_hs[:, :, i], -1)),
                            8,
                            eps=0.001**2)
        temp = np.expand_dims(temp, axis=-1)
        gp_hs.append(temp)

    gp_hs = np.concatenate(gp_hs, axis=-1)

    I_GFPCA = p.inverse_transform(gp_hs)

    #adjustment
    I_GFPCA[I_GFPCA < 0] = 0
    I_GFPCA[I_GFPCA > 1] = 1

    return I_GFPCA
Example #4
0
def SFIM(pan, hs):

    M, N, c = pan.shape
    m, n, C = hs.shape
    
    ratio = int(np.round(M/m))
        
    print('get sharpening ratio: ', ratio)
    assert int(np.round(M/m)) == int(np.round(N/n))
    
    #upsample
    u_hs = upsample_interp23(hs, ratio)
    
    if np.mod(ratio, 2)==0:
        ratio = ratio + 1
        
    pan = np.tile(pan, (1, 1, C))
    
    pan = (pan - np.mean(pan, axis=(0, 1)))*(np.std(u_hs, axis=(0, 1), ddof=1)/np.std(pan, axis=(0, 1), ddof=1))+np.mean(u_hs, axis=(0, 1))
    
    kernel = np.ones((ratio, ratio))
    kernel = kernel/np.sum(kernel)
    
    I_SFIM = np.zeros((M, N, C))
    for i in range(C):
        lrpan = signal.convolve2d(pan[:, :, i], kernel, mode='same', boundary = 'wrap')
        I_SFIM[:, :, i] = u_hs[:, :, i]*pan[:, :, i]/(lrpan+1e-8)

    #adjustment
    I_SFIM[I_SFIM<0]=0
    I_SFIM[I_SFIM>1]=1    
    
    return I_SFIM
Example #5
0
def Wavelet(pan, hs):

    M, N, c = pan.shape
    m, n, C = hs.shape

    ratio = int(np.round(M / m))

    print('get sharpening ratio: ', ratio)
    assert int(np.round(M / m)) == int(np.round(N / n))

    #upsample
    u_hs = upsample_interp23(hs, ratio)

    pan = np.squeeze(pan)
    pc = pywt.wavedec2(pan, 'haar', level=2)

    rec = []
    for i in range(C):
        temp_dec = pywt.wavedec2(u_hs[:, :, i], 'haar', level=2)

        pc[0] = temp_dec[0]

        temp_rec = pywt.waverec2(pc, 'haar')
        temp_rec = np.expand_dims(temp_rec, -1)
        rec.append(temp_rec)

    I_Wavelet = np.concatenate(rec, axis=-1)

    #adjustment
    I_Wavelet[I_Wavelet < 0] = 0
    I_Wavelet[I_Wavelet > 1] = 1

    return I_Wavelet
Example #6
0
def PCA(pan, hs):

    M, N, c = pan.shape
    m, n, C = hs.shape

    ratio = int(np.round(M / m))

    print('get sharpening ratio: ', ratio)
    assert int(np.round(M / m)) == int(np.round(N / n))

    image_hr = pan

    #upsample
    u_hs = upsample_interp23(hs, ratio)

    p = princomp(n_components=C)
    pca_hs = p.fit_transform(np.reshape(u_hs, (M * N, C)))

    pca_hs = np.reshape(pca_hs, (M, N, C))

    I = pca_hs[:, :, 0]

    image_hr = (image_hr - np.mean(image_hr)) * np.std(I, ddof=1) / np.std(
        image_hr, ddof=1) + np.mean(I)

    pca_hs[:, :, 0] = image_hr[:, :, 0]

    I_PCA = p.inverse_transform(pca_hs)

    #equalization
    I_PCA = I_PCA - np.mean(I_PCA, axis=(0, 1)) + np.mean(u_hs)

    #adjustment
    I_PCA[I_PCA < 0] = 0
    I_PCA[I_PCA > 1] = 1

    return I_PCA
Example #7
0
def MTF_GLP(pan, hs, sensor='gaussian'):
    
    M, N, c = pan.shape
    m, n, C = hs.shape
    
    ratio = int(np.round(M/m))
        
    print('get sharpening ratio: ', ratio)
    assert int(np.round(M/m)) == int(np.round(N/n))
    
    #upsample
    u_hs = upsample_interp23(hs, ratio)
    
    #equalization
    image_hr = np.tile(pan, (1, 1, C))
    
    image_hr = (image_hr - np.mean(image_hr, axis=(0,1)))*(np.std(u_hs, axis=(0, 1), ddof=1)/np.std(image_hr, axis=(0, 1), ddof=1))+np.mean(u_hs, axis=(0,1))
    
#    print(image_hr.shape)
    
    pan_lp = np.zeros_like(u_hs)
    N =31
    fcut = 1/ratio
    match = 0
    
    if sensor == 'gaussian':
        sig = (1/(2*(2.772587)/ratio**2))**0.5
        kernel = np.multiply(cv2.getGaussianKernel(9, sig), cv2.getGaussianKernel(9,sig).T)
        
        t=[]
        for i in range(C):
            temp = signal.convolve2d(image_hr[:, :, i], kernel, mode='same', boundary = 'wrap')
            temp = temp[0::ratio, 0::ratio]
            temp = np.expand_dims(temp, -1)
            t.append(temp)
        
        t = np.concatenate(t, axis=-1)
        pan_lp = upsample_interp23(t, ratio)
    
    elif sensor == None:
        match=1
        GNyq = 0.3*np.ones((C,))
    elif sensor=='QB':
        match=1
        GNyq = np.asarray([0.34, 0.32, 0.30, 0.22],dtype='float32')    # Band Order: B,G,R,NIR
    elif sensor=='IKONOS':
        match=1           #MTF usage
        GNyq = np.asarray([0.26,0.28,0.29,0.28],dtype='float32')    # Band Order: B,G,R,NIR
    elif sensor=='GeoEye1':
        match=1             # MTF usage
        GNyq = np.asarray([0.23,0.23,0.23,0.23],dtype='float32')    # Band Order: B,G,R,NIR   
    elif sensor=='WV2':
        match=1            # MTF usage
        GNyq = [0.35,0.35,0.35,0.35,0.35,0.35,0.35,0.27]
    elif sensor=='WV3':
        match=1             #MTF usage
        GNyq = 0.29 * np.ones(8)
    
    if match==1:
        t = []
        for i in range(C):
            alpha = np.sqrt(N*(fcut/2)**2/(-2*np.log(GNyq)))
            H = np.multiply(cv2.getGaussianKernel(N, alpha[i]), cv2.getGaussianKernel(N, alpha[i]).T)
            HD = H/np.max(H)
            
            h = fir_filter_wind(HD, kaiser2d(N, 0.5))
            
            temp = signal.convolve2d(image_hr[:, :, i], np.real(h), mode='same', boundary = 'wrap')
            temp = temp[0::ratio, 0::ratio]
            temp = np.expand_dims(temp, -1)
            t.append(temp)
        
        t = np.concatenate(t, axis=-1)
        pan_lp = upsample_interp23(t, ratio)
        
    I_MTF_GLP = u_hs + image_hr - pan_lp        
    
    #adjustment
    I_MTF_GLP[I_MTF_GLP<0]=0
    I_MTF_GLP[I_MTF_GLP>1]=1
    
    return I_MTF_GLP
Example #8
0
def GSA(pan, hs):

    M, N, c = pan.shape
    m, n, C = hs.shape

    ratio = int(np.round(M / m))

    print('get sharpening ratio: ', ratio)
    assert int(np.round(M / m)) == int(np.round(N / n))

    #upsample
    u_hs = upsample_interp23(hs, ratio)

    #remove means from u_hs
    means = np.mean(u_hs, axis=(0, 1))
    image_lr = u_hs - means

    #remove means from hs
    image_lr_lp = hs - np.mean(hs, axis=(0, 1))

    #sintetic intensity
    image_hr = pan - np.mean(pan)
    image_hr0 = cv2.resize(image_hr, (n, m), cv2.INTER_CUBIC)
    image_hr0 = np.expand_dims(image_hr0, -1)

    alpha = estimation_alpha(image_hr0,
                             np.concatenate((image_lr_lp, np.ones((m, n, 1))),
                                            axis=-1),
                             mode='global')

    I = np.dot(np.concatenate((image_lr, np.ones((M, N, 1))), axis=-1), alpha)

    I0 = I - np.mean(I)

    #computing coefficients
    g = []
    g.append(1)

    for i in range(C):
        temp_h = image_lr[:, :, i]
        c = np.cov(np.reshape(I0, (-1, )), np.reshape(temp_h, (-1, )), ddof=1)
        g.append(c[0, 1] / np.var(I0))
    g = np.array(g)

    #detail extraction
    delta = image_hr - I0
    deltam = np.tile(delta, (1, 1, C + 1))

    #fusion
    V = np.concatenate((I0, image_lr), axis=-1)

    g = np.expand_dims(g, 0)
    g = np.expand_dims(g, 0)

    g = np.tile(g, (M, N, 1))

    V_hat = V + g * deltam

    I_GSA = V_hat[:, :, 1:]

    I_GSA = I_GSA - np.mean(I_GSA, axis=(0, 1)) + means

    #adjustment
    I_GSA[I_GSA < 0] = 0
    I_GSA[I_GSA > 1] = 1

    return I_GSA