Skip to content

Instantly share code, notes, and snippets.

@LeeKamentsky
Created August 9, 2015 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeeKamentsky/e7981f9fc8351f29fd43 to your computer and use it in GitHub Desktop.
Save LeeKamentsky/e7981f9fc8351f29fd43 to your computer and use it in GitHub Desktop.
#
# Create and reload an image with
# 0 1 2 3 4 5 6 7 8 9 visible
#
from pylab import *
rcParams['font.family'] = 'monospace'
rcParams['font.size'] = 96
rcParams['figure.figsize'] = (20, 4)
rcParams['figure.subplot.top'] = .9
rcParams['figure.subplot.wspace'] = .2
clf()
title("0 1 2 3 4 5 6 7 8 9")
axis('off')
gcf().savefig("c:/temp/1234567890.png", bbox_inches='tight', pad_inches=1)
i1234567890 = imread("c:/temp/1234567890.png")
#
# Look at it
#
imshow(i1234567890)
#
# Code to view each of the glyphs
# You will have to tweak all of these
# to chop out the text correctly
#
rcParams['font.size'] = 12
w = 80
pad = 58
for i in range(10):
subplot(3, 4, i+1).imshow(i1234567890[70:170, ((w+pad)*i+135):((w+pad)*i+w+135)])
#
# Make the numpy array of the glyphs once the above looks correct
#
a = np.dstack([i1234567890[70:170, ((w+pad)*i+135):((w+pad)*i+w+135), 0]*255 for i in range(10)]).astype(np.uint8)
#
# Order the glyphs so that the glyph index is first
#
a = a.transpose(2, 0, 1)
#
# Show it for copy and paste - you could also write it
# out or do something more intelligent.
#
print a.tolist()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment