pytorch之torchvision.transforms图像变换实例
作者:啧啧啧biubiu 时间:2021-05-19 05:44:05
transforms.CenterCrop(size)
将给定的PIL.Image进行中心切割,得到给定的size,size可以是tuple,(target_height, target_width)。size也可以是一个Integer,在这种情况下,切出来的图片的形状是正方形。
size可以为int,也可以为float
#定义中心切割
centerCrop = transforms.CenterCrop((img.size[0]/2,img.size[1]/2))
imgccrop = centerCrop(img)
transforms.RandomCrop(size,padding=0)
切割中心点的位置随机选取。size可以是tuple也可以是Integer。
但是如果是Tuple,只能是int型的不能是float
#要求目标size必须为整数
randomCrop1 = transforms.RandomCrop((int(img.size[0]/2),int(img.size[1]/2))) #padding默认为False
randomCrop2 = transforms.RandomCrop((int(img.size[0]/2),int(img.size[1]/2)),padding=10)
imgrcrop1 = randomCrop1(img)
imgrcrop2 = randomCrop2(img)
transforms.RandomHorizontalFlip
随机水平翻转给定的PIL.Image,概率为0.5。即:一半的概率翻转,一半的概率不翻转。
#随机将图片旋转180°
randomFlip = transforms.RandomHorizontalFlip()
imgf = randomFlip(img)
transforms.RandomSizedCrop(size, interpolation=2)
先将给定的PIL.Image随机切,然后再resize成给定的size大小。
size只能是Int,不能是float或tuple
#参数需为一个整数,不能是float或者tuple
randomcut = transforms.RandomResizedCrop(100)
imgc = randomcut(img)
transforms.Pad(padding, fill=0)
将给定的PIL.Image的所有边用给定的pad value填充。 padding:要填充多少像素fill
可以用于给图片加边框2333
#加边界框
pad = transforms.Pad(padding=10,fill=0)
pad_img = pad(img)
pad_img.save("block.jpg")
来源:https://blog.csdn.net/qq_37385726/article/details/81812915
标签:pytorch,torchvision,transforms,图像
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python的时间模块datetime详解
2023-10-17 01:36:48
Python多线程实现支付模拟请求过程解析
2023-04-09 17:59:35
Keras多线程机制与flask多线程冲突的解决方案
2023-09-12 02:10:51
python实现门限回归方式
2023-12-27 09:19:06
![](https://img.aspxhome.com/file/2023/8/79668_0s.jpg)
关于django python manage.py startapp 应用名出错异常原因解析
2023-04-04 08:57:28
![](https://img.aspxhome.com/file/2023/4/64224_0s.png)
Python的爬虫程序编写框架Scrapy入门学习教程
2021-12-27 10:01:48
![](https://img.aspxhome.com/file/2023/5/76705_0s.png)
python开发之thread实现布朗运动的方法
2021-04-10 00:17:36
![](https://img.aspxhome.com/file/2023/2/92102_0s.png)
Python机器学习从ResNet到DenseNet示例详解
2023-04-21 09:19:16
![](https://img.aspxhome.com/file/2023/6/77666_0s.png)
mysql 导入导出数据
2011-02-23 12:27:00
仿6room网站图片链接效果
2007-06-21 13:59:00
![](https://img.aspxhome.com/file/uploadpic/20075/2007511165137528.gif)
来看看如何防止采集
2007-08-19 20:11:00
让验证码友好一点
2007-10-20 13:45:00
![](https://img.aspxhome.com/file/UploadPic/200710/20/20071020135017833s.gif)
“语法错误 (逗号) 在查询表达式id=20, 21”,怎么处理这个逗号?
2009-09-18 14:52:00
页面中图像格式的选用之我见
2007-10-31 18:11:00
![](https://img.aspxhome.com/file/UploadPic/200710/31/2007103119144423s.png)
python 异常的传递性及主动抛出学习
2021-03-19 05:02:38
Python编译为二进制so可执行文件实例
2023-03-05 06:30:36
详细介绍Python进度条tqdm的使用
2022-12-13 19:45:08
![](https://img.aspxhome.com/file/2023/9/77619_0s.gif)
Python使用captcha制作验证码的实现示例
2023-04-16 00:49:35
![](https://img.aspxhome.com/file/2023/3/75113_0s.png)
Oracle回滚段的概念,用法和规划及问题的解决
2010-07-26 13:08:00
python生成器generator:深度学习读取batch图片的操作
2022-07-31 08:43:06