def idwt1(cA,cD,wname): [lpd1,hpd1,lpr1,hpr1]=filter.filtcoef(wname) len_lpfilt=int(len(lpr1)) len_hpfilt=int(len(hpr1)) len_avg=int(len_lpfilt/2 + len_hpfilt/2) N= 2 * len(cD) U=2 cA_up=sample.upsamp(cA,U) cA_up=misc.per_ext(cA_up,int(len_avg/2)) X_lp=np.real(convol.convfft(cA_up,lpr1)) cD_up=sample.upsamp(cD,U) cD_up=misc.per_ext(cD_up,int(len_avg/2)) X_hp=np.real(convol.convfft(cD_up,hpr1)) X_lp=X_lp[0:N+len_avg-1] X_lp=X_lp[len_avg-1:] X_hp=X_hp[0:N+len_avg-1] X_hp=X_hp[len_avg-1:] X=X_lp+X_hp return X
def idwt1(cA, cD, wname): [lpd1, hpd1, lpr1, hpr1] = filter.filtcoef(wname) len_lpfilt = int(len(lpr1)) len_hpfilt = int(len(hpr1)) len_avg = int(len_lpfilt / 2 + len_hpfilt / 2) N = 2 * len(cD) U = 2 cA_up = sample.upsamp(cA, U) cA_up = misc.per_ext(cA_up, int(len_avg / 2)) X_lp = np.real(convol.convfft(cA_up, lpr1)) cD_up = sample.upsamp(cD, U) cD_up = misc.per_ext(cD_up, int(len_avg / 2)) X_hp = np.real(convol.convfft(cD_up, hpr1)) X_lp = X_lp[0 : N + len_avg - 1] X_lp = X_lp[len_avg - 1 :] X_hp = X_hp[0 : N + len_avg - 1] X_hp = X_hp[len_avg - 1 :] X = X_lp + X_hp return X
def swt(sig, J, nm): swtop = np.array([]) N = int(len(sig)) length = N [lpd, hpd, lpr, hpr] = filter.filtcoef(nm) for iter in range(J): if iter > 0: M = int(2 ** iter) low_pass = sample.upsamp(lpd, M) high_pass = sample.upsamp(hpd, M) else: low_pass = lpd high_pass = hpd len_filt = int(len(low_pass)) sig = misc.per_ext(sig, int(len_filt / 2)) cA = np.real(convol.convfft(sig, low_pass)) cD = np.real(convol.convfft(sig, high_pass)) cA = cA[len_filt:] cA = cA[0:N] cD = cD[len_filt:] cD = cD[0:N] sig = cA if iter == J - 1: swtop = np.append(cD, swtop) swtop = np.append(cA, swtop) else: swtop = np.append(cD, swtop) return swtop, length
def idwt1_sym(cA,cD,wname): [lpd1,hpd1,lpr1,hpr1]=filter.filtcoef(wname) if len(cA) > len(cD): cA=cA[0:len(cD)] len_lpfilt=int(len(lpr1)) len_hpfilt=int(len(hpr1)) lf=len_lpfilt N= 2 * len(cD) U=2 cA_up=sample.upsamp(cA,U) cA_up=cA_up[0:len(cA_up)-1] X_lp=np.real(convol.convfft(cA_up,lpr1)) cD_up=sample.upsamp(cD,U) cD_up=cD_up[0:len(cD_up)-1] X_hp=np.real(convol.convfft(cD_up,hpr1)) X=X_lp+X_hp X=X[lf-2:] X=X[:len(X)-lf+2] return X
def swt(sig,J,nm): swtop=np.array([]) N=int(len(sig)) length=N [lpd,hpd,lpr,hpr]=filter.filtcoef(nm) for iter in range(J): if iter > 0: M=int(2**iter) low_pass=sample.upsamp(lpd,M) high_pass=sample.upsamp(hpd,M) else: low_pass=lpd high_pass=hpd len_filt=int(len(low_pass)) sig=misc.per_ext(sig,int(len_filt/2)) cA=np.real(convol.convfft(sig,low_pass)) cD=np.real(convol.convfft(sig,high_pass)) cA=cA[len_filt:] cA=cA[0:N] cD=cD[len_filt:] cD=cD[0:N] sig=cA if iter==J-1: swtop=np.append(cD,swtop) swtop=np.append(cA,swtop) else: swtop=np.append(cD,swtop) return swtop,length
def idwt1_sym(cA, cD, wname): [lpd1, hpd1, lpr1, hpr1] = filter.filtcoef(wname) if len(cA) > len(cD): cA = cA[0 : len(cD)] len_lpfilt = int(len(lpr1)) len_hpfilt = int(len(hpr1)) lf = len_lpfilt N = 2 * len(cD) U = 2 cA_up = sample.upsamp(cA, U) cA_up = cA_up[0 : len(cA_up) - 1] X_lp = np.real(convol.convfft(cA_up, lpr1)) cD_up = sample.upsamp(cD, U) cD_up = cD_up[0 : len(cD_up) - 1] X_hp = np.real(convol.convfft(cD_up, hpr1)) X = X_lp + X_hp X = X[lf - 2 :] X = X[: len(X) - lf + 2] return X
def swt2(inpsig,J,nm): swtout=np.array([]) sig=np.array(inpsig) m_size=int(np.size(sig,0)) n_size=int(np.size(sig,1)) rows_n=m_size cols_n=n_size [lp1,hp1,lp2,hp2]=filter.filtcoef(nm) for iter in range(J): U=int(2**iter) low_pass=np.array([]) high_pass=np.array([]) if iter>0: low_pass=sample.upsamp(lp1,U) high_pass=sample.upsamp(hp1,U) else: low_pass=lp1 high_pass=hp1 lf=int(len(low_pass)) if int(np.size(sig,0)%2) == 0: rows_n=int(np.size(sig,0)) else: rows_n=int(np.size(sig,0)+1) if int(np.size(sig,1)%2) == 0: cols_n=int(np.size(sig,1)) else: cols_n=int(np.size(sig,1)+1) signal=np.ndarray(shape=(rows_n+lf,cols_n+lf)) signal=misc.per_ext2d(sig,lf/2) len_x=int(np.size(signal,0)) len_y=int(np.size(signal,1)) sigL=np.ndarray(shape=(rows_n+lf,cols_n)) sigH=np.ndarray(shape=(rows_n+lf,cols_n)) cA=np.ndarray(shape=(rows_n,cols_n)) cH=np.ndarray(shape=(rows_n,cols_n)) cV=np.ndarray(shape=(rows_n,cols_n)) cD=np.ndarray(shape=(rows_n,cols_n)) for i in range(len_x): temp_row=signal[i,0:len_y] oup=np.real(convol.convfft(temp_row,low_pass)) oup=oup[lf:] oup=oup[0:cols_n] oup2=np.real(convol.convfft(temp_row,high_pass)) oup2=oup2[lf:] oup2=oup2[0:cols_n] sigL[i,:]=oup sigH[i,:]=oup2 for j in range(cols_n): temp_row=sigL[0:len_x,j] oup=np.real(convol.convfft(temp_row,low_pass)) oup=oup[lf:] oup=oup[0:rows_n] oup2=np.real(convol.convfft(temp_row,high_pass)) oup2=oup2[lf:] oup2=oup2[0:rows_n] cA[:,j]=oup cH[:,j]=oup2 for j in range(cols_n): temp_row=sigH[0:len_x,j] oup=np.real(convol.convfft(temp_row,low_pass)) oup=oup[lf:] oup=oup[0:rows_n] oup2=np.real(convol.convfft(temp_row,high_pass)) oup2=oup2[lf:] oup2=oup2[0:rows_n] cV[:,j]=oup cD[:,j]=oup2 sig=cA temp_sig2=np.array([]) if iter==J-1: temp_sig2=np.reshape(cA,[np.size(cA,0)*np.size(cA,1)]) temp=np.reshape(cH,[np.size(cH,0)*np.size(cH,1)]) temp_sig2=np.concatenate([temp_sig2,temp]) temp=np.reshape(cV,[np.size(cV,0)*np.size(cV,1)]) temp_sig2=np.concatenate([temp_sig2,temp]) temp=np.reshape(cD,[np.size(cD,0)*np.size(cD,1)]) temp_sig2=np.concatenate([temp_sig2,temp]) swtout=np.concatenate([temp_sig2,swtout]) length=np.array([rows_n,cols_n]) return swtout,length
def iswt(swtop,J,nm): N=int(len(swtop)/(J+1)) [lpd,hpd,lpr,hpr]=filter.filtcoef(nm) low_pass=lpr high_pass=hpr lf=int(len(low_pass)) for iter in range(J): iswt_output=np.zeros(N) if iter==0: appx_sig=swtop[0:N] det_sig=swtop[N:2*N] else: det_sig=swtop[(iter+1)*N:(iter+2)*N] value=int(2**(J-1-iter)) for count in range(value): appx1=appx_sig[count:N:value] det1=det_sig[count:N:value] len1=len(appx1) appx2=appx1[0:len1:2] det2=det1[0:len1:2] U=int(2) cL0=sample.upsamp(appx2,U) cH0=sample.upsamp(det2,U) cL0=misc.per_ext(cL0,int(lf/2)) cH0=misc.per_ext(cH0,int(lf/2)) oup00L=np.real(convol.convfft(cL0,low_pass)) oup00H=np.real(convol.convfft(cH0,high_pass)) oup00L=oup00L[lf-1:] oup00L=oup00L[0:len1] oup00H=oup00H[lf-1:] oup00H=oup00H[0:len1] oup00=oup00L+oup00H appx3=appx1[1:len1:2] det3=det1[1:len1:2] cL1=sample.upsamp(appx3,U) cH1=sample.upsamp(det3,U) cL1=misc.per_ext(cL1,int(lf/2)) cH1=misc.per_ext(cH1,int(lf/2)) oup01L=np.real(convol.convfft(cL1,low_pass)) oup01H=np.real(convol.convfft(cH1,high_pass)) oup01L=oup01L[lf-1:] oup01L=oup01L[0:len1] oup01H=oup01H[lf-1:] oup01H=oup01H[0:len1] oup01=oup01L+oup01H oup01=misc.circshift(oup01,-1) index2=int(0) for index in xrange(count,N,value): temp=(oup00[index2]+oup01[index2])*1.0/2.0 iswt_output[index]=temp index2+=1 appx_sig=iswt_output return iswt_output
def swt2(inpsig, J, nm): swtout = np.array([]) sig = np.array(inpsig) m_size = int(np.size(sig, 0)) n_size = int(np.size(sig, 1)) rows_n = m_size cols_n = n_size [lp1, hp1, lp2, hp2] = filter.filtcoef(nm) for iter in range(J): U = int(2 ** iter) low_pass = np.array([]) high_pass = np.array([]) if iter > 0: low_pass = sample.upsamp(lp1, U) high_pass = sample.upsamp(hp1, U) else: low_pass = lp1 high_pass = hp1 lf = int(len(low_pass)) if int(np.size(sig, 0) % 2) == 0: rows_n = int(np.size(sig, 0)) else: rows_n = int(np.size(sig, 0) + 1) if int(np.size(sig, 1) % 2) == 0: cols_n = int(np.size(sig, 1)) else: cols_n = int(np.size(sig, 1) + 1) signal = np.ndarray(shape=(rows_n + lf, cols_n + lf)) signal = misc.per_ext2d(sig, lf / 2) len_x = int(np.size(signal, 0)) len_y = int(np.size(signal, 1)) sigL = np.ndarray(shape=(rows_n + lf, cols_n)) sigH = np.ndarray(shape=(rows_n + lf, cols_n)) cA = np.ndarray(shape=(rows_n, cols_n)) cH = np.ndarray(shape=(rows_n, cols_n)) cV = np.ndarray(shape=(rows_n, cols_n)) cD = np.ndarray(shape=(rows_n, cols_n)) for i in range(len_x): temp_row = signal[i, 0:len_y] oup = np.real(convol.convfft(temp_row, low_pass)) oup = oup[lf:] oup = oup[0:cols_n] oup2 = np.real(convol.convfft(temp_row, high_pass)) oup2 = oup2[lf:] oup2 = oup2[0:cols_n] sigL[i, :] = oup sigH[i, :] = oup2 for j in range(cols_n): temp_row = sigL[0:len_x, j] oup = np.real(convol.convfft(temp_row, low_pass)) oup = oup[lf:] oup = oup[0:rows_n] oup2 = np.real(convol.convfft(temp_row, high_pass)) oup2 = oup2[lf:] oup2 = oup2[0:rows_n] cA[:, j] = oup cH[:, j] = oup2 for j in range(cols_n): temp_row = sigH[0:len_x, j] oup = np.real(convol.convfft(temp_row, low_pass)) oup = oup[lf:] oup = oup[0:rows_n] oup2 = np.real(convol.convfft(temp_row, high_pass)) oup2 = oup2[lf:] oup2 = oup2[0:rows_n] cV[:, j] = oup cD[:, j] = oup2 sig = cA temp_sig2 = np.array([]) if iter == J - 1: temp_sig2 = np.reshape(cA, [np.size(cA, 0) * np.size(cA, 1)]) temp = np.reshape(cH, [np.size(cH, 0) * np.size(cH, 1)]) temp_sig2 = np.concatenate([temp_sig2, temp]) temp = np.reshape(cV, [np.size(cV, 0) * np.size(cV, 1)]) temp_sig2 = np.concatenate([temp_sig2, temp]) temp = np.reshape(cD, [np.size(cD, 0) * np.size(cD, 1)]) temp_sig2 = np.concatenate([temp_sig2, temp]) swtout = np.concatenate([temp_sig2, swtout]) length = np.array([rows_n, cols_n]) return swtout, length
def iswt(swtop, J, nm): N = int(len(swtop) / (J + 1)) [lpd, hpd, lpr, hpr] = filter.filtcoef(nm) low_pass = lpr high_pass = hpr lf = int(len(low_pass)) for iter in range(J): iswt_output = np.zeros(N) if iter == 0: appx_sig = swtop[0:N] det_sig = swtop[N : 2 * N] else: det_sig = swtop[(iter + 1) * N : (iter + 2) * N] value = int(2 ** (J - 1 - iter)) for count in range(value): appx1 = appx_sig[count:N:value] det1 = det_sig[count:N:value] len1 = len(appx1) appx2 = appx1[0:len1:2] det2 = det1[0:len1:2] U = int(2) cL0 = sample.upsamp(appx2, U) cH0 = sample.upsamp(det2, U) cL0 = misc.per_ext(cL0, int(lf / 2)) cH0 = misc.per_ext(cH0, int(lf / 2)) oup00L = np.real(convol.convfft(cL0, low_pass)) oup00H = np.real(convol.convfft(cH0, high_pass)) oup00L = oup00L[lf - 1 :] oup00L = oup00L[0:len1] oup00H = oup00H[lf - 1 :] oup00H = oup00H[0:len1] oup00 = oup00L + oup00H appx3 = appx1[1:len1:2] det3 = det1[1:len1:2] cL1 = sample.upsamp(appx3, U) cH1 = sample.upsamp(det3, U) cL1 = misc.per_ext(cL1, int(lf / 2)) cH1 = misc.per_ext(cH1, int(lf / 2)) oup01L = np.real(convol.convfft(cL1, low_pass)) oup01H = np.real(convol.convfft(cH1, high_pass)) oup01L = oup01L[lf - 1 :] oup01L = oup01L[0:len1] oup01H = oup01H[lf - 1 :] oup01H = oup01H[0:len1] oup01 = oup01L + oup01H oup01 = misc.circshift(oup01, -1) index2 = int(0) for index in xrange(count, N, value): temp = (oup00[index2] + oup01[index2]) * 1.0 / 2.0 iswt_output[index] = temp index2 += 1 appx_sig = iswt_output return iswt_output