-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadBinFile.py
37 lines (31 loc) · 952 Bytes
/
loadBinFile.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
import numpy as np
import os
import matplotlib.pyplot as plt
# data directory
input = os.getcwd() + "/data/data.bin"
imageSize = 32
labelSize = 1
imageDepth = 3
debugEncodedImage = True
# show given image on the window for debug
def showImage(r, g, b):
temp = []
for i in range(len(r)):
temp.append(r[i])
temp.append(g[i])
temp.append(b[i])
show = np.array(temp).reshape(imageSize, imageSize, imageDepth)
plt.imshow(show, interpolation='nearest')
plt.show()
def showImageWithData(data, offset):
eachColorSize = imageSize * imageSize
offset = labelSize + (labelSize + eachColorSize * 3) * offset
rgb = []
for i in range(3):
color = eachColorSize * i
rgbData = data[offset + color : offset + color + eachColorSize]
rgb.append(rgbData)
showImage(rgb[0], rgb[1], rgb[2])
for i in range(3):
data = np.fromfile(input, dtype='u1')
showImageWithData(data, i)