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

相关文章

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

SpringBoot集成Milvus实现数据增删改查功能

《SpringBoot集成Milvus实现数据增删改查功能》milvus支持的语言比较多,支持python,Java,Go,node等开发语言,本文主要介绍如何使用Java语言,采用springboo... 目录1、Milvus基本概念2、添加maven依赖3、配置yml文件4、创建MilvusClient

SQL表间关联查询实例详解

《SQL表间关联查询实例详解》本文主要讲解SQL语句中常用的表间关联查询方式,包括:左连接(leftjoin)、右连接(rightjoin)、全连接(fulljoin)、内连接(innerjoin)、... 目录简介样例准备左外连接右外连接全外连接内连接交叉连接自然连接简介本文主要讲解SQL语句中常用的表

SpringValidation数据校验之约束注解与分组校验方式

《SpringValidation数据校验之约束注解与分组校验方式》本文将深入探讨SpringValidation的核心功能,帮助开发者掌握约束注解的使用技巧和分组校验的高级应用,从而构建更加健壮和可... 目录引言一、Spring Validation基础架构1.1 jsR-380标准与Spring整合1

MySQL 中查询 VARCHAR 类型 JSON 数据的问题记录

《MySQL中查询VARCHAR类型JSON数据的问题记录》在数据库设计中,有时我们会将JSON数据存储在VARCHAR或TEXT类型字段中,本文将详细介绍如何在MySQL中有效查询存储为V... 目录一、问题背景二、mysql jsON 函数2.1 常用 JSON 函数三、查询示例3.1 基本查询3.2

SpringBatch数据写入实现

《SpringBatch数据写入实现》SpringBatch通过ItemWriter接口及其丰富的实现,提供了强大的数据写入能力,本文主要介绍了SpringBatch数据写入实现,具有一定的参考价值,... 目录python引言一、ItemWriter核心概念二、数据库写入实现三、文件写入实现四、多目标写入

使用Python将JSON,XML和YAML数据写入Excel文件

《使用Python将JSON,XML和YAML数据写入Excel文件》JSON、XML和YAML作为主流结构化数据格式,因其层次化表达能力和跨平台兼容性,已成为系统间数据交换的通用载体,本文将介绍如何... 目录如何使用python写入数据到Excel工作表用Python导入jsON数据到Excel工作表用

Mysql如何将数据按照年月分组的统计

《Mysql如何将数据按照年月分组的统计》:本文主要介绍Mysql如何将数据按照年月分组的统计方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mysql将数据按照年月分组的统计要的效果方案总结Mysql将数据按照年月分组的统计要的效果方案① 使用 DA

鸿蒙中Axios数据请求的封装和配置方法

《鸿蒙中Axios数据请求的封装和配置方法》:本文主要介绍鸿蒙中Axios数据请求的封装和配置方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1.配置权限 应用级权限和系统级权限2.配置网络请求的代码3.下载在Entry中 下载AxIOS4.封装Htt

Python获取中国节假日数据记录入JSON文件

《Python获取中国节假日数据记录入JSON文件》项目系统内置的日历应用为了提升用户体验,特别设置了在调休日期显示“休”的UI图标功能,那么问题是这些调休数据从哪里来呢?我尝试一种更为智能的方法:P... 目录节假日数据获取存入jsON文件节假日数据读取封装完整代码项目系统内置的日历应用为了提升用户体验,