All Projects → vxy10 → Imageaugmentation

vxy10 / Imageaugmentation

Image augmentation for randomly rotating, shearing, translating and changing lighting conditions.

Projects that are alternatives of or similar to Imageaugmentation

Rapids Single Cell Examples
Examples of single-cell genomic analysis accelerated with RAPIDS
Stars: ✭ 138 (+0%)
Mutual labels:  jupyter-notebook
Causalgraphicalmodels
Causal Graphical Models in Python
Stars: ✭ 137 (-0.72%)
Mutual labels:  jupyter-notebook
Gossiping Chinese Corpus
PTT 八卦版問答中文語料
Stars: ✭ 137 (-0.72%)
Mutual labels:  jupyter-notebook
Easy slam tutorial
首个中文的简单从零开始实现视觉SLAM理论与实践教程,使用Python实现。包括:ORB特征点提取,对极几何,视觉里程计后端优化,实时三维重建地图。A easy SLAM practical tutorial (Python).图像处理、otsu二值化。更多其他教程我的CSDN博客
Stars: ✭ 137 (-0.72%)
Mutual labels:  jupyter-notebook
Sketch rnn keras
Keras implementation of Sketch RNN
Stars: ✭ 138 (+0%)
Mutual labels:  jupyter-notebook
Automate The Boring Stuff With Python Solutions
Solutions for Automate the Boring Stuff with Python
Stars: ✭ 136 (-1.45%)
Mutual labels:  jupyter-notebook
Fetching Financial Data
Fetching financial data for technical & fundamental analysis and algorithmic trading from a variety of python packages and sources.
Stars: ✭ 137 (-0.72%)
Mutual labels:  jupyter-notebook
Openff Toolkit
The Open Forcefield Toolkit provides implementations of the SMIRNOFF format, parameterization engine, and other tools. Documentation available at http://open-forcefield-toolkit.readthedocs.io
Stars: ✭ 138 (+0%)
Mutual labels:  jupyter-notebook
Indaba 2018
Practical Notebooks for the Deep Learning Indaba 2018
Stars: ✭ 138 (+0%)
Mutual labels:  jupyter-notebook
Nndl Codes
Sample Codes for NNDL
Stars: ✭ 138 (+0%)
Mutual labels:  jupyter-notebook
Dab And Tpose Controlled Lights
Control your lights with dab and t-pose, duh
Stars: ✭ 137 (-0.72%)
Mutual labels:  jupyter-notebook
Minifold
MiniFold: Deep Learning for Protein Structure Prediction inspired by DeepMind AlphaFold algorithm
Stars: ✭ 136 (-1.45%)
Mutual labels:  jupyter-notebook
Symbiflow Arch Defs
FOSS architecture definitions of FPGA hardware useful for doing PnR device generation.
Stars: ✭ 137 (-0.72%)
Mutual labels:  jupyter-notebook
Cnn Audio Denoiser
Tensorflow 2.0 implementation of the paper: A Fully Convolutional Neural Network for Speech Enhancement
Stars: ✭ 138 (+0%)
Mutual labels:  jupyter-notebook
Machine Learning And Data Science
This is a repository which contains all my work related Machine Learning, AI and Data Science. This includes my graduate projects, machine learning competition codes, algorithm implementations and reading material.
Stars: ✭ 137 (-0.72%)
Mutual labels:  jupyter-notebook
Glasses
High-quality Neural Networks for Computer Vision 😎
Stars: ✭ 138 (+0%)
Mutual labels:  jupyter-notebook
Generative adversarial networks 101
Keras implementations of Generative Adversarial Networks. GANs, DCGAN, CGAN, CCGAN, WGAN and LSGAN models with MNIST and CIFAR-10 datasets.
Stars: ✭ 138 (+0%)
Mutual labels:  jupyter-notebook
Recommender live
Stars: ✭ 138 (+0%)
Mutual labels:  jupyter-notebook
Ethnicolr
Predict Race and Ethnicity Based on the Sequence of Characters in a Name
Stars: ✭ 137 (-0.72%)
Mutual labels:  jupyter-notebook
Fm tensorflow
Factorization Machines implementation with Tensorflow
Stars: ✭ 138 (+0%)
Mutual labels:  jupyter-notebook

