PaddlePaddle tutorial Ⅶ——Augmentation for Image

图像数据

本次使用的图片为lena.jpg,图像来源于百度百科

1

Paddle提供两种转换方式,一种是利用functional进行转换,类似于使用函数的方式。另一种是使用Transform方式,这种方式可以将所有的转换方法存入一个列表,使用更加方便。数据增强采用的图像格式为PIL,更多增强方式参见官方文档

import numpy as np
from PIL import Image
from paddle.vision.transforms import functional as F
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings("ignore")

functional

image = Image.open('lena.jpg')
adjust_contrast_img = F.adjust_contrast(image, 0.4)
adjust_brightness_img = F.adjust_brightness(image, 0.4)
adjust_hue_img = F.adjust_hue(image, 0.4)
adjust_saturation_img = F.adjust_saturation(image, 0.4)
center_crop_img = F.center_crop(image, (150, 100))
cropped_img = F.crop(image, 56, 150, 200, 300)
flpped_img = F.hflip(image)
fig = plt.gcf()
fig.set_size_inches(18, 10)

ax_img = plt.subplot(2, 4, 1)
ax_img.imshow(image, cmap='binary')
ax_img.set_title('raw image',
                 fontsize=10)

ax_img = plt.subplot(2, 4, 2)
ax_img.imshow(adjust_contrast_img, cmap='binary')
ax_img.set_title('adjust contrast image',
                 fontsize=10)

ax_img = plt.subplot(2, 4, 3)
ax_img.imshow(adjust_brightness_img, cmap='binary')
ax_img.set_title('adjust brightness image',
                 fontsize=10)

ax_img = plt.subplot(2, 4, 4)
ax_img.imshow(adjust_hue_img, cmap='binary')
ax_img.set_title('adjust hue image',
                 fontsize=10)

ax_img = plt.subplot(2, 4, 5)
ax_img.imshow(adjust_saturation_img, cmap='binary')
ax_img.set_title('adjust saturation image',
                 fontsize=10)

ax_img = plt.subplot(2, 4, 6)
ax_img.imshow(center_crop_img, cmap='binary')
ax_img.set_title('adjust saturation image',
                 fontsize=10)

ax_img = plt.subplot(2, 4, 7)
ax_img.imshow(cropped_img, cmap='binary')
ax_img.set_title('adjust saturation image',
                 fontsize=10)

ax_img = plt.subplot(2, 4, 8)
ax_img.imshow(flpped_img, cmap='binary')
ax_img.set_title('adjust saturation image',
                 fontsize=10)

plt.show()

1

Transform

from paddle.vision.transforms import *
image = Image.open('lena.jpg')
transform_list = [BrightnessTransform(0.4), CenterCrop(224), ColorJitter(0.4, 0.4, 0.4, 0.4), ContrastTransform(0.4),
                 Grayscale(), RandomCrop(176), HueTransform(0.4)]
transform_name_list = ['BrightnessTransform', 'CenterCrop', 'ColorJitter', 'ContrastTransform', 'Grayscale', 'RandomCrop', 'HueTransform']
transformed_image = [transform(image) for transform in transform_list]
fig = plt.gcf()
fig.set_size_inches(18, 10)


ax_img = plt.subplot(2, 4, 1)
ax_img.imshow(image, cmap='binary')
ax_img.set_title('raw image',
                 fontsize=10)

for i in range(len(transformed_image)):
    ax_img = plt.subplot(2, 4, i+2)
    ax_img.imshow(transformed_image[i], cmap='binary')
    ax_img.set_title(transform_name_list[i],
                     fontsize=10)
plt.show()

1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值