-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils_dct.py
33 lines (22 loc) · 912 Bytes
/
utils_dct.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
32
33
import torch
import torch_dct
def dct_flip(x):
return torch_dct.idct_2d(torch.flip(torch_dct.dct_2d(x, norm='ortho'), [-2, -1]), norm='ortho')
def dct_low_pass(x, bandwidth):
if len(x.size()) == 2:
x.unsqueeze_(0)
mask = torch.zeros_like(x)
mask[:, :bandwidth, :bandwidth] = 1
return torch_dct.idct_2d(torch_dct.dct_2d(x, norm='ortho') * mask, norm='ortho').squeeze_()
def dct_high_pass(x, bandwidth):
if len(x.size()) == 2:
x.unsqueeze_(0)
mask = torch.zeros_like(x)
mask[:, -bandwidth:, -bandwidth:] = 1
return torch_dct.idct_2d(torch_dct.dct_2d(x, norm='ortho') * mask, norm='ortho').squeeze_()
def dct_cutoff_low(x, bandwidth):
if len(x.size()) == 2:
x.unsqueeze_(0)
mask = torch.ones_like(x)
mask[:, :bandwidth, :bandwidth] = 0
return torch_dct.idct_2d(torch_dct.dct_2d(x, norm='ortho') * mask, norm='ortho').squeeze_()