【图像增强】图像分割中Albumentations同时增强原图与掩码

        深度学习中比较常用的是数据增强库Albumentations
  其开源、快速、简单且增强方式很多:重要的是可以同时增强图像及其掩码,边界框或关键点位置等。

话不多说先安装:

pip install albumentations

实验

from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import cv2
import albumentations as A


img = Image.open('./tupian/image.jpg').convert('RGB')
img = np.uint8(img)

mask = Image.open('./tupian/mask.jpg').convert('L')
mask = np.uint8(mask)
mask = mask / 255.0

transform = A.Compose([A.ShiftScaleRotate(shift_limit=0.15, scale_limit=0.15, 
                                          rotate_limit=25, p=0.5, border_mode=0),
                       A.ColorJitter(),
                       A.HorizontalFlip(),
                       A.VerticalFlip()])

transformed = transform(image=img, mask=mask)

img_A = transformed['image']
mask_A = transformed['mask']

plt.figure()
plt.subplot(2,2,1),plt.imshow(img)
plt.axis('off'),plt.title('原图')
plt.subplot(2,2,2),plt.imshow(mask, 'gray')
plt.axis('off'),plt.title('原掩码')
plt.subplot(2,2,3),plt.imshow(img_A)
plt.axis('off'),plt.title('变换后原图')
plt.subplot(2,2,4),plt.imshow(mask_A, 'gray')
plt.axis('off'),plt.title('变换后掩码')
plt.show()

                        
原文链接:https://blog.csdn.net/qq_43426908/article/details/121955919

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
语义分割图像增强算法是为了丰富图像训练集,提取图像特征和泛化模型而设计的。常见的图像增强方式包括旋转图像、剪切图像、改变图像色差、扭曲图像特征、改变图像尺寸大小和增强图像噪音等。然而,对于语义分割任务,需要同时对原始图像和掩码图进行增强,因此现有的深度学习框架自带的图像增强工具并不能直接使用。但是可以使用Augmentor工具库来实现该功能。通过定义图像的旋转、翻转、缩放等操作,并指定执行的概率和参数,可以在训练集生成更多的增强样本。例如,可以使用以下Python代码对图像进行数据增强: ``` import Augmentor p = Augmentor.Pipeline("test1") p.ground_truth("test2") p.rotate(probability=0.8, max_left_rotation=10, max_right_rotation=10) p.flip_left_right(probability=0.5) p.zoom_random(probability=0.3, percentage_area=0.85) p.sample(20) ``` 这段代码使用Augmentor库导入数据增强工具并设置图像存储路径和掩码文件存储路径。然后通过调用旋转、翻转和缩放等函数来增强图像,可以根据需要设置执行的概率和参数。最后,调用sample函数生成扩充后的数据样本。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [结合图像语义分割的增强现实型平视显示系统设计与研究](https://download.csdn.net/download/weixin_38595473/14937134)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [语义分割图像增强新方法](https://blog.csdn.net/niuxuerui11/article/details/114866772)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值