summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-01-15 20:35:32 +0100
committerJules Laplace <julescarbon@gmail.com>2019-01-15 20:35:32 +0100
commitafd063ed2a80b4318bbcaa4ab5df489ab4efd6bd (patch)
tree2936cfee8b6c934342e056392212832e5575230d
parent386386473d905f4f7b03daa02cfecdadfc78b631 (diff)
fixies
-rw-r--r--merge_frames.py17
-rw-r--r--test.py3
2 files changed, 14 insertions, 6 deletions
diff --git a/merge_frames.py b/merge_frames.py
index c413b97..f26ed9a 100644
--- a/merge_frames.py
+++ b/merge_frames.py
@@ -5,8 +5,10 @@ import operator
from multiprocessing import Pool, cpu_count
from shutil import rmtree
from PIL import Image
+from math import floor
parser = argparse.ArgumentParser()
+parser.add_argument('--step', default=256, type=int)
parser.add_argument('--overlap', default=2, type=int)
parser.add_argument('--scale', default=4, type=int)
parser.add_argument('dir', metavar='dir', help='Directory to process')
@@ -21,11 +23,11 @@ def merge_files(file, crop_dir_list, ww, hh, overlap, merge_dir):
print(fn)
canvas = Image.new('RGB', (ww, hh,))
for crop_dir_tuple in crop_dir_list:
- x, y, w, h = crop_dir_tuple
+ x, y, w, h, ix, iy = crop_dir_tuple
crop_dir = "crop_{}_{}_{}_{}".format(x, y, w, h)
image = Image.open("{}/{}/{}".format(args.dir, crop_dir, fn))
- crop = image.crop((overlap, overlap, image.size[0] - overlap * 2, image.size[1] - overlap * 2))
- canvas.paste(crop, (x * args.scale, y * args.scale,))
+ crop = image.crop((overlap, overlap, image.size[0] - overlap, image.size[1] - overlap))
+ canvas.paste(crop, ((x - (ix * args.overlap)) * args.scale, (y - (iy * args.overlap)) * args.scale,))
canvas.save("{}/{}".format(merge_dir, fn))
def merge_dir():
@@ -44,13 +46,18 @@ def merge_dir():
if x == 0:
hh = max(y + h - args.overlap * 2, hh)
if y == 0:
- ww = max(x + w - args.overlap * 2, ww)
- crop_dir_list.append((x, y, w, h,))
+ ww = max(x + w - args.overlap * 2, ww)
+ ix = 0 if x == 0 else 1 # floor(x / args.step)
+ iy = floor(y / args.step)
+ crop_dir_list.append((x, y, w, h, ix, iy))
crop_dir_list = sorted(crop_dir_list, key=operator.itemgetter(0, 1))
ww *= args.scale
hh *= args.scale
+ ww -= overlap
+ hh -= overlap
+
print("{}x{}".format(ww, hh))
files = sorted(glob.glob("{}/*.png".format(crop_dirs[0])))
diff --git a/test.py b/test.py
index 3b3db01..eab51b2 100644
--- a/test.py
+++ b/test.py
@@ -49,7 +49,8 @@ def process_dir(dir):
out_path = os.path.join(args.out_dir, dataset, str(args.L) + 'L', part)
render_path = os.path.join(args.out_dir, 'renders')
os.makedirs(out_path, exist_ok=True)
- os.makedirs(render_path, exist_ok=True)
+ if args.mov_from_dirs:
+ os.makedirs(render_path, exist_ok=True)
dir_frames = sorted(glob.glob(os.path.join(dir, '*.png')))
# print(dir_frames)