# HG changeset patch # User Xavier Glorot # Date 1265758284 18000 # Node ID ab70fbca513c76d3a2447f0a7f96183e553dd7cd # Parent 7949f46b03e0e9c0134dc4eca6b635565778bf92 Change path to AddBackground and add a image_file attribute (not to do a listdir at each image) diff -r 7949f46b03e0 -r ab70fbca513c transformations/add_background_image.py --- a/transformations/add_background_image.py Tue Feb 09 11:43:09 2010 -0500 +++ b/transformations/add_background_image.py Tue Feb 09 18:31:24 2010 -0500 @@ -15,8 +15,9 @@ self.h = 32 self.w = 32 self.threshold = threshold; - self.bg_image_dir = './images/' - self.pattern = '*.jpg' + self.bg_image_dir = '/data/lisa/data/ift6266h10/image_net/' + self.pattern = '*.JPEG' + self.image_files = fnmatch.filter(os.listdir(self.bg_image_dir),self.pattern) # get threshold value def get_settings_names(self): @@ -51,11 +52,9 @@ # select a random background image from "bg_image_dir" and crops it def rand_bg_image(self): - files = os.listdir(self.bg_image_dir) - image_files = fnmatch.filter(files, self.pattern) - i = random.randint(0, len(image_files) - 1) + i = random.randint(0, len(self.image_files) - 1) - image = self.load_image(self.bg_image_dir + image_files[i]) + image = self.load_image(self.bg_image_dir + self.image_files[i]) self.bg_image = self.rand_crop(image) # set "bg_image" as background to "image", based on a pixels threshold