-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
47 lines (35 loc) · 1.23 KB
/
utils.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
import numpy as np
import cv2
# used for linear mapping... 线性变换
def linear_mapping(images):
max_value = images.max()
min_value = images.min()
parameter_a = 1 / (max_value - min_value)
parameter_b = 1 - max_value * parameter_a
image_after_mapping = parameter_a * images + parameter_b
return image_after_mapping
# pre-processing the image...
def pre_process(img):
# get the size of the img...
height, width = img.shape
img = np.log(img + 1)
img = (img - np.mean(img)) / (np.std(img) + 1e-5)
# use the hanning window...
window = window_func_2d(height, width) #减少FFT中信号的泄漏
img = img * window
return img
def window_func_2d(height, width):
win_col = np.hanning(width)
win_row = np.hanning(height)
mask_col, mask_row = np.meshgrid(win_col, win_row)
win = mask_col * mask_row
return win
def random_warp(img):
a = -180 / 16
b = 180 / 16
r = a + (b - a) * np.random.uniform()
# rotate the image...
matrix_rot = cv2.getRotationMatrix2D((img.shape[1]/2, img.shape[0]/2), r, 1)
img_rot = cv2.warpAffine(np.uint8(img * 255), matrix_rot, (img.shape[1], img.shape[0]))
img_rot = img_rot.astype(np.float32) / 255
return img_rot