@@ -0,0 +1,1508 @@
+#!/usr/bin/python%0A#%0A# Usage: ./create_mat_from_folder.py IMAGE_FOLDER OUTPUT_FILE%0A# %0A# Author : Krit Chaiso%0A#%0A%0Aimport cv2%0Aimport os%0Aimport numpy%0Aimport sys%0A%0Aimport scipy.io as sio%0A%0Aimage_extensions = %5B'.pgm', '.png', '.jpg', '.jpeg'%5D%0A%0Adef get_image_list(folder_name = 'input'):%0A    # get all images from image_folder%0A    images_filename = %5B%5D%0A    for root, dirs, files in os.walk(folder_name):%0A        for file in files:%0A            if file.endswith(tuple(image_extensions)):%0A                images_filename.append(os.path.join(root, file))%0A    return images_filename%0A%0Adef normalize(array, is_sigmoid = False):%0A    mean = numpy.mean(array)%0A    array = array - mean%0A    pstd = 3 * numpy.std(array)%0A    array = numpy.array(%5Bmax(min(pixel, pstd), -pstd)/pstd for pixel in array%5D)%0A    if is_sigmoid:%0A        array = (array+1)*0.4+0.1%0A    else:%0A        array = array*0.9%0A    return array%0A%0Aif __name__ == %22__main__%22:%0A    if len(sys.argv) == 3:%0A        IMAGE_FOLDER = sys.argv%5B1%5D%0A        OUTPUT_FILE = sys.argv%5B2%5D%0A    else:%0A        print %22Usage: ./create_mat_from_folder.py IMAGE_FOLDER OUTPUT_FILE%22%0A        exit(0)%0A%0A    image_list = get_image_list(IMAGE_FOLDER)%0A%0A    train = %5B%5D%0A    # create dataset%0A    for image in image_list:%0A        im = cv2.imread(image, cv2.IMREAD_GRAYSCALE)%0A%0A        h,w = im.shape%0A        im_array = im.reshape(h*w)%0A        im_array = normalize(im_array, is_sigmoid=True)%0A        train.append(im_array)%0A%0A    print len(train)%0A    sio.savemat(OUTPUT_FILE, %7B'train_data':numpy.vstack(train)%7D)%0A%0A

Add generate .mat script