Created
February 22, 2019 10:09
-
-
Save ialhashim/736424b598553ea8e2444b57c288b245 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
print(target.shape) | |
def process_file(i): | |
file = files[i] | |
cx,cy = coords(file) | |
xi, yi = cx[0]//size, cy[0]//size | |
x = np.clip(np.asarray(Image.open( 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