-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_edge_img.py
56 lines (47 loc) · 1.38 KB
/
generate_edge_img.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import cv2, torch, os
import numpy as np
from pathlib import Path
from glob import glob
IMG_FORMATS = (
"bmp",
"dng",
"jpeg",
"jpg",
"mpo",
"png",
"tif",
"tiff",
"webp",
"pfm",
) # include image suffixes
llvip_dataset_path = "data/LLVIP"
prw_dataset_path = "data/PRW-v16.04.20"
image_folder_list = [
Path(llvip_dataset_path) / "infrared",
Path(llvip_dataset_path) / "visible",
Path(prw_dataset_path) / "frame",
]
for image_folder in image_folder_list:
root_path = glob(str(Path(image_folder) / "**" / "*.*"), recursive=True)
image_path = sorted(
x.replace("/", os.sep)
for x in root_path
if x.split(".")[-1].lower() in IMG_FORMATS
)
for path in image_path:
img = cv2.imread(str(path), 0)
f = np.fft.fft2(img)
fshift = np.fft.fftshift(f)
rows, cols = img.shape
crow, ccol = int(rows / 2), int(cols / 2)
fshift[crow - 15 : crow + 15, ccol - 15 : ccol + 15] = 0
ishift = np.fft.ifftshift(fshift)
iimg = np.fft.ifft2(ishift)
iimg = np.abs(iimg)
iimg = torch.from_numpy(iimg).type(torch.uint8).numpy()
split_ = str(path).split("/")
split_[3] = split_[3] + "_HF"
path_HF = Path("/".join(split_))
os.makedirs(path_HF.parent, exist_ok=True)
cv2.imwrite(str(path_HF), iimg)
print(path_HF)