-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_image.py
42 lines (37 loc) · 913 Bytes
/
make_image.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
import cv2
import numpy as np
import os
k = 0
mif = open('image.mif', 'w')
def colorToVec9 (color):
# (g, r, b) 0~255
v = 0
v |= color[0] >> 5
v |= color[1] >> 5 << 3
v |= color[2] >> 5 << 6
return v
def writeImage (imagePath):
global k, mif
try:
image = cv2.imread(imagePath)
image = cv2.resize(image, (16, 16))
(m, n, _) = image.shape
for i in range(m):
for j in range(n):
mif.write('\t%03X : %03o;\n' % (k, colorToVec9( image[i, j] )))
k += 1
except:
for i in range(16):
for j in range(16):
mif.write('\t%03X : %03o;\n' % (k, 0))
k += 1
image_num = 64
mif.write('-- Generated by make_image.py\n\n')
mif.writelines(['WIDTH=9;\n', 'DEPTH=%d;\n' % (16*16*image_num), 'ADDRESS_RADIX=HEX;\n', 'DATA_RADIX=OCT;\n'])
mif.write('\n')
mif.write('CONTENT BEGIN\n')
for i in range(image_num):
path = './images/%d.png' % i
print(path)
writeImage(path)
mif.write('END;\n')