Data Augmentation (Height Distortion: Fluctuation)
Python
It is expected that the data can be used for augmentation in neural network training.
main
0 files
Data Augmentation (Height …..py
Data Augmentation (Height …..py
2580 bytes
import numpy as np
def _slinedata(np_array):
"""
Used when sum of splited line data
"""
height, width = np_array.shape
x_line = np.zeros(width)
y_line = np.zeros(height)
return x_line, y_line
def _minMax(Zdata):
# Min = 0, Max = 1
#Zdata = _zdata(tiff_path)
zMin = np.min(Zdata)
denominator = (np.max(Zdata) - zMin) + 1e-16
return (Zdata - zMin) / denominator
def _exp(x,a,b,c):
return a*np.exp(abs(b)*x)+c
def _fluctuation(value, fluc_coeff=(0.5,0.01,0.015),envelop_ratio=8):
if fluc_coeff[0] >= 1:
return 0, 0, value, 0
"""
fluc_coeff = (position, max value of noise, exp slope)\n
position: 0 ~ 1 ratio\n
max value of noise [um]\n
exp slope: 0 ~ 100\n
high value: low freq noise\n
low value: high freq noise\n
envelop_ratio: (envelop amp / mean amp) ratio
"""
point_index = int(len(value)*fluc_coeff[0])
result_real = value[point_index:].copy()
result_imag = value[point_index:].copy()
half = int(len(result_real)/2)
freq = np.fft.fftfreq(len(value), half*2)
x_axis = np.linspace(0,50,half)
exp_line = _exp(x_axis,fluc_coeff[1],fluc_coeff[2],fluc_coeff[1])
result_real[:half] = exp_line* np.random.randn(half)
result_real[half:] = np.flip(result_real[:half])
result_imag[:half] = exp_line*np.random.randn(half)
result_imag[half:] = -np.flip(result_imag[:half])
result_imag = result_imag*1j
result_real[half-2:half+2] *= envelop_ratio
result_imag[half-2:half+2] *= envelop_ratio
result = result_real + result_imag
result_ifft = abs(np.fft.ifft(result))
value[point_index:] = result_ifft
return result,result_ifft, value, point_index
def fluctuation(Zdata_array, x_fluc_coeff=(0,0,0), y_fluc_coeff=(0,1,0.18),envelop_ratio=8):
"""
fluc_coeff = (position, max value of noise, exp slope)\n
position: 0 ~ 1 ratio\n
max value of noise [um]\n
exp slope: 0 ~ 100\n
high value: low freq noise\n
low value: high freq noise\n
envelop_ratio: (envelop amp / mean amp) ratio
"""
x_line, y_line = _slinedata(Zdata_array)
_, _,dist_x, _ = _fluctuation(x_line,x_fluc_coeff,envelop_ratio=8)
_, _, dist_y, _ = _fluctuation(y_line,y_fluc_coeff,envelop_ratio=8)
dist_x = _minMax(dist_x)*x_fluc_coeff[1]
dist_y = _minMax(dist_y)*y_fluc_coeff[1]
mx, my = np.meshgrid(dist_x,dist_y)
return Zdata_array + mx + my
Comments (0)
No comments yet. Be the first to comment!