Created
January 25, 2017 18:48
-
-
Save christian-rauch/61912ac97cd56388d5cebc3a9646ce67 to your computer and use it in GitHub Desktop.
resize image in parallel by sampling
This file contains 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
#!/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