Commit 1b8c72fb authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

enabling several tiles at one location w/ same augmentation

parent be5eae2f
......@@ -5,7 +5,7 @@ from skimage import io, img_as_float, img_as_ubyte
from PIL import Image
import numpy as np
import uuid
from osmaug.dictionnary.dictionnary_tf import augm_dict
from osmaug.dictionnary.dictionnary_tf import augm_param_dict,augm_dict
from osmaug.transformation.crop import crop
def collosm_function(params: Dict):
......@@ -17,21 +17,30 @@ def collosm_function(params: Dict):
os.mkdir(resdir)
df = pd.read_csv(params['file']['name'],sep=',')
df['ID'] = df['ID'].apply(str)
zoom = pd.DataFrame.from_dict(params['osm'], orient='columns')
filenames = {}
for index_zoom, row_zoom in zoom.iterrows():
filename_tmp = []
for index, row in df.iterrows():
filename = row['ID']+'_zoom_'+row_zoom['zoom']+'.jpg'
tile = pd.DataFrame.from_dict(params['tile'], orient='columns')
# getting the dimension of each tile. Assuming all tiles get identical dimensions
filename = df.loc[0,'ID']+'_'+tile.loc[0,'name']+'_zoom_'+tile.loc[0,'zoom']+'.jpg'
img = img_as_float(io.imread(os.path.join(workdir,filename)))
img_shape = img.shape
res = pd.DataFrame()
for index, row in df.iterrows():
# identic augmentation for all the tiles at the same location
id_augm = str(uuid.uuid4().hex)
augm_param = augm_param_dict[params['augmentation']['augmentation']]
augm = augm_dict[params['augmentation']['augmentation']]
augm_matrix = augm_param(img_shape[0],img_shape[1])
for index_tile, row_tile in tile.iterrows():
filename = row['ID']+'_'+row_tile['name']+'_zoom_'+row_tile['zoom']+'.jpg'
print(filename)
img = img_as_float(io.imread(os.path.join(workdir,filename)))
augm = augm_dict[params['augmentation']['augmentation']]
img = augm(img)
img = augm(img,augm_matrix)
img = crop(img, delta=params['augmentation']['delta_pixel'])
filename_aug = str(uuid.uuid4().hex)+'_'+filename
filename_aug = id_augm+'_'+filename
Image.fromarray(img_as_ubyte(img)).save(os.path.join(res_img_dir,filename_aug))
filename_tmp.append(filename_aug)
filenames['z'+row_zoom["zoom"]] = filename_tmp
df_file = pd.DataFrame(filenames)
res = pd.concat([df.reset_index(drop=True), df_file], axis=1)
#filename_tmp.append(filename_aug)
res.loc[index,row_tile["name"]+'_'+row_tile["zoom"]] = filename_aug
#df_file = pd.DataFrame(filenames)
res = pd.concat([df.reset_index(drop=True), res], axis=1)
res.to_csv(os.path.join(res_data_dir,'dataset.csv'))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment