File size: 695 Bytes
5ab6d2e
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env python3
"""prep.py - makes a benchmark original from a public dataset photo: the centre square of the photo, BICUBIC-resized to the set's side
(1024 or 512 px, Pillow), RGB. check.py --sources rebuilds every original this way and compares its pixels with the photo's info.json.

  python3 scripts/prep.py SRC_FILE OUT.png SIZE"""
import sys
from PIL import Image

def prep(src, out, size):
  im = Image.open(src).convert('RGB'); w, h = im.size; s = min(w, h)
  im = im.crop(((w - s) // 2, (h - s) // 2, (w - s) // 2 + s, (h - s) // 2 + s)).resize((size, size), Image.BICUBIC); im.save(out); return im

if __name__ == '__main__':
  prep(sys.argv[1], sys.argv[2], int(sys.argv[3]))