-
Notifications
You must be signed in to change notification settings - Fork 1
/
thermal_analysis.py
73 lines (48 loc) · 1.59 KB
/
thermal_analysis.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
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
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import numpy as np
import math
import matplotlib.pyplot as plt
#==========[Parameters]============
OUTPUT_W=24*2
OUTPUT_H=32*2
HEIGHT=500
WIDTH=500
#==========[Test center list]============
center_list=[[5,7],[75,86],[300,460]]
#==========[Functions]============
def get_matrix():
matrix=[]
thermal_matrix = open('tmatrix.txt').read()
thermal_matrix = [item.split() for item in matrix.split(' ')[:-1]]
for item in thermal_matrix:
matrix.append(float(item[0]))
thermal_matrix.close()
return matrix
def preprocess_matrix(matrix):
matrix=np.asarray(matrix, dtype=np.float32)
matrix=np.reshape(matrix, (OUTPUT_W, OUTPUT_H))
matrix=matrix.transpose()
matrix=np.flip(matrix, 1)
return matrix
def check_matrix(c_list,matrix):
for pt in c_list:
cX=pt[0]
cY=pt[1]
new_cX=math.trunc(cX*OUTPUT_W/width)
new_cY=math.trunc(cY*OUTPUT_H/HEIGHT)
for x in range(new_cX-3,new_cX+3):
if x>=0 and x<OUTPUT_W :
for y in range(new_cY-3,new_cY+3):
if y>=0 and y<OUTPUT_H :
if matrix[x][y]>40:
print("Defect in {},{} \n".format(cX,cY))
defect_centers.append([cX,cY])
return defect_centers
#==========[Main]============
while(1) :
defect_centers=[]
current_matrix= get_matrix()
current_matrix= preprocess_matrix(current_matrix)
defect_centers= check_matrix(center_list,current_matrix)