We often need to work within the image directly and not as an array vector. This section will guide us through converting our arrays to .png
images.
Exporting the vectors to images requires importing the following library:
import image from matplotlib
This section walks through the steps to convert a sample of MNIST arrays to files in a local folder.
- Create a subfolder to save our images to our main folder of
MNIST/
using the following script:
if not os.path.exists('MNIST/images'): os.makedirs('MNIST/images/') os.chdir('MNIST/images/')
- Loop through the first 10 samples of MNIST arrays and convert them to
.png
files using the following script:
from matplotlib import image for i in range(1,10): png = data.train.images[i] png = np.array(png, dtype='float') pixels = png.reshape((28, 28)) image.imsave('image_no_{}.png'.format(i), pixels, cmap = 'gray')
- Execute the following script to see the list of images...