Generating additional data for unbalanced classes by jittering the original image.

In many deep learning applications, we often come across data sets where one type of data may be seen more than other types. For example, in a traffic sign identification task, there may be more stop signs than speed limit signs. Therefore, in these cases, we need to make sure that the trained model is not biased towards the class that has more data. As an example, consider a data set where there are 5 speed limit signs and 20 stop signs. If the model predicts all signs to be stop signs, its accuracy is 80%. Further, f1-score of such a model is 0.88. Therefore, the model has high tendency to be biased toward the 'stop' sign class. In such cases, additional data can be generated to make the size of data sets similar.

One way to collect more data is to take the picture of the same sign from different angles. This can be done easily in openCV by applying affine transformations, such as rotations, translations and shearing. Affine transformations are transformations where the parallel lines before transformation remain parallel after transformation.

Below I present a function that can be used to generate jittered images. The function takes in the original image, range of angle rotation, range of translation and range of shearing and returns a jittered image. As the function chooses true transformation values from a uniform distribution that is specified by these ranges. I also added brighness augmentation which can be chosen to be on or off by setting the brighness flag in transform_image() function.

Note, the same techniques can be applied using image generator in Keras. However, the transform_image() function provided here will help you play with the parameters and see whats happening under the hood.

#importing some useful packages
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import cv2

import numpy as np
%matplotlib inline
import matplotlib.image as mpimg

def augment_brightness_camera_images(image):
    image1 = cv2.cvtColor(image,cv2.COLOR_RGB2HSV)
    random_bright = .25+np.random.uniform()
    #print(random_bright)
    image1[:,:,2] = image1[:,:,2]*random_bright
    image1 = cv2.cvtColor(image1,cv2.COLOR_HSV2RGB)
    return image1

def transform_image(img,ang_range,shear_range,trans_range,brightness=0):
    '''
    This function transforms images to generate new images.
    The function takes in following arguments,
    1- Image
    2- ang_range: Range of angles for rotation
    3- shear_range: Range of values to apply affine transform to
    4- trans_range: Range of values to apply translations over.

    A Random uniform distribution is used to generate different parameters for transformation

    '''
    # Rotation

    ang_rot = np.random.uniform(ang_range)-ang_range/2
    rows,cols,ch = img.shape    
    Rot_M = cv2.getRotationMatrix2D((cols/2,rows/2),ang_rot,1)

    # Translation
    tr_x = trans_range*np.random.uniform()-trans_range/2
    tr_y = trans_range*np.random.uniform()-trans_range/2
    Trans_M = np.float32([[1,0,tr_x],[0,1,tr_y]])

    # Shear
    pts1 = np.float32([[5,5],[20,5],[5,20]])

    pt1 = 5+shear_range*np.random.uniform()-shear_range/2
    pt2 = 20+shear_range*np.random.uniform()-shear_range/2

    # Brightness


    pts2 = np.float32([[pt1,5],[pt2,pt1],[5,pt2]])

    shear_M = cv2.getAffineTransform(pts1,pts2)

    img = cv2.warpAffine(img,Rot_M,(cols,rows))
    img = cv2.warpAffine(img,Trans_M,(cols,rows))
    img = cv2.warpAffine(img,shear_M,(cols,rows))

    if brightness == 1:
      img = augment_brightness_camera_images(img)

    return img
image = mpimg.imread('stopsign.jpg')
plt.imshow(image);
plt.axis('off');

png

gs1 = gridspec.GridSpec(10, 10)
gs1.update(wspace=0.01, hspace=0.02) # set the spacing between axes.
plt.figure(figsize=(12,12))
for i in range(100):
    ax1 = plt.subplot(gs1[i])
    ax1.set_xticklabels([])
    ax1.set_yticklabels([])
    ax1.set_aspect('equal')
    img = transform_image(image,20,10,5,brightness=1)

    plt.subplot(10,10,i+1)
    plt.imshow(img)
    plt.axis('off')

plt.show()

png

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].