-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathline_labler.py
More file actions
35 lines (26 loc) · 1.15 KB
/
line_labler.py
File metadata and controls
35 lines (26 loc) · 1.15 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
import numpy as np
import cv2
import matplotlib
matplotlib.use('Agg') # Must be before importing matplotlib.pyplot or pylab!
import matplotlib.pyplot as plt
def histogram(train_no):
angles = [np.degrees(cv2.HoughLines(cv2.Canny(sample,50,150,apertureSize = 3),1,np.pi/180,10)[0][0][1]) for sample in (np.load("y_gen.npy")*255).astype(np.uint8).reshape(-1,28,28)]
hist = np.histogram(angles)
fig = plt.figure()
plt.bar(hist[1][:-1], hist[0])
fig.savefig("histogram_%d.png" % train_no)
# for i, sample in enumerate((np.load("x_gen.npy")*255).astype(np.uint8).reshape(-1,28,28)[:100]):
# edges = cv2.Canny(sample,50,150,apertureSize = 3)
# color = cv2.cvtColor(sample,cv2.COLOR_GRAY2BGR)
# lines = cv2.HoughLines(edges,1,np.pi/180,10)
# for rho,theta in lines[0]:
# a = np.cos(theta)
# b = np.sin(theta)
# x0 = a*rho
# y0 = b*rho
# x1 = int(x0 + 1000*(-b))
# y1 = int(y0 + 1000*(a))
# x2 = int(x0 - 1000*(-b))
# y2 = int(y0 - 1000*(a))
# cv2.line(color,(x1,y1),(x2,y2),(0,0,255),2)
# cv2.imwrite('houghlines%d.jpg' % i,color)