目前有一个需求,需要生成一批某证件污渍的样本用来训练。
如果直接附着黑色的图像,再改变透明度的话不太像。
所以想到一种直接改变像素点亮度的方式。
但是针对一张1000*800的高像素来说,让某一个像素改变是不足以看到效果的,需要让相邻的一批都改变。
首先:需要先定义一个中心点。x,y
x = random.randint(150, 584) y = random.randint(150, 314)
# 区域所需要的所有点 dot_list = [(x, y)] # 递归扩散寻找周围点 search_dot(dot_list, 500)
递归不能大于1000次,所以,像素点这里选择500个。
def search_dot(dot_list, num_times):
if len(dot_list) <= num_times:
tmp_dot_list = []
for i in dot_list:
(x, y) = i
# 一个点周围有8个相邻点,从8个相邻点中选择未在总列表点中的
dot_1 = (x + 1, y + 1)
dot_2 = (x - 1, y - 1)
dot_3 = (x + 1, y - 1)
dot_4 = (x - 1, y + 1)
dot_5 = (x + 1, y)
dot_6 = (x, y + 1)
dot_7 = (x - 1, y)
dot_8 = (x, y - 1)
if dot_1 not in dot_list:
tmp_dot_list.append(dot_1)
if dot_2 not in dot_list:
tmp_dot_list.append(dot_2)
if dot_3 not in dot_list:
tmp_dot_list.append(dot_3)
if dot_4 not in dot_list:
tmp_dot_list.append(dot_4)
if dot_5 not in dot_list:
tmp_dot_list.append(dot_5)
if dot_6 not in dot_list:
tmp_dot_list.append(dot_6)
if dot_7 not in dot_list:
tmp_dot_list.append(dot_7)
if dot_8 not in dot_list:
tmp_dot_list.append(dot_8)
len_ = len(tmp_dot_list)
ran_int = random.randint(0, len_ - 1)
dot_list.append(tmp_dot_list[ran_int])
search_dot(dot_list)
else:
hund_list(dot_list)
文章描述了一种使用Python编程的方法,通过定义中心点并递归扩散,改变像素亮度来生成模拟证件污渍的样本,以满足特定训练需求,限制在1000*800像素内,最多扩散500次。
1243

被折叠的 条评论
为什么被折叠?



