-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathdefect_detection_visualization.py
More file actions
147 lines (104 loc) · 4.85 KB
/
defect_detection_visualization.py
File metadata and controls
147 lines (104 loc) · 4.85 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import cv2
from detect_defects import calc_error
import matplotlib.image as mpimg
from stats_of_cloth import *
from scipy.stats import gaussian_kde
def paintDefects_warps(file_name, robust_cov, threshold=30):
float_points_list = pickle.load(open(file_name, "rb" ))
for pt in float_points_list:
pt.faulty=False
#update distances, since they were changed
float_points_list.calcDistances()
x_vals = [fp.x for fp in float_points_list]
y_vals = [fp.y for fp in float_points_list]
mean_ver_dist = float_points_list.getMedianWarpDist()
min_x = min(x_vals) + 0.5*mean_ver_dist
max_x = max(x_vals) - 0.5*mean_ver_dist
min_y = min(y_vals) + 1.2*mean_ver_dist
max_y = max(y_vals) - 1.2*mean_ver_dist
inner_points = floatPointList()
for pt in float_points_list:
if min_x < pt.x < max_x and min_y < pt.y < max_y:
inner_points.append(pt)
X = np.zeros([len(inner_points),3])
for idx, pt in enumerate(inner_points):
X[idx, 0] = pt.area
X[idx, 1] = pt.lower_dist
X[idx, 2] = pt.upper_dist
fault_count, faulty_points = calc_error(X, inner_points, robust_cov, threshold)
x = np.zeros(faulty_points.__len__())
y = np.zeros(faulty_points.__len__())
for idx, myFloatPoint in enumerate(faulty_points):
x[idx] = myFloatPoint.x
y[idx] = myFloatPoint.y
#ax.plot(myFloatPoint.x, myFloatPoint.y, color='red', marker='s', markersize=30, alpha=0.15)
# Calculate the point density
xy = np.vstack([x, y])
z = gaussian_kde(xy)(xy)
# Sort the points by density, so that the densest points are plotted last
idx = z.argsort()
x, y, z = x[idx], y[idx], z[idx]
ax.scatter(x, y, color='red')# c=z, marker='s', s=500, edgecolor='', alpha=0.5)
x=3
def paintDefects_wefts(file_name, robust_cov, threshold=30):
float_points_list = pickle.load(open(file_name, "rb" ))
for pt in float_points_list:
pt.faulty=False
#update distances, since they were changed
float_points_list.calcDistances()
x_vals = [fp.x for fp in float_points_list]
y_vals = [fp.y for fp in float_points_list]
mean_hor_dist = float_points_list.getMedianWeftDist()
min_x = min(x_vals) + 1.2*mean_hor_dist
max_x = max(x_vals) - 1.2*mean_hor_dist
min_y = min(y_vals) + .5*mean_hor_dist
max_y = max(y_vals) - .5*mean_hor_dist
inner_points = floatPointList()
for pt in float_points_list:
if min_x < pt.x < max_x and min_y < pt.y < max_y:
inner_points.append(pt)
X = np.zeros([len(inner_points),3])
for idx, pt in enumerate(inner_points):
X[idx,0] = pt.area
X[idx,1] = pt.right_dist
X[idx,2] = pt.left_dist
fault_count, faulty_points = calc_error(X, inner_points, robust_cov, threshold)
x = np.zeros(faulty_points.__len__())
y = np.zeros(faulty_points.__len__())
for idx, myFloatPoint in enumerate(faulty_points):
x[idx] = myFloatPoint.x
y[idx] = myFloatPoint.y
#ax.plot(myFloatPoint.x, myFloatPoint.y, color='red', marker='s', markersize=30, alpha=0.15)
# Calculate the point density
xy = np.vstack([x, y])
z = gaussian_kde(xy)(xy)
# Sort the points by density, so that the densest points are plotted last
idx = z.argsort()
x, y, z = x[idx], y[idx], z[idx]
ax.scatter(x, y, color='red')# c=z, marker='s', s=500, edgecolor='', alpha=0.5)
#plt.show()
x=3
#######################################################################################################################
#######################################################################################################################
threshold=30
warp_path = 'V:/ITA/MA_weninger/plain_weave/Fabric1/yarns_corrected/c0130c___warp.p'
weft_path = 'V:/ITA/MA_weninger/plain_weave/Fabric1/yarns_corrected/c0130c___weft.p'
image = mpimg.imread('V:/ITA/MA_weninger/plain_weave/Fabric1/test_images/fl0130c.png')
robust_cov_warp = pickle.load(open('V:/ITA/MA_weninger/plain_weave/Fabric1/MCD_warp.p', "rb"))
robust_cov_weft = pickle.load(open('V:/ITA/MA_weninger/plain_weave/Fabric1/MCD_weft.p', "rb"))
target_name = 'Y:\temp\test'
fig, ax = plt.subplots(figsize=(10, 10))
axes = plt.gca()
axes.invert_yaxis()
if image is not None:
plt.axis('off')
plt.imshow(image)
axes.set_xlim(left=0, right=1900)
axes.set_ylim(top=0, bottom=1900)
paintDefects_wefts(file_name=weft_path, robust_cov=robust_cov_weft, threshold=threshold)
paintDefects_warps(file_name=warp_path, robust_cov=robust_cov_warp, threshold=threshold)
plt.show()
x=3
# dens00e, density01e, dens10e, dens11e = detectDefects_wefts(file_name=weft_path, target_name=target_name_weft,
# robust_cov=robust_cov_weft, write_images=False,
# image=fl_im, threshold=threshold1)