This is the sixth day of my participation in the First Challenge 2022. For details: First Challenge 2022.

0 foreword

Augly is an open source Python library for data enhancement. Augly supports audio, image, video, and text data, and provides over 100 data enhancement features that can be directly applied to input content. For images, it provides more than 100 data enhancement methods such as cropping, selecting images, adding text to images, increasing saturation, and adjusting brightness. PIP installation, right out of the box, is very convenient for us to use for image processing. It is powerful enough to enhance data not only offline but also online during the Torch training. For details, see the official examples.

At present, this paper gives the following enhancement methods

  • Image fuzzy
  • Change image brightness
  • Change the aspect ratio of the image
  • Color the shaking
  • Contrast enhancement
  • Cut to scale
  • Changing image quality
  • Turn gray
  • Flip horizontal
  • Create text above the image
  • Change the opacity of the image
  • Add emoticons to pictures
  • The two images overlap
  • Web coverage
  • Add a bar in the middle of the image
  • Add text to picture
  • Image boundary filling
  • Fill in the short edges to make a square
  • Perspective transformation
  • Mosaic
  • Random noise
  • The image rotation
  • Change image saturation
  • Change the image resolution
  • sharpen
  • Random pixel ratio varies arbitrarily
  • Flip vertical

1 installation Augly

! pip install auglyCopy the code
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Requirement already satisfied: Requirement already SATISFIED in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (0.1.9) Requirement already satisfied: Pillow>=8.2.0 in /opt/conda/ ENvs /python35-paddle120-env/lib/python3.7/site-packages (from augly) (8.3.2) Requirement already satisfied: Requirement in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from augly) (1.21.2) Requirement already satisfied: Nlpaug ==1.1.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from augly) (1.1.3) Requirement already satisfied: Python-magic >=0.4.22 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from augly) (0.4.24) Requirement already satisfied: In /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from augly) (2021.9.30) Requirement already satisfied: Iopath >=0.1.8 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from augly) (0.1.9) Requirement already satisfied: Portalocker in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from iopath>=0.1.8->augly) (2.3.2) Requirement already satisfied: RQDM in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from iopath>=0.1.8->augly)Copy the code

2 common image enhancement interface

import augly.image as imaugs
import PIL.Image as Image

image_path = "day.jpeg"

aug_image = Image.open(image_path)
aug_image.show()
Copy the code

# Image blur
output_path = "work/blur.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.blur(aug_image,output_path=output_path)

aug_image.show()
Copy the code

# Change image brightness
output_path = "work/brightness.jpeg"             # output image path

aug_image = Image.open(image_path)
aug_image = imaugs.brightness(aug_image,factor=1.5,output_path=output_path)     # Change the factor parameter to adjust brightness

aug_image.show()
Copy the code

# Change the image aspect ratio
output_path = "work/change_aspect_ratio.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.change_aspect_ratio(aug_image,ratio=2,output_path=output_path)

aug_image.show()
Copy the code

# color wobble
output_path = "work/color_jitter.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.color_jitter(aug_image,brightness_factor=1.0,contrast_factor=1.0,saturation_factor=1.5,output_path=output_path)

aug_image.show()
Copy the code

# Contrast enhancement
output_path = "work/contrast.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.contrast(aug_image,factor=1.5,output_path=output_path)

aug_image.show()
Copy the code

# Cut to scale
output_path = "work/crop.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.crop(aug_image,x1=0.1,y1=0.1,x2=0.9,y2=0.9,output_path=output_path)

aug_image.show()
Copy the code

# Change the image quality
output_path = "work/encoding_quality.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.encoding_quality(aug_image,output_path=output_path)

aug_image.show()
Copy the code

# to turn gray
output_path = "work/grayscale.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.grayscale(aug_image,output_path=output_path)

aug_image.show()
Copy the code

# Flip horizontal
output_path = "work/hflip.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.hflip(aug_image,output_path=output_path)

aug_image.show()
Copy the code

# Create text above the image
output_path = "work/meme_format.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.meme_format(aug_image,text="hello world",caption_height=50,output_path=output_path)

aug_image.show()
Copy the code

# Change the opacity of the image
output_path = "work/opacity.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.opacity(aug_image,level=0.5,output_path=output_path)

aug_image.show()
Copy the code

# Emoticons for pictures
output_path = "work/overlay_emoji.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.overlay_emoji(aug_image,output_path=output_path)

aug_image.show()
Copy the code

# Two images overlap
image_path2 = "day1.jpeg"
output_path = "work/overlay_image.jpeg"

aug_image1 = Image.open(image_path)
aug_image2 = Image.open(image_path2)

aug_image = imaugs.overlay_image(aug_image1,image_path2,output_path=output_path)

aug_image.show()
Copy the code

# Web page coverage
output_path = "work/overlay_onto_screenshot.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.overlay_onto_screenshot(aug_image,output_path=output_path)

aug_image.show()
Copy the code

# Add a horizontal bar in the middle of the image
output_path = "work/overlay_stripes.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.overlay_stripes(aug_image,line_width=0.1,output_path=output_path)

aug_image.show()
Copy the code

# Add text to picture
output_path = "work/overlay_text.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.overlay_text(aug_image,output_path=output_path)

aug_image.show()
Copy the code

# Fill image boundaries
output_path = "work/pad.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.pad(aug_image,w_factor=0.25,h_factor=0.25,output_path=output_path)

aug_image.show()
Copy the code

# Fill the short side to make a square
output_path = "work/pad_square.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.pad_square(aug_image,color=(255.255.255),output_path=output_path)

aug_image.show()
Copy the code

# Perspective transform
output_path = "work/perspective_transform.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.perspective_transform(aug_image,output_path=output_path)

aug_image.show()
Copy the code

# Mosaic
output_path = "work/pixelization.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.pixelization(aug_image,ratio=0.5,output_path=output_path)

aug_image.show()
Copy the code

# Random noise
output_path = "work/random_noise.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.random_noise(aug_image,output_path=output_path)

aug_image.show()
Copy the code

# Image rotation
output_path = "work/rotate.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.rotate(aug_image,degrees=10,output_path=output_path)

aug_image.show()
Copy the code

# Change image saturation
output_path = "work/saturation.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.saturation(aug_image,factor=1.5,output_path=output_path)

aug_image.show()
Copy the code

# Change the image resolution
output_path = "work/scale.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.scale(aug_image,factor=0.8,output_path=output_path)

aug_image.show()
Copy the code

# sharpening
output_path = "work/sharpen.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.sharpen(aug_image,factor=1.5,output_path=output_path)

aug_image.show()
Copy the code

# Random pixel ratio varies arbitrarily
output_path = "work/shuffle_pixels.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.shuffle_pixels(aug_image,factor=0.1,output_path=output_path)

aug_image.show()
Copy the code

# Vertical flip
output_path = "work/vflip.jpeg"

aug_image = Image.open(image_path)
aug_image = imaugs.vflip(aug_image,output_path=output_path)

aug_image.show()
Copy the code