【图像增强】图像分割中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
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值