This is my code to transform my handwriting picutures:
def changeData(path = "./mynum/num/"):
    # path = "./mynum/num/"
    dir_or_files = os.listdir(path)
    files = []
    for dir_file in os.listdir(path):
        files.append(dir_file)
        
    MNIST_SIZE = 28
    datas = []
    labels = []
    for file in files:
        # transform pictures
        # print(path+files[0])
        # read the image and trun to gray
        img = io.imread(path+file, as_gray=True)
        # resize to 28*28
        translated_img = transform.resize(img, (MNIST_SIZE, MNIST_SIZE))
        # change to 1*784 array
        flatten_img = np.reshape(translated_img, 784)
        # 1 is black，0 is whtie
        result = np.array([1 - flatten_img])
        # get the label
        labels.append([int(file[-5])])
        datas.append(result)
        print(file)
    datas = np.array(datas)
    labels = np.array(labels)
    return datas, labels

The picture’s name is set like “03_3.png”.The 03 before _ is ID, the 3 after _ 3 is the real number of the picture.
The full code link. 8