Created
April 3, 2015 02:18
-
-
Save bobye/93a7fd21bf0f1c447822 to your computer and use it in GitHub Desktop.
prep_img_set.py
This file contains 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
import os | |
import Image | |
import glob | |
import numpy | |
def is_grey_scale(img_path="lena.jpg"): | |
im = Image.open(img_path).convert('RGB') | |
w,h = im.size | |
for i in range(w): | |
for j in range(h): | |
r,g,b = im.getpixel((i,j)) | |
if r != g != b: return False | |
return True | |
mainpath='../images/Expressionism' | |
symbpath='./Expressionism/images' | |
artists=os.listdir(mainpath) | |
# rename grayscale images | |
for artist in artists: | |
images=glob.glob(mainpath + '/' + artist + '/*.jpg') | |
for image in images: | |
if is_grey_scale(image): | |
os.rename(image, image + '.1') | |
# create symbolic links | |
counts = [len(glob.glob(mainpath + '/' + artist + '/*.jpg')) for artist in artists] | |
for idx,artist in enumerate(artists): | |
if counts[idx] >= 30: | |
os.symlink('../../' + mainpath + '/' + artist, symbpath + '/' + artist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment