def _get_image_files(self, path): ''' Each path should contain a data and labels folder containing images. Creates a list of tuples containing path name for data and label. ''' tiles = util.get_image_files(os.path.join(path, 'data')) labels = util.get_image_files(os.path.join(path, 'labels')) self._is_valid_dataset(tiles, labels) return list(zip(tiles, labels))
def calculate_std_from_dataset(path, dataset): #dataset = util.get_dataset(path) variance = [] #for set in dataset: folder_path = os.path.join(path, dataset, 'data') tiles = util.get_image_files(folder_path) samples = [] i = 0 for tile in tiles: i += 1 print(tile) im = Image.open(os.path.join(folder_path, tile), 'r') s, v = get_image_estimate(im) samples.append(s) variance.append(v) if (i % 10 == 0): print("Progress", i) #Average standard deviation by averaging the variances and taking square root of average. #Source: http://bit.ly/1VS5pmT combined = np.concatenate(samples) print("Real std", np.std(combined)) dataset_std = np.sqrt(np.sum(variance) / len(variance)) return dataset_std
def calculate_std_from_dataset(path, dataset): #dataset = util.get_dataset(path) variance = [] #for set in dataset: folder_path = os.path.join(path, dataset, 'data') tiles = util.get_image_files(folder_path) samples = [] i = 0 for tile in tiles: i += 1 print(tile) im = Image.open(os.path.join(folder_path, tile), 'r') s, v = get_image_estimate(im) samples.append(s) variance.append(v) if(i%10 == 0): print("Progress", i) #Average standard deviation by averaging the variances and taking square root of average. #Source: http://bit.ly/1VS5pmT combined = np.concatenate(samples) print("Real std" , np.std(combined)) dataset_std = np.sqrt(np.sum(variance) / len(variance)) return dataset_std
os.makedirs(sub_dir + "/data") dataset_base = "/home/olav/Pictures/Norwegian_roads_dataset" dataset_dest = "/home/olav/Pictures/Norwegian_roads_dataset_alpha" datasets = loader.get_dataset(dataset_base) color_to_alpha = False content = ["data"] create_dataset_structure(dataset_dest, datasets) for set in datasets: for t in content: rel_path = "/" + set + "/" + t images = loader.get_image_files(dataset_base + rel_path) for img_path in images: src_path = dataset_base + rel_path + "/" + img_path dest_path = dataset_dest + rel_path + "/" + img_path src_im = Image.open(src_path) im = src_im.convert('RGBA') if color_to_alpha: pixel_data = im.load() height = im.size[1] width = im.size[0] for y in xrange(height): # For each row ... for x in xrange(width): # Iterate through each column ...