Mercurial > ift6266
comparison transformations/add_background_image.py @ 70:be24db3a4d6e
bug fix in reading pkl image list file
author | Xavier Glorot <glorotxa@iro.umontreal.ca> |
---|---|
date | Wed, 10 Feb 2010 00:38:54 -0500 |
parents | 6d87c0df2b0e |
children | 53ee1097c02c |
comparison
equal
deleted
inserted
replaced
69:6d87c0df2b0e | 70:be24db3a4d6e |
---|---|
14 class AddBackground(): | 14 class AddBackground(): |
15 def __init__(self, threshold = 128): | 15 def __init__(self, threshold = 128): |
16 self.h = 32 | 16 self.h = 32 |
17 self.w = 32 | 17 self.w = 32 |
18 self.threshold = threshold; | 18 self.threshold = threshold; |
19 self.bg_image_file = '/data/lisa/data/ift6266h10/image_net/filelist.pkl' | 19 self.bg_image_file = '/data/lisa/data/ift6266h10/image_net/' |
20 f=open(self.bg_image_file) | 20 f=open(self.bg_image_file+'filelist.pkl') |
21 self.image_files = cPickle.load(f) | 21 self.image_files = cPickle.load(f) |
22 f.close() | 22 f.close() |
23 | 23 |
24 # get threshold value | 24 # get threshold value |
25 def get_settings_names(self): | 25 def get_settings_names(self): |
50 def rand_crop(self,image): | 50 def rand_crop(self,image): |
51 i_w, i_h = image.shape | 51 i_w, i_h = image.shape |
52 x, y = random.randint(0, i_w - self.w), random.randint(0, i_h - self.h) | 52 x, y = random.randint(0, i_w - self.w), random.randint(0, i_h - self.h) |
53 return image[x:x + self.w, y:y + self.h] | 53 return image[x:x + self.w, y:y + self.h] |
54 | 54 |
55 # select a random background image from "bg_image_dir" and crops it | 55 # select a random background image from "bg_image_file" and crops it |
56 def rand_bg_image(self): | 56 def rand_bg_image(self): |
57 i = random.randint(0, len(self.image_files) - 1) | 57 i = random.randint(0, len(self.image_files) - 1) |
58 | 58 |
59 image = self.load_image(self.bg_image_dir + self.image_files[i]) | 59 image = self.load_image(self.bg_image_file + self.image_files[i]) |
60 self.bg_image = self.rand_crop(image) | 60 self.bg_image = self.rand_crop(image) |
61 | 61 |
62 # set "bg_image" as background to "image", based on a pixels threshold | 62 # set "bg_image" as background to "image", based on a pixels threshold |
63 def set_bg(self,image): | 63 def set_bg(self,image): |
64 b = (image < self.threshold / 255.0).astype(numpy.float32) | 64 b = (image < self.threshold / 255.0).astype(numpy.float32) |