subsampling images to prevent OOM errors