In [1]:
import pandas as pd
import numpy as np
import tifffile as tif
import os
import utils
import global_vars
In [2]:
grid_sizes = pd.read_csv(os.path.join(global_vars.DATA_DIR,'grid_sizes.csv'), index_col=0)
train_labels = pd.read_csv(os.path.join(global_vars.DATA_DIR,'train_wkt_v4.csv'), index_col=0)
train_names = list(train_labels.index.unique())
In [4]:
base_size= 835
label_sizes = [base_size, base_size*2, base_size*4]
for im_name in train_names:
for i in range(1, 11):
polys = utils.get_polygon_list(train_labels, im_name, i)
x_max = grid_sizes.loc[im_name,'Xmax']
y_min = grid_sizes.loc[im_name,'Ymin']
for size in label_sizes:
plist, ilist = utils.get_and_convert_contours(polys, (size,size), x_max, y_min)
im_mask = utils.plot_mask((size,size), plist, ilist)
im_mask = im_mask.reshape((size, size, 1))
tif.imsave(os.path.join(global_vars.DATA_DIR,'labels',
im_name + '_' + str(size)+ '_class_' +str(i)+'.tif'), im_mask)