python图片数据扩充
'''
作者:TimeVShow
time:2019/8/29
效果:找到标签文件中的所有的图片,对其进行水平翻转,垂直翻转等操作,
并保留改变后的图片,同时在标签集中写入图片的信息
'''
import os
from PIL import Image, ImageFilter
import random
def process_train_set(data_dir="./data_sets/cat_12", list_file_name="train_list.txt"):
file_list_0 = os.path.join(data_dir, list_file_name_0)
file_list = os.path.join(data_dir, list_file_name)
with open(file_list, "r+") as flist:
read_data = flist.read()
flist.truncate()
for eachline in read_data.split('\n'):
img_path,label = eachline.split('\t')
label = label.split("\n")[0]
img_full_path = os.path.join(data_dir, img_path)
if(os.path.exists(img_full_path) == False):
continue
img_path_temp = horizontalFlip(img_full_path)
line = img_path_temp.replace(data_dir + "/", "") + "\t" + label + "\n"
flist.write(line)
img_path_temp = verticalFlip(img_full_path)
line = img_path_temp.replace(data_dir + "/", "") + "\t" + label + "\n"
flist.write(line)
for jitterring_type in range(1, 9)