Page MenuHomec4science

augmentation_tools.py
No OneTemporary

File Metadata

Created
Sun, Apr 27, 23:11

augmentation_tools.py

import os
#import tensorflow
import numpy as np
import scipy
#import cv2
from scipy import ndimage
#from matplotlib import pyplot as plt
from PIL import Image
def change_contrast(img, level):
factor = (259 * (level + 255)) / (255 * (259 - level))
def contrast(c):
return 128 + factor * (c - 128)
return img.point(contrast)
def change_contrast_multi(img, steps):
result = []
for n, level in enumerate(steps):
img_filtered = change_contrast(img, level)
result.append(img_filtered)
return result
def rotatedImages(image_array):
return [ndimage.rotate(image_array, degree) for degree in range(0,360,90)] ## rotated image, 4 times 90 degree
def rgb2gray(rgb):
return np.dot(rgb[...,:3], [0.299, 0.587, 0.114])
def sobel(image_array):
image_gray = rgb2gray(image_array).astype('int')
dx = ndimage.sobel(image_gray, axis=0, mode='constant') # horizontal derivative
dy = ndimage.sobel(image_gray, axis=1, mode='constant') # vertical derivative
mag = np.hypot(dx, dy) # magnitude
return mag

Event Timeline