# -*- coding: utf-8 -*-
import sys
import numpy as np
import struct
from PIL import Image
print "hell word"
filename = 't10k-images-idx3-ubyte'
binfile = open(filename,'rb')
buf = binfile.read()
index = 0
magic,numImages,numRows,numColumns = struct.unpack_from('>IIII',buf,index) # 指定类型读取数据,得到图片总数
index += struct.calcsize('>IIII')
for image in range(0,numImages):
im = struct.unpack_from('>784B',buf,index) #读一个图片
index +=struct.calcsize('>784B')
im = np.array(im,dtype = 'uint8')
im = im.reshape(28,28) #像素大小
im = Image.fromarray(im)
im.save('mnist_test/train_%s.bmp'%image,'bmp') #保存转换后的图片格式