@@ -0,0 +1,1234 @@
+%22%22%22%0ASample code for load the 8000 pre-processed background image data.%0ABefore running, first download the files from:%0A  https://github.com/ankush-me/SynthText#pre-generated-dataset%0A%22%22%22%0A%0Aimport h5py%0Aimport numpy as np%0Afrom PIL import Image%0Aimport os.path as osp%0Aimport cPickle as cp%0A%0Aim_dir = 'bg_img'%0Adepth_db = h5py.File('depth.h5','r')%0Aseg_db = h5py.File('seg.h5','r')%0A%0Aimnames = sorted(depth_db.keys())%0A%0Awith open('imnames.cp', 'rb') as f:%0A  filtered_imnames = set(cp.load(f))%0A%0Afor imname in imnames:%0A  # ignore if not in filetered list:%0A  if imname not in filtered_imnames: continue%0A  %0A  # get the colour image:%0A  img = Image.open(osp.join(imname)).convert('RGB')%0A  %0A  # get depth:%0A  depth = depth_db%5Bimname%5D%5B:%5D.T%0A  depth = depth%5B:,:,0%5D%0A%0A  # get segmentation info:%0A  seg = seg_db%5B'mask'%5D%5Bimname%5D%5B:%5D.astype('float32')%0A  area = seg_db%5B'mask'%5D%5Bimname%5D.attrs%5B'area'%5D%0A  label = seg_db%5B'mask'%5D%5Bimname%5D.attrs%5B'label'%5D%0A%0A  # re-size uniformly:%0A  sz = depth.shape%5B:2%5D%5B::-1%5D%0A  img = np.array(img.resize(sz,Image.ANTIALIAS))%0A  seg = np.array(Image.fromarray(seg).resize(sz,Image.NEAREST))%0A  %0A  # see %60gen.py%60 for how to use img, depth, seg, area, label for further processing.%0A  #    https://github.com/ankush-me/SynthText/blob/master/gen.py%0A

Create use_preproc_bg.py