-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwavelet_transform.py
31 lines (24 loc) · 954 Bytes
/
wavelet_transform.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Wavelet transform to be applied to the images in the dataset
import numpy as np
import pywt
from typing import Callable, Tuple
def create_dwt_fn(
wavelet: str, level: int
) -> Callable[[np.ndarray, np.ndarray], Tuple[np.ndarray, np.ndarray]]:
"""
Returns a function that applies the given transform to an input and target
to be used inside the IcasspDataset class
"""
def dwt(input: np.ndarray, target: np.ndarray) -> [np.ndarray, np.ndarray]:
input_1, _ = pywt.coeffs_to_array(
pywt.wavedecn(input[:, :, :1024], wavelet=wavelet, level=level)
)
input_2, _ = pywt.coeffs_to_array(
pywt.wavedecn(input[:, :, 1024:], wavelet=wavelet, level=level)
)
input = np.concatenate((input_1, input_2), axis=2)
target, _ = pywt.coeffs_to_array(
pywt.wavedecn(target, wavelet=wavelet, level=level)
)
return input, target
return dwt