-
Notifications
You must be signed in to change notification settings - Fork 0
/
Eye_of_Eagle.py
212 lines (187 loc) · 9.6 KB
/
Eye_of_Eagle.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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env python
# coding: utf-8
# In[43]:
import os
import cv2
import numpy as np
from IPython import display
import streamlit as st
import pandas as pd
import time
st.sidebar.markdown("<h1 style='text-align: left; color: maroon;'>Plasma-Classification </h1>",unsafe_allow_html=True)
st.sidebar.markdown("<h1 style='text-align: left; color: maroon;'></h1>",unsafe_allow_html=True)
st.sidebar.markdown("<h1 style='text-align: left; color: maroon;'></h1>",unsafe_allow_html=True)
st.sidebar.markdown("<h1 style='text-align: left; color: maroon;'></h1>",unsafe_allow_html=True)
st.sidebar.markdown("<h4 style='text-align: left; color: maroon;'>Select Feature:</h4>",unsafe_allow_html=True)
# In[41]:
feature_name=st.sidebar.selectbox("",("Surface Touch Detection", "Area and Other Features"))
DIR="C:/Users/Pararth Dave/Desktop/DAIICT/sem2/Numerical Method/Project/NM_PRUJECT_WITH_MS"
all_folds=os.listdir(DIR)
all_folds.sort()
LOC=DIR+"/"+all_folds[11]
all_files=os.listdir(LOC)
all_files.sort()
LOC=DIR+"/"+all_folds[11]
all_files=os.listdir(LOC)
all_files.sort()
# In[22]:
if feature_name=="Surface Touch Detection":
image_holder = st.empty()
text_holder=st.empty()
text_holder5=st.empty()
text_holder1=st.empty()
text_holder2=st.empty()
text_holder3=st.empty()
text_holder4=st.empty()
text_holder.text("")
text_holder5.text("")
text_holder1.text("")
text_holder2.text("")
text_holder3.text("")
text_holder4.text("")
# if feature_name=Surface Touch Detection
img = cv2.imread(LOC+"/"+all_files[10],cv2.IMREAD_GRAYSCALE)
vecR=np.array([1 for i in range(img.shape[1])])
vecC=np.array([1 for i in range(img.shape[0])])
for i in all_files:
img = cv2.imread(LOC+"/"+i,cv2.IMREAD_GRAYSCALE)
ret,img = cv2.threshold(img,50,255,cv2.THRESH_TOZERO)
# plt.imshow(img,cmap=plt.get_cmap('gray'))
# plt.show()
norm_row=img.dot(vecR)
norm_col=img.T.dot(vecC)
image_holder.image(img,width=400)
# time.sleep(5000)
if max(norm_row)>100 or max(norm_col)>100:
text_holder.markdown("<h3 style='text-align: left; color: green;'>Plasma is touching the surface!</h3>",unsafe_allow_html=True)
else:
text_holder.markdown("<h3 style='text-align: left; color: red;'>Plasma is not touching the surface!</h3>",unsafe_allow_html=True)
time.sleep(0.2)
# st.pyplot(plt)
# In[32]:
elif feature_name=="Area and Other Features":
image_holder = st.empty()
text_holder=st.empty()
text_holder5=st.empty()
text_holder1=st.empty()
text_holder2=st.empty()
text_holder3=st.empty()
text_holder4=st.empty()
LOC=DIR+"/"+all_folds[11]
all_files=os.listdir(LOC)
all_files.sort()
img = cv2.imread(LOC+"/"+all_files[0],cv2.IMREAD_GRAYSCALE)
totalPix=img.shape[0]*img.shape[1]
buff_row=[img.shape[0]/2,img.shape[0]/2]
buff_col=[img.shape[1]/2,img.shape[1]/2]
vecR=np.array([1 for i in range(img.shape[1])])
vecC=np.array([1 for i in range(img.shape[0])])
for i in all_files:
DOWNDIR=False
RIGHTDIR=False
UP=0
DOWN=0
LEFT=0
RIGHT=0
img = cv2.imread(LOC+"/"+i,cv2.IMREAD_GRAYSCALE)
ret,img = cv2.threshold(img,50,255,cv2.THRESH_TOZERO)
ret,imgB = cv2.threshold(img,50,255,cv2.THRESH_BINARY)
norm_row=img.dot(vecR)
norm_col=img.T.dot(vecC)
image_holder.image(img,width=400)
if max(norm_row)>100 or max(norm_col)>100:
text_holder.markdown("<h3 style='text-align: left; color: green;'>Plasma is touching the surface!</h3>",unsafe_allow_html=True)
for j in range(norm_row.shape[0]):
if not DOWNDIR:
if norm_row[j]!=0:
if j<buff_row[0]:
UP+=1
elif j==buff_row[0]:
pass
elif j>buff_row[0]:
UP-=1
buff_row[0]=j
DOWNDIR=True
if DOWNDIR:
if norm_row[j]==0:
if j>buff_row[1]:
DOWN+=1
elif j==buff_row[1]:
pass
elif j<buff_row[1]:
DOWN-=1
buff_row[1]=j
break
for j in range(norm_col.shape[0]):
if not RIGHTDIR:
if norm_col[j]!=0:
if j<buff_col[0]:
LEFT+=1
elif j==buff_col[0]:
pass
elif j>buff_row[0]:
LEFT-=1
buff_col[0]=j
RIGHTDIR=True
if RIGHTDIR:
if norm_col[j]==0:
if j>buff_col[1]:
RIGHT+=1
elif j==buff_col[1]:
pass
elif j<buff_row[1]:
RIGHT-=1
buff_col[1]=j
break
if (UP+DOWN+LEFT+RIGHT)==0:
text_holder5.markdown("<h3 style='text-align: left; color: red;'>Plasma is not moving!</h3>",unsafe_allow_html=True)
else:
if (UP>0) and (DOWN>0) and (LEFT>0) and (RIGHT>0):
text_holder5.markdown("<h3 style='text-align: left; color: green;'>Plasma is Expanding!</h3>",unsafe_allow_html=True)
elif (UP<0) and (DOWN<0) and (LEFT<0) and (RIGHT<0):
text_holder5.markdown("<h3 style='text-align: left; color: green;'>Plasma is Contracting!</h3>",unsafe_allow_html=True)
else:
if (UP>0) and (DOWN>0):
text_holder1.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Expanding Vertically!</h3>",unsafe_allow_html=True)
elif ((UP>0) and (DOWN==0)):
text_holder1.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Expanding in Upward Direction!</h3>",unsafe_allow_html=True)
elif ((UP==0) and (DOWN>0)):
text_holder1.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Expanding in Downward Direction!</h3>",unsafe_allow_html=True)
elif ((UP<0) and (DOWN==0)):
text_holder1.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Contracting in Upward Direction!</h3>",unsafe_allow_html=True)
elif ((UP==0) and (DOWN<0)):
text_holder1.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Contracting in Upward Direction!</h3>",unsafe_allow_html=True)
elif (UP<0) and (DOWN<0):
text_holder1.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Contracting Vertically!</h3>",unsafe_allow_html=True)
elif (UP>0) and (DOWN<=0):
text_holder1.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Moving Up!</h3>",unsafe_allow_html=True)
elif (UP<=0) and (DOWN>0):
text_holder1.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Moving Down!</h3>",unsafe_allow_html=True)
if (LEFT>0) and (RIGHT>0):
text_holder3.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Expanding Horizontally!</h3>",unsafe_allow_html=True)
elif ((LEFT>0) and (RIGHT==0)):
text_holder3.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Expanding in Left Direction!</h3>",unsafe_allow_html=True)
elif ((LEFT==0) and (RIGHT>0)):
text_holder3.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Expanding in Right Direction!</h3>",unsafe_allow_html=True)
elif ((LEFT<0) and (RIGHT==0)):
text_holder3.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Contracting in Left Direction!</h3>",unsafe_allow_html=True)
elif ((LEFT==0) and (RIGHT<0)):
text_holder3.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Contracting in Right Direction!</h3>",unsafe_allow_html=True)
elif (LEFT<0) and (RIGHT<0):
text_holder3.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Contracting Horizontally!</h3>",unsafe_allow_html=True)
elif (LEFT>0) and (RIGHT<=0):
text_holder3.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Moving Left!</h3>",unsafe_allow_html=True)
elif (LEFT<=0) and (RIGHT>0):
text_holder3.markdown("<h3 style='text-align: left; color: blue;'>Plasma is Moving Right!</h3>",unsafe_allow_html=True)
imgB=np.multiply(((1/255)*np.ones(imgB.shape)),imgB)
area=sum(sum(imgB))/totalPix
text_holder4.markdown("<h3 style='text-align: left; color: maroon;'>Plasma's Area: "+str(area)+"</h3>",unsafe_allow_html=True)
else:
text_holder.markdown("<h3 style='text-align: left; color: red;'>Plasma is not touching the surface!</h3>",unsafe_allow_html=True)
time.sleep(0.6)
text_holder.text("")
text_holder1.text("")
text_holder2.text("")
text_holder3.text("")
text_holder4.text("")
text_holder5.text("")