Skip to content

Instantly share code, notes, and snippets.

@christian-rauch
Created January 25, 2017 18:48
Show Gist options
  • Save christian-rauch/61912ac97cd56388d5cebc3a9646ce67 to your computer and use it in GitHub Desktop.
Save christian-rauch/61912ac97cd56388d5cebc3a9646ce67 to your computer and use it in GitHub Desktop.
resize image in parallel by sampling
#!/usr/bin/env python
import skimage.io as io
import warnings
import sys, os
import glob
from joblib import Parallel, delayed
import multiprocessing
def sample(f):
img = io.imread(f)
# only keep ever 4th row and column
img_sampled = img[::4, ::4]
with warnings.catch_warnings():
warnings.simplefilter("ignore")
io.imsave(f, img_sampled)
files = glob.glob(os.path.join(sys.argv[1],'*.png'))
num_cores = multiprocessing.cpu_count()
# start in parallel
Parallel(n_jobs=num_cores)(delayed(sample)(f) for f in files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment