Created
June 22, 2018 03:47
-
-
Save Hiromi-nee/af05feaef2f39818b7aaaa3eb4c2acb1 to your computer and use it in GitHub Desktop.
[Intel AI DevCamp] image aug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#%%bash | |
#echo "Start resizing to 227x227" | |
#parallel -j 200 convert {} -resize 227x227 -filter spline -unsharp 0x6+0.5+0 -background black -gravity center -extent 227x227 {} ::: *.jpg | |
#echo "Resizing done" | |
#mkdir flop | |
#echo "Start augmentation 1" | |
#parallel -j 200 convert {} -flop flop/{.}-flop.jpg ::: *.jpg | |
#echo "Finish augmetation 1" | |
#mkdir flip | |
#echo "Start augmentation 2" | |
#parallel -j 200 convert {} -transverse -rotate 90 flip/{.}-flip.jpg ::: *.jpg | |
#echo "Finish augmetation 2" | |
#mkdir blur | |
#echo "Start augmentation 3" | |
#parallel -j 200 convert {} -blur 0x1 blur/{.}-blur.jpg ::: *.jpg | |
#echo "Finish augmetation 3" | |
#mkdir red | |
#echo "Start augmentation 4" | |
#parallel -j 200 convert {} -channel R -separate red/{.}-red.jpg ::: *.jpg | |
#echo "Finish augmetation 4" | |
#mkdir blue | |
#echo "Start augmentation 5" | |
#parallel -j 200 convert {} -channel B -separate blue/{.}-blue.jpg ::: *.jpg | |
#echo "Finish augmetation 5" | |
#mkdir green | |
#echo "Start augmentation 6" | |
#parallel -j 200 convert {} -channel G -separate green/{.}-green.jpg ::: *.jpg | |
#echo "Finish augmetation 6" | |
#echo "Copying augmented data to main folder" | |
#cp flop/* flip/* blur/* red/* blue/* green/* . | |
#echo "Augmentation done" | |
from multiprocessing import Pool | |
from PIL import Image | |
import sys | |
def resize_image(file, size=224): | |
black_background = Image.new('RGB', (size, size), "black") | |
img = Image.open(file) | |
img.thumbnail((size,size)) | |
x, y = img.size | |
black_background.paste(img, (int((size - x) / 2), int((size - y) / 2))) | |
black_background.save(file) | |
return black_background | |
pool = Pool(6) | |
for i, _ in enumerate(pool.map(resize_image, glob.glob("breeds/*"))): | |
if i % 10 == 0: | |
sys.stdout.write('\r{0} out of {1} processed'.format(i+1, len(glob.glob("breeds/*")))) | |
sys.stdout.write('\n') | |
sys.stdout.flush() | |
display_images(glob.glob('breeds/*.jpg')) | |
print("Done.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment