def execute(outputsize): faces_dir_path = "data/train_set/48_48_faces_web_augmented" bkgs_dir_path = "data/train_set/48_48_nonfaces_aflw" target_path = "data/train_set/13" faces_dir=join(target_path,"faces") nonfaces_dir = join(target_path,"nonfaces") os.makedirs(nonfaces_dir) os.makedirs(faces_dir) img_faces = [ f for f in listdir(faces_dir_path) if isfile(join(faces_dir_path,f)) and f.endswith("png") ] img_bkgs = [ f for f in listdir(bkgs_dir_path) if isfile(join(bkgs_dir_path,f)) and f.endswith("jpg") ] for i, img_name in enumerate(img_faces): img_path = join(faces_dir_path,img_name) img = imread(img_path) resized_img = resize(img,outputsize) ubyte_img = img_as_ubyte(resized_img) imsave(join(faces_dir,img_name), ubyte_img) print "processed "+ img_path for i, img_name in enumerate(img_bkgs): img_path = join(bkgs_dir_path,img_name) img = imread(img_path) gray_img = rgb2gray(img) resized_img = resize(gray_img,outputsize) ubyte_img = img_as_ubyte(resized_img) imsave(join(nonfaces_dir,img_name), ubyte_img) print "processed "+ img_path
def convert_to_gray(): bkgs_dir_path = "data/train_set/13/nonfaces" target_path = "data/train_set/13/nonfaces_gray" os.makedirs(target_path) img_bkgs = [ f for f in listdir(bkgs_dir_path) if isfile(join(bkgs_dir_path,f)) and f.endswith("jpg") ] for i, img_name in enumerate(img_bkgs): img_path = join(bkgs_dir_path,img_name) img = imread(img_path) gray_img = rgb2gray(img) imsave(join(target_path,img_name), gray_img)
def convert_to_gray(): bkgs_dir_path = "data/train_set/13/nonfaces" target_path = "data/train_set/13/nonfaces_gray" os.makedirs(target_path) img_bkgs = [ f for f in listdir(bkgs_dir_path) if isfile(join(bkgs_dir_path, f)) and f.endswith("jpg") ] for i, img_name in enumerate(img_bkgs): img_path = join(bkgs_dir_path, img_name) img = imread(img_path) gray_img = rgb2gray(img) imsave(join(target_path, img_name), gray_img)
def resize_imgs_in_dir(outputsize): img_dir_path = "data/newnonfaces/48_48_non_faces_aflw" target_path = "data/newnonfaces/13/nonfaces" os.makedirs(target_path) img_faces = [ f for f in listdir(img_dir_path) if isfile(join(img_dir_path,f)) and f.endswith("jpg") ] for i, img_name in enumerate(img_faces): img_path = join(img_dir_path,img_name) img = imread(img_path) resized_img = resize(img,outputsize) ubyte_img = img_as_ubyte(resized_img) imsave(join(target_path,img_name), ubyte_img) print "processed "+ img_path
def resize_imgs_in_dir(outputsize): img_dir_path = "data/newnonfaces/48_48_non_faces_aflw" target_path = "data/newnonfaces/13/nonfaces" os.makedirs(target_path) img_faces = [ f for f in listdir(img_dir_path) if isfile(join(img_dir_path, f)) and f.endswith("jpg") ] for i, img_name in enumerate(img_faces): img_path = join(img_dir_path, img_name) img = imread(img_path) resized_img = resize(img, outputsize) ubyte_img = img_as_ubyte(resized_img) imsave(join(target_path, img_name), ubyte_img) print "processed " + img_path
def execute(outputsize): faces_dir_path = "data/train_set/48_48_faces_web_augmented" bkgs_dir_path = "data/train_set/48_48_nonfaces_aflw" target_path = "data/train_set/13" faces_dir = join(target_path, "faces") nonfaces_dir = join(target_path, "nonfaces") os.makedirs(nonfaces_dir) os.makedirs(faces_dir) img_faces = [ f for f in listdir(faces_dir_path) if isfile(join(faces_dir_path, f)) and f.endswith("png") ] img_bkgs = [ f for f in listdir(bkgs_dir_path) if isfile(join(bkgs_dir_path, f)) and f.endswith("jpg") ] for i, img_name in enumerate(img_faces): img_path = join(faces_dir_path, img_name) img = imread(img_path) resized_img = resize(img, outputsize) ubyte_img = img_as_ubyte(resized_img) imsave(join(faces_dir, img_name), ubyte_img) print "processed " + img_path for i, img_name in enumerate(img_bkgs): img_path = join(bkgs_dir_path, img_name) img = imread(img_path) gray_img = rgb2gray(img) resized_img = resize(gray_img, outputsize) ubyte_img = img_as_ubyte(resized_img) imsave(join(nonfaces_dir, img_name), ubyte_img) print "processed " + img_path