Data Augmentation (Height Distortion: Tip Damage)

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 2964 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 _step(value, step_coeff=(0.5,1)):
    """
    step_coeff = (position, gap)\n
    position: 0 ~ 1 ratio\n
    gap [um]\n
    gap: if use negative sign, step shape is inverse
    """
    point_index = int(len(value)*step_coeff[0])
    value[point_index:] = step_coeff[1]
    return value ,point_index
 
def step(Zdata_array, x_step_coeff=(0,0), y_step_coeff=(0.5,1),\
    x_line_coeff=0.5, y_line_coeff=0.5):
    """
    step_coeff = (position, gap)\n
    position: 0 ~ 1 ratio\n
    gap [um]\n
    gap: if use negative sign, step shape is inverse
    """
    x_line, y_line = _slinedata(Zdata_array)
    dist_x, x_line_index = _step(x_line,x_step_coeff)
    dist_y, y_line_index = _step(y_line,y_step_coeff)
    mx, my = np.meshgrid(dist_x,dist_y)
    x_line_pos = int(len(mx[x_line_index,:])*x_line_coeff)
    y_line_pos = int(len(my[y_line_index,:])*y_line_coeff)
    mx[x_line_index,:x_line_pos] -= x_step_coeff[1]
    my[y_line_index,:y_line_pos] -= y_step_coeff[1]
    return Zdata_array + mx + my

def _ribbed(value, ribbed_coeff=(0.5,0.7,1)):
   """
    width, height: 0 ~ 1 ratio\n
    ribbed_coeff = (pos_start, pos_end ,gap)\n
    pos_start: 0 ~ 1 ratio\n
    pos_end: 0 ~ 1 ratio\n
    gap [um]\n
    gap: if use negative sign, step shape is inverse
    """
    point_start_index = int(len(value)*ribbed_coeff[0])
    point_end_index =int(len(value)*ribbed_coeff[1])
    value[point_start_index:point_end_index] = ribbed_coeff[2]
    return value,point_start_index, point_end_index
 
def ribbed(Zdata_array, x_ribbed_coeff=(0,0,0), y_ribbed_coeff=(0.5,0.7,1),
    x_line_coeff = 0.5, y_line_coeff = 0.5):
   """
    width, height: 0 ~ 1 ratio\n
    ribbed_coeff = (pos_start, pos_end ,gap)\n
    pos_start: 0 ~ 1 ratio\n
    pos_end: 0 ~ 1 ratio\n
    gap [um]\n
    gap: if use negative sign, step shape is inverse
    """
    x_line, y_line = _slinedata(Zdata_array)
    dist_x, x_line_start_index, x_line_end_index = _ribbed(x_line,x_ribbed_coeff)
    dist_y, y_line_start_index, y_line_end_index = _ribbed(y_line,y_ribbed_coeff)
    mx, my = np.meshgrid(dist_x, dist_y)
 
    x_line_start_pos = int(len(mx[x_line_start_index,:])*x_line_coeff)
    y_line_start_pos = int(len(my[y_line_start_index,:])*y_line_coeff)
    mx[x_line_start_index,:x_line_start_pos] -= x_ribbed_coeff[2]
    my[y_line_start_index,:y_line_start_pos] -= y_ribbed_coeff[2]
     
    x_line_end_pos = int(len(mx[x_line_end_index,:])*x_line_coeff)
    y_line_end_pos = int(len(my[y_line_end_index,:])*y_line_coeff)
    mx[x_line_end_index,:x_line_end_pos] -= x_ribbed_coeff[2]
    my[y_line_end_index,:y_line_end_pos] -= y_ribbed_coeff[2]
    return Zdata_array + mx + my
Comments (0)

No comments yet. Be the first to comment!

Snippet Information
Author: jungyu.lee
Language: Python
Created: May 13, 2026
Updated: 0 minutes ago
Views: 3
Stars: 0