def wavedec(data, wavelet, mode='sym', level=None): """ Multilevel 1D Discrete Wavelet Transform of data. Returns coefficients list - [cAn, cDn, cDn-1, ..., cD2, cD1] data - input data wavelet - wavelet to use (Wavelet object or name string) mode - signal extension mode, see MODES level - decomposition level. If level is None then it will be calculated using `dwt_max_level` function. """ if not isinstance(wavelet, Wavelet): wavelet = Wavelet(wavelet) if level is None: level = dwt_max_level(len(data), wavelet.dec_len) elif level < 0: raise ValueError("Level value of %d is too low . Minimum level is 0." % level) coeffs_list = [] a = data for i in xrange(level): a, d = dwt(a, wavelet, mode) coeffs_list.append(d) coeffs_list.append(a) coeffs_list.reverse() return coeffs_list
def decompose(self): """ Decompose node data creating two subnodes with DWT coefficients" """ if self.level < self.maxlevel: a, d = dwt(self.data, self.wavelet, self.mode) self.createChild("a", a) self.createChild("d", d) return self.a, self.d else: raise ValueError("Maximum level value reached")
def _decompose(self): if self.is_empty: data_a, data_d = None, None if self._get_node(self.A) is None: self._create_subnode(self.A, data_a) if self._get_node(self.B) is None: self._create_subnode(self.B, data_b) else: data_a, data_d = dwt(self.data, self.wavelet, self.mode) self._create_subnode(self.A, data_a) self._create_subnode(self.D, data_d) return self._get_node(self.A), self._get_node(self.D)
def _decompose(self): if self.is_empty: data_a, data_d = None, None if self._get_node(self.A) is None: self._create_subnode(self.A, data_a) if self._get_node(self.D) is None: self._create_subnode(self.D, data_d) else: data_a, data_d = dwt(self.data, self.wavelet, self.mode) self._create_subnode(self.A, data_a) self._create_subnode(self.D, data_d) return self._get_node(self.A), self._get_node(self.D)
def dwt2(data, wavelet, mode='sym'): """ 2D Discrete Wavelet Transform. data - 2D array with input data wavelet - wavelet to use (Wavelet object or name string) mode - signal extension mode, see MODES Returns approximaion and three details 2D coefficients arrays. The result form four 2D coefficients arrays organized in tuples: (approximation, (horizontal details, vertical details, diagonal details) ) which sometimes is also interpreted as layed out in one 2D array of coefficients, where: ----------------- | | | | A(LL) | H(LH) | | | | (A, (H, V, D)) <---> ----------------- | | | | V(HL) | D(HH) | | | | ----------------- """ data = as_float_array(data) if len(data.shape) != 2: raise ValueError("Expected 2D data array") if not isinstance(wavelet, Wavelet): wavelet = Wavelet(wavelet) mode = MODES.from_object(mode) # filter rows H, L = [], [] append_L = L.append append_H = H.append for row in data: cA, cD = dwt(row, wavelet, mode) append_L(cA) append_H(cD) del data # filter columns H = transpose(H) L = transpose(L) LL, LH = [], [] append_LL = LL.append append_LH = LH.append for row in L: cA, cD = dwt(array(row, default_dtype), wavelet, mode) append_LL(cA) append_LH(cD) del L HL, HH = [], [] append_HL = HL.append append_HH = HH.append for row in H: cA, cD = dwt(array(row, default_dtype), wavelet, mode) append_HL(cA) append_HH(cD) del H # build result structure # (approx., (horizontal, vertical, diagonal)) ret = (transpose(LL), (transpose(LH), transpose(HL), transpose(HH))) return ret
def dwt2(data, wavelet, mode='sym'): """ 2D Discrete Wavelet Transform. data - 2D array with input data wavelet - wavelet to use (Wavelet object or name string) mode - signal extension mode, see MODES Returns approximation and three details 2D coefficients arrays. The result form four 2D coefficients arrays organized in tuples: (approximation, (horizontal details, vertical details, diagonal details) ) which sometimes is also interpreted as laid out in one 2D array of coefficients, where: ----------------- | | | | A(LL) | H(LH) | | | | (A, (H, V, D)) <---> ----------------- | | | | V(HL) | D(HH) | | | | ----------------- """ data = as_float_array(data) if len(data.shape) != 2: raise ValueError("Expected 2D data array") if not isinstance(wavelet, Wavelet): wavelet = Wavelet(wavelet) mode = MODES.from_object(mode) # filter rows H, L = [], [] for row in data: cA, cD = dwt(row, wavelet, mode) L.append(cA) H.append(cD) del data # filter columns H = transpose(H) L = transpose(L) LL, LH = [], [] for row in L: cA, cD = dwt(array(row, default_dtype), wavelet, mode) LL.append(cA) LH.append(cD) del L HL, HH = [], [] for row in H: cA, cD = dwt(array(row, default_dtype), wavelet, mode) HL.append(cA) HH.append(cD) del H # build result structure # (approx., (horizontal, vertical, diagonal)) ret = (transpose(LL), (transpose(LH), transpose(HL), transpose(HH))) return ret