summaryrefslogtreecommitdiff
path: root/merge_frames.py
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 /merge_frames.py
parent386386473d905f4f7b03daa02cfecdadfc78b631 (diff)
fixies
Diffstat (limited to 'merge_frames.py')
-rw-r--r--merge_frames.py17
1 files changed, 12 insertions, 5 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])))