saritha5 commited on
Commit
dd539b9
·
1 Parent(s): ca63cea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +86 -84
app.py CHANGED
@@ -29,102 +29,104 @@ from io import BytesIO
29
  import h5py
30
 
31
 
32
- st.set_page_config(
33
- page_title = "Choose the options"
34
- )
35
- st.title("""
 
 
36
  Image Blurriness Occluded
37
  """)
38
- st.subheader("Prediction of Blur or NotBlur Image")
39
- images = ["blur1.png","blurimg2.png","blurimg3.png","images_11.jpeg"]
40
- with st.sidebar:
41
- st.write("choose an image")
42
- st.image(images)
43
- model_file_path = "mobile_net_occ.h5"
44
 
45
- ##Blurriness Features
46
 
47
- plt. figure(figsize=(10,9))
48
- def variance_of_laplacian(image):
49
- return cv2.Laplacian(image, cv2.CV_64F).var()
50
 
51
- def threshold(value, thresh):
52
- if value > thresh:
53
- return "Not Blur"
54
- else:
55
- return "Blur"
56
- def blurr_predict(img_iter):
57
 
58
- def make_prediction(img_content):
59
- pil_image = Image.open(img_content)
60
- imgplot = plt.imshow(pil_image)
61
- #st.image(pil_image)
62
- plt.show()
63
- gray_cvimage = cv2.cvtColor(np.array(pil_image), cv2.COLOR_RGB2GRAY)
64
- #print(gray_cvimage)
65
- variance_laplacian = variance_of_laplacian(gray_cvimage)
66
- #print(variance_laplacian)
67
- return variance_laplacian
68
 
69
- variance_score = make_prediction(img_iter)
70
- thresh = 2000
71
- variance_score = variance_score/thresh
72
- predicted_label = threshold(variance_score, 1)
73
- return predicted_label,variance_score
74
 
75
- #image_path = "images_11.jpeg"
76
- file = st.file_uploader('Upload an Image',type=(["jpeg","jpg","png"]))
77
-
78
- if file is None:
79
- st.write("Please upload an image file")
80
- else:
81
- image= Image.open(file)
82
- st.image(image,use_column_width = True)
83
- predicted_label,variance_score = blurr_predict(file)
84
- #st.header(predicted_label)
85
- #st.header(str(round(variance_score,2)))
86
- string = "The image is," + str(predicted_label) + " with the score value of " + str(round(variance_score,2))
87
- st.subheader(string)
88
 
89
- st.header("Prediction of Occluded or not Occluded ")
90
- plt. figure(figsize=(10,9))
91
- def occ_predict(img_content):
92
- im = []
93
- image=cv2.imread(img_content)
94
- imgplot = plt.imshow(image)
95
- plt.show()
96
- img = Image.fromarray(image, 'RGB')
97
- resize_image = img.resize((50, 50))
98
- im.append(np.array(resize_image))
99
- fv = np.array(im)
100
- np_array_img = fv.astype('float32') / 255
101
- model_gcs = h5py.File(model_file_path, 'r')
102
- myModel = load_model(model_gcs)
103
- prediction = myModel.predict(np_array_img)
104
- score = prediction[0][0].item()
105
- thresh = 0.5
106
- if score > thresh:
107
- return "Not Occluded",score
108
  else:
109
- return "Occluded",score
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
- f = st.file_uploader('Upload an Image',type=(["jpeg","jpg","png"]))
112
- st.subheader("Prediction of Blur or NotBlur Image")
113
- images1 = ["blur1.png","blurimg2.png","blurimg3.png","images_11.jpeg"]
114
- with st.sidebar:
115
- st.write("choose an image")
116
- st.image(images)
117
 
118
- if f is None:
119
- st.write("Please upload an image file")
120
- else:
121
- image1= Image.open(f)
122
- st.image(image1,use_column_width = True)
123
- predicted_label1,variance_score1 = occ_predict(f)
124
- #st.header(predicted_label)
125
- #st.header(str(round(variance_score,2)))
126
- string1 = "The image is," + str(predicted_label1) + " with the score value of " + str(round(variance_score1,2))
127
- st.subheader(string1)
128
 
129
  #predicted_label, score = occ_predict("/content/drive/MyDrive/Occulded.jpg")
130
  #print("The image is", '\033[1m' + predicted_label1 + '\033[0m', "with the score value of" ,round(score,2))
 
29
  import h5py
30
 
31
 
