imgaug数据增强实例

2024-03-05 21:32
文章标签 数据 实例 增强 imgaug

本文主要是介绍imgaug数据增强实例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 这里给出一个数据增强包imgaug的应用实例


可以简单修改数据路径即可运行程序,对数据进行增强,可以加上对文件夹下的dataset遍历,批处理数据增强。程序来源于Imgaug的github issues便通过做修改,运行于ubuntu,win10下数据写出有问题:

'see' command line parameter default in ubuntu

import imgaug as ia
from imgaug import augmenters as iaa
import numpy as np
import cv2im = cv2.imread('C:/Users/admin/Desktop/20130201_m007.jpg')
im = cv2.resize(im, (224,224)).astype(np.int8)
images = np.zeros([2,224,224,3])
images[0] = im# Sometimes(0.5, ...) applies the given augmenter in 50% of all cases,
# e.g. Sometimes(0.5, GaussianBlur(0.3)) would blur roughly every second image.
st = lambda aug: iaa.Sometimes(0.3, aug)# Define our sequence of augmentation steps that will be applied to every image
# All augmenters with per_channel=0.5 will sample one value _per image_
# in 50% of all cases. In all other cases they will sample new values
# _per channel_.
seq = iaa.Sequential([iaa.Fliplr(0.5), # horizontally flip 50% of all imagesiaa.Flipud(0.5), # vertically flip 50% of all imagesst(iaa.Superpixels(p_replace=(0, 1.0), n_segments=(20, 200))), # convert images into their superpixel representationst(iaa.Crop(percent=(0, 0.1))), # crop images by 0-10% of their height/widthst(iaa.GaussianBlur((0, 3.0))), # blur images with a sigma between 0 and 3.0st(iaa.Sharpen(alpha=(0, 1.0), )), # sharpen imagesst(iaa.Emboss(alpha=(0, 1.0), strength=(0, 2.0))), # emboss images# search either for all edges or for directed edgesst(iaa.Sometimes(0.5,iaa.EdgeDetect(alpha=(0, 0.7)),iaa.DirectedEdgeDetect(alpha=(0, 0.7), direction=(0.0, 1.0)),)),st(iaa.AdditiveGaussianNoise(loc=0, scale=(0.0, 0.2), per_channel=0.5)), # add gaussian noise to imagesst(iaa.Dropout((0.0, 0.1), per_channel=0.5)), # randomly remove up to 10% of the pixelsst(iaa.Invert(0.25, per_channel=True)), # invert color channelsst(iaa.Add((-10, 10), per_channel=0.5)), # change brightness of images (by -10 to 10 of original value)st(iaa.Multiply((0.5, 1.5), per_channel=0.5)), # change brightness of images (50-150% of original value)st(iaa.ContrastNormalization((0.5, 2.0), per_channel=0.5)), # improve or worsen the contrastst(iaa.Affine(scale={"x": (0.8, 1.2), "y": (0.8, 1.2)}, # scale images to 80-120% of their size, individually per axistranslate_px={"x": (-16, 16), "y": (-16, 16)}, # translate by -16 to +16 pixels (per axis)rotate=(-45, 45), # rotate by -45 to +45 degreesshear=(-16, 16), # shear by -16 to +16 degreesorder=ia.ALL, # use any of scikit-image's interpolation methodscval=(0, 255), # if mode is constant, use a cval between 0 and 255mode=ia.ALL # use any of scikit-image's warping modes (see 2nd image from the top for examples))),st(iaa.ElasticTransformation(alpha=(0.5, 3.5), sigma=0.25)) # apply elastic transformations with random strengths],random_order=True # do all of the above in random order
)images_aug = seq.augment_images(images)
seq.show_grid(images[0], rows=8, cols=8)

 

这篇关于imgaug数据增强实例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/777871

相关文章

SQL Server修改数据库名及物理数据文件名操作步骤

《SQLServer修改数据库名及物理数据文件名操作步骤》在SQLServer中重命名数据库是一个常见的操作,但需要确保用户具有足够的权限来执行此操作,:本文主要介绍SQLServer修改数据... 目录一、背景介绍二、操作步骤2.1 设置为单用户模式(断开连接)2.2 修改数据库名称2.3 查找逻辑文件名

Python实例题之pygame开发打飞机游戏实例代码

《Python实例题之pygame开发打飞机游戏实例代码》对于python的学习者,能够写出一个飞机大战的程序代码,是不是感觉到非常的开心,:本文主要介绍Python实例题之pygame开发打飞机... 目录题目pygame-aircraft-game使用 Pygame 开发的打飞机游戏脚本代码解释初始化部

canal实现mysql数据同步的详细过程

《canal实现mysql数据同步的详细过程》:本文主要介绍canal实现mysql数据同步的详细过程,本文通过实例图文相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的... 目录1、canal下载2、mysql同步用户创建和授权3、canal admin安装和启动4、canal

使用SpringBoot整合Sharding Sphere实现数据脱敏的示例

《使用SpringBoot整合ShardingSphere实现数据脱敏的示例》ApacheShardingSphere数据脱敏模块,通过SQL拦截与改写实现敏感信息加密存储,解决手动处理繁琐及系统改... 目录痛点一:痛点二:脱敏配置Quick Start——Spring 显示配置:1.引入依赖2.创建脱敏

Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析

《Spring组件实例化扩展点之InstantiationAwareBeanPostProcessor使用场景解析》InstantiationAwareBeanPostProcessor是Spring... 目录一、什么是InstantiationAwareBeanPostProcessor?二、核心方法解

详解如何使用Python构建从数据到文档的自动化工作流

《详解如何使用Python构建从数据到文档的自动化工作流》这篇文章将通过真实工作场景拆解,为大家展示如何用Python构建自动化工作流,让工具代替人力完成这些数字苦力活,感兴趣的小伙伴可以跟随小编一起... 目录一、Excel处理:从数据搬运工到智能分析师二、PDF处理:文档工厂的智能生产线三、邮件自动化:

java String.join()方法实例详解

《javaString.join()方法实例详解》String.join()是Java提供的一个实用方法,用于将多个字符串按照指定的分隔符连接成一个字符串,这一方法是Java8中引入的,极大地简化了... 目录bVARxMJava String.join() 方法详解1. 方法定义2. 基本用法2.1 拼接

Python数据分析与可视化的全面指南(从数据清洗到图表呈现)

《Python数据分析与可视化的全面指南(从数据清洗到图表呈现)》Python是数据分析与可视化领域中最受欢迎的编程语言之一,凭借其丰富的库和工具,Python能够帮助我们快速处理、分析数据并生成高质... 目录一、数据采集与初步探索二、数据清洗的七种武器1. 缺失值处理策略2. 异常值检测与修正3. 数据

pandas实现数据concat拼接的示例代码

《pandas实现数据concat拼接的示例代码》pandas.concat用于合并DataFrame或Series,本文主要介绍了pandas实现数据concat拼接的示例代码,具有一定的参考价值,... 目录语法示例:使用pandas.concat合并数据默认的concat:参数axis=0,join=

C#代码实现解析WTGPS和BD数据

《C#代码实现解析WTGPS和BD数据》在现代的导航与定位应用中,准确解析GPS和北斗(BD)等卫星定位数据至关重要,本文将使用C#语言实现解析WTGPS和BD数据,需要的可以了解下... 目录一、代码结构概览1. 核心解析方法2. 位置信息解析3. 经纬度转换方法4. 日期和时间戳解析5. 辅助方法二、L