-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindDigits.py
More file actions
67 lines (47 loc) · 1.53 KB
/
Copy pathFindDigits.py
File metadata and controls
67 lines (47 loc) · 1.53 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sys
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
import Train
import SimpleNN2
# Load image as grayscale
fileName = r"..\iphonepuzzle_a-600x893.jpg"
img = io.imread(fileName, True)
# Load neural network
(nn, th1, th2) = SimpleNN2.loadNetwork(r"..\networkParams.bin")
# Try 28*28 slices
sliceSizeX = 28
sliceSizeY = 28
xSlices = img.shape[1] // sliceSizeX
ySlices = img.shape[0] // sliceSizeY
imgMod = img.copy()
for x in range(xSlices):
for y in range(ySlices):
xFr = x*sliceSizeX
xTo = xFr + sliceSizeX
yFr = y*sliceSizeY
yTo = yFr + sliceSizeY
subImage = img[yFr:yTo, xFr:xTo]
#prob = SimpleNN2.predictProbability(nn, th1, th2, subImage.flatten()).flatten()
cl = SimpleNN2.predictProbability(nn, th1, th2, subImage.flatten()).flatten()
if cl[3] > 0.25 :
print("Found at ({0},{1})".format(y, x))
imgMod[yFr:yTo, xFr:xTo] *= 0.5
#plt.imshow(subImage.reshape((28,28)))
#break
plt.imshow(img, cmap=cm.gray)
plt.imshow(imgMod, cmap=cm.gray)
#for x in range(xSlices):
# for y in range(ySlices):
# xFr = x*sliceSizeX
# xTo = xFr + sliceSizeX
# yFr = y*sliceSizeY
# yTo = yFr + sliceSizeY
# subImage = img[yFr:yTo, xFr:xTo]
# ax = plt.subplot(ySlices, xSlices, y*xSlices+x+1)
# plt.set_cmap('gray')
# plt.axis('off')
# ax.imshow(subImage.reshape((28,28)))
#plt.subplots_adjust(hspace=-0.85)
#plt.gcf().set_size_inches(9, 9)
#plt.show()