32
+ page_names = ["Blurred or Not Blurred Prediction","Occluded or Not Occluded Prediction"]
33
+ page = st.radio('Navigation',page_names)
34
+ st.write("Welcome to the Project")
35
+
36
+ if page = "Blurred or Not Blurred Prediction":
37
+ st.title("""
38
  Image Blurriness Occluded
39
  """)
40
+ st.subheader("Prediction of Blur or NotBlur Image")
41
+ images = ["blur1.png","blurimg2.png","blurimg3.png","images_11.jpeg"]
42
+ with st.sidebar:
43
+ st.write("choose an image")
44
+ st.image(images)
45
+ model_file_path = "mobile_net_occ.h5"
46
 
47
+ ##Blurriness Features
48
 
49
+ plt. figure(figsize=(10,9))
50
+ def variance_of_laplacian(image):
51
+ return cv2.Laplacian(image, cv2.CV_64F).var()
52
 
53
+ def threshold(value, thresh):
54
+ if value > thresh:
55
+ return "Not Blur"
56
+ else:
57
+ return "Blur"
58
+ def blurr_predict(img_iter):
59
 
60
+ def make_prediction(img_content):
61
+ pil_image = Image.open(img_content)
62
+ imgplot = plt.imshow(pil_image)
63
+ #st.image(pil_image)
64
+ plt.show()
65
+ gray_cvimage = cv2.cvtColor(np.array(pil_image), cv2.COLOR_RGB2GRAY)
66
+ #print(gray_cvimage)
67
+ variance_laplacian = variance_of_laplacian(gray_cvimage)
68
+ #print(variance_laplacian)
69
+ return variance_laplacian
70
 
71
+ variance_score = make_prediction(img_iter)
72
+ thresh = 2000
73
+ variance_score = variance_score/thresh
74
+ predicted_label = threshold(variance_score, 1)
75
+ return predicted_label,variance_score
76
 
77
+ #image_path = "images_11.jpeg"
78
+ file = st.file_uploader('Upload an Image',type=(["jpeg","jpg","png"]))
 
 
 
 
 
 
 
 
 
 
 
79
 
80
+ if file is None:
81
+ st.write("Please upload an image file")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  else:
83
+ image= Image.open(file)
84
+ st.image(image,use_column_width = True)
85
+ predicted_label,variance_score = blurr_predict(file)
86
+ #st.header(predicted_label)
87
+ #st.header(str(round(variance_score,2)))
88
+ string = "The image is," + str(predicted_label) + " with the score value of " + str(round(variance_score,2))
89
+ st.subheader(string)
90
+ else:
91
+ st.title("Prediction of Occluded or not Occluded ")
92
+ plt. figure(figsize=(10,9))
93
+ def occ_predict(img_content):
94
+ im = []
95
+ image=cv2.imread(img_content)
96
+ imgplot = plt.imshow(image)
97
+ plt.show()
98
+ img = Image.fromarray(image, 'RGB')
99
+ resize_image = img.resize((50, 50))
100
+ im.append(np.array(resize_image))
101
+ fv = np.array(im)
102
+ np_array_img = fv.astype('float32') / 255
103
+ model_gcs = h5py.File(model_file_path, 'r')
104
+ myModel = load_model(model_gcs)
105
+ prediction = myModel.predict(np_array_img)
106
+ score = prediction[0][0].item()
107
+ thresh = 0.5
108
+ if score > thresh:
109
+ return "Not Occluded",score
110
+ else:
111
+ return "Occluded",score
112
 
113
+ f = st.file_uploader('Upload an Image',type=(["jpeg","jpg","png"]))
114
+ st.subheader("Prediction of Blur or NotBlur Image")
115
+ images1 = ["blur1.png","blurimg2.png","blurimg3.png","images_11.jpeg"]
116
+ with st.sidebar:
117
+ st.write("choose an image")
118
+ st.image(images)
119
 
120
+ if f is None:
121
+ st.write("Please upload an image file")
122
+ else:
123
+ image1= Image.open(f)
124
+ st.image(image1,use_column_width = True)
125
+ predicted_label1,variance_score1 = occ_predict(f)
126
+ #st.header(predicted_label)
127
+ #st.header(str(round(variance_score,2)))
128
+ string1 = "The image is," + str(predicted_label1) + " with the score value of " + str(round(variance_score1,2))
129
+ st.subheader(string1)
130
 
131
  #predicted_label, score = occ_predict("/content/drive/MyDrive/Occulded.jpg")
132
  #print("The image is", '\033[1m' + predicted_label1 + '\033[0m', "with the score value of" ,round(score,2))