#! -*- coding:utf-8 -*-

import os
import sys
import cv2
import numpy as np

def _resizing(img):
    #return cv2.resize(img, (256, 256))
    return cv2.resize(img, (32, 32))

def _reg(img):
    return img/127.5 - 1.0

def _re_reg(img):
    return (img + 1.0) * 127.5

def get_figs(target_dir):
    ret = []
    for file_name in os.listdir(target_dir):
        target_file = os.path.join(target_dir, file_name)
        img = cv2.imread(target_file, 0)
        ret.append(_reg(_resizing(img)))
    return np.asarray(ret, dtype = np.float32)

def dump_figs(figs, dump_dir):
    for i, fig in enumerate(figs):
        target_file = os.path.join(dump_dir, '{}.jpg'.format(i))
        cv2.imwrite(target_file, _re_reg(fig))

[((10, 11, 10, 36), 'cv2.resize', 'cv2.resize', ({(10, 22, 10, 25): 'img', (10, 27, 10, 35): '(32, 32)'}, {}), '(img, (32, 32))', False, 'import cv2\n'), ((20, 21, 20, 43), 'os.listdir', 'os.listdir', ({(20, 32, 20, 42): 'target_dir'}, {}), '(target_dir)', False, 'import os\n'), ((24, 11, 24, 46), 'numpy.asarray', 'np.asarray', (), '', True, 'import numpy as np\n'), ((21, 22, 21, 57), 'os.path.join', 'os.path.join', ({(21, 35, 21, 45): 'target_dir', (21, 47, 21, 56): 'file_name'}, {}), '(target_dir, file_name)', False, 'import os\n'), ((22, 14, 22, 40), 'cv2.imread', 'cv2.imread', ({(22, 25, 22, 36): 'target_file', (22, 38, 22, 39): '0'}, {}), '(target_file, 0)', False, 'import cv2\n')]