forked from chaitusvk/chamanti_ocr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
print_utils.py
49 lines (45 loc) · 1.44 KB
/
print_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
def pprint(slab):
if slab.max() == 255:
pprint_(slab/255.)
else:
pprint_(slab)
def pprint_(slab):
"""
Prints a 'slab' of printed 'text' using ascii.
:param slab: A matrix of floats from [0, 1]
"""
for ir, r in enumerate(slab):
print('{:2d}¦'.format(ir), end='')
for val in r:
if val < 0.0: print('-', end='')
elif val < .15: print(' ', end=''),
elif val < .35: print('░', end=''),
elif val < .65: print('▒', end=''),
elif val < .85: print('▓', end=''),
elif val <= 1.: print('█', end=''),
else: print('+', end='')
print('¦')
def pprint_ascii(nparr):
print('-' * (len(nparr[0]) + 5))
for ir, r in enumerate(nparr):
print('{:3d}|'.format(ir), end='')
for c in r:
if c == 0: v = ' '
elif c < .2: v = '.'
elif c < .4: v = '*'
elif c < .6: v = 'o'
elif c < .8: v = '0'
elif c < 1: v = '@'
else: v = '#'
print(v, end='')
print('|')
print('-' * (len(nparr[0]) + 5))
def pprint_binary(nparr):
print('-' * (len(nparr[0]) + 5))
for ir, r in enumerate(nparr):
print('{:3d}|'.format(ir), end='')
for p in r:
print([' ', '#'][1 * p], end='')
print('|')
print('-' * (len(nparr[0]) + 5))