-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShow1 (1).py
More file actions
190 lines (154 loc) · 4.97 KB
/
Show1 (1).py
File metadata and controls
190 lines (154 loc) · 4.97 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import matplotlib.image as img
import pathlib
import warnings
warnings.filterwarnings('ignore')
import cv2
import pickle
from numpy import linalg as LA
from tkinter import *
from tkinter import messagebox
import os
import cv2
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
pd.options.mode.chained_assignment = None # default='warn'
from PIL import Image
from tqdm import tqdm
import pickle
#from skimage.feature import greycomatrix,greycoprops --OLD vERSION
from skimage.feature import graycomatrix, graycoprops
import skimage.feature as feature
import easygui
def fxnglcm(img,i,df):
cv2.imwrite('0.png', img)
img=cv2.imread('0.png',0)
print(np.shape(img))
graycom = feature.graycomatrix(img, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4], levels=256)
c = feature.graycoprops(graycom, 'contrast')
d = feature.graycoprops(graycom, 'dissimilarity')
h = feature.graycoprops(graycom, 'homogeneity')
e = feature.graycoprops(graycom, 'energy')
corr = feature.graycoprops(graycom, 'correlation')
ASM = feature.graycoprops(graycom, 'ASM')
c = np.squeeze(c)
d = np.squeeze(d)
h = np.squeeze(h)
e = np.squeeze(e)
corr = np.squeeze(corr)
asm = np.squeeze(ASM)
df["GLCM-Contrast-1"][i] = c[0]
df["GLCM-Contrast-2"][i] = c[1]
df["GLCM-Contrast-3"][i] = c[2]
df["GLCM-Contrast-4"][i] = c[3]
df["GLCM-Dissimilarity-1"][i] =d[0]
df["GLCM-Dissimilarity-2"][i] =d[1]
df["GLCM-Dissimilarity-3"][i] =d[2]
df["GLCM-Dissimilarity-4"][i] =d[3]
df["GLCM-Homogeneity-1"][i] =h[0]
df["GLCM-Homogeneity-2"][i]=h[1]
df["GLCM-Homogeneity-3"][i] =h[2]
df["GLCM-Homogeneity-4"][i] =h[3]
df["GLCM-Energy-1"][i] =e[0]
df["GLCM-Energy-2"][i] =e[1]
df["GLCM-Energy-3"][i] =e[2]
df["GLCM-Energy-4"][i] =e[3]
df["GLCM-Correlation-1"][i] =corr[0]
df["GLCM-Correlation-2"][i] =corr[1]
df["GLCM-Correlation-3"][i] =corr[2]
df["GLCM-Correlation-4"][i] =corr[3]
df["GLCM-ASM-1"][i] =asm[0]
df["GLCM-ASM-2"][i] =asm[1]
df["GLCM-ASM-3"][i] =asm[2]
df["GLCM-ASM-4"][i] =asm[3]
return df
def glcmfiller(imgarr,i,gry,df):
if imgarr.shape !=(224, 224):
og = cv2.cvtColor(imgarr,cv2.COLOR_BGR2GRAY)
fxnglcm(og,i,df)
df["gry"][i] = og
else:
fxnglcm(imgarr,i,df)
df["gry"][i] = imgarr
return
file= open("model.h5",'rb')
TRNFV = pickle.load(file)
file.close()
def Calc_Wt(TRR,TST):
WTRN = TRR
R, C = np.shape(WTRN)
M = []
ERR = []
WTST = TST
R, C = np.shape(WTRN)
print('RC',np.shape(WTRN))
for i in range(0, C):
RR = WTRN[:,i]
Temp = np.subtract(WTST, RR)
ERR = LA.norm(Temp)
M.append(ERR)
ind = np.argmin(M);
return ind
from tkinter import filedialog
# VIDEO READ
fnam= filedialog.askopenfilename(filetypes = (("BROWSE ", "*.png"), ("All files", "*")))
# -----------------------------------------------
# MAIN CODE
# -----------------------------------------------
# READ IMAGE
img=cv2.imread(fnam)
a=img
cv2.imshow('INPUT IMAGE',img)
cv2.waitKey(100)
cv2.destroyAllWindows()
# RESIZING
img = cv2.resize(img,(256,256),3)
cv2.imshow('RESIZED IMAGE',img)
cv2.waitKey(100)
cv2.destroyAllWindows()
# MEDIAN FILTERED
img1 = cv2.medianBlur(img,5)
cv2.imshow('MEDIAN IMAGE',img1)
cv2.waitKey(100)
cv2.destroyAllWindows()
file= open("model.h5",'rb')
CNN = pickle.load(file)
file.close()
#CNN=np.transpose(CNN)
img= cv2.cvtColor(a,cv2.COLOR_BGR2GRAY)
graycom = feature.graycomatrix(img, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4], levels=256)
c = feature.graycoprops(graycom, 'contrast')
d = feature.graycoprops(graycom, 'dissimilarity')
h = feature.graycoprops(graycom, 'homogeneity')
e = feature.graycoprops(graycom, 'energy')
corr = feature.graycoprops(graycom, 'correlation')
ASM = feature.graycoprops(graycom, 'ASM')
c = np.squeeze(c)
d = np.squeeze(d)
h = np.squeeze(h)
e = np.squeeze(e)
corr = np.squeeze(corr)
asm = np.squeeze(ASM)
FV=[c,d,h,e,corr,asm]
FV=np.ravel(FV)
print('index',np.shape(FV),np.shape(CNN))
n=Calc_Wt(CNN,FV)
print('index',n)
if n<=50:
Dis='NO'
else:
Dis='YES'
print('-------------------------------------------------------\n')
print(' ',Dis,' \n')
print('-------------------------------------------------------\n')
if n<=50:
Dis='NORMAL'
easygui.msgbox(" RESULT --> NORMAL... !", title="simple gui")
else:
Dis='TB PRESENT'
easygui.msgbox(" RESULT --> TB PRESENT !", title="simple gui")
print('-------------------------------------------------------\n')
print(' ',Dis,' \n')
print('-------------------------------------------------------\n')