# imageDir 为原数据集的存放位置
# saveDir 为数据增强后数据的存放位置
###
#
def flip(root_path,img_name): #翻转图像
img = Image.open(os.path.join(root_path, img_name))
filp_img = img.transpose(Image.FLIP_LEFT_RIGHT)
filp_img.save(os.path.join(root_path,img_name.split('.')[0] + '_flip.jpg'))
return filp_img
def rotation(root_path, img_name):
img = Image.open(os.path.join(root_path, img_name))
rotation_img = img.rotate(20) #旋转角度
rotation_img.save(os.path.join(root_path,img_name.split('.')[0] + '_rotation.jpg'))
return rotation_img
def randomColor(root_path, img_name): #随机颜色
"""
对图像进行颜色抖动
:param image: PIL的图像image
:return: 有颜色色差的图像image
"""
image = Image.open(os.path.join(root_path, img_name))
random_factor = np.random.randint(0, 31) / 10. # 随机因子
color_image = ImageEnhance.Color(image).enhance(random_factor) # 调整图像的饱和度
random_factor = np.random.rand
数据增强-翻转、旋转、随机颜色、对比度增强、亮度增强、颜色增强
最新推荐文章于 2023-11-25 17:12:08 发布
该代码实现了对图像的一系列增强操作,包括翻转、旋转、随机颜色调整、对比度和亮度增强,以用于数据集的扩充。通过ImageEnhance库调整图像的饱和度、亮度、对比度和锐度,以创建新的图像变体。

最低0.47元/天 解锁文章
1334

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



