Skip to content

Instantly share code, notes, and snippets.



Created Feb 22, 2019
What would you like to do?
from joblib import Parallel, delayed
import numpy as np
from skimage.transform import resize
files = list(data.keys())[1:]
def coords(filename):
filename = filename.replace('11_1024/', '').replace('.jpg', '').replace('11_', '')
filename = filename.replace('[','').replace(']','').split('_')
x,y = filename[0].split('-'), filename[1].split('-')
ix, iy = [int(x[0]),int(x[1])], [int(y[0]),int(y[1])]
return ix,iy
def paste(y, x, img, target, size):
target[y*size:(y+1)*size, x*size:(x+1)*size, :] = img
count_x, count_y = 800, 500
size = 6
water = np.array((9/255,25/255,38/255)).reshape((1,1,3))
#target = np.zeros((count_y*size,count_x*size,3))
target = np.repeat(water, (count_y*size*count_x*size), axis=0).reshape((count_y*size,count_x*size,3))
def process_file(i):
file = files[i]
cx,cy = coords(file)
xi, yi = cx[0]//size, cy[0]//size
x = np.clip(np.asarray( BytesIO(data[file]) )).reshape(1024,1024,3)/255,0,1)
x_resized = resize(x, (size, size), preserve_range=True, mode='reflect', anti_aliasing=True)
paste(yi, xi, x_resized, target, size)
Parallel(n_jobs=40,verbose=1, require='sharedmem')(delayed(process_file)(i) for i in range(len(files)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment