AshanGimhana
commited on
Commit
•
c31b288
1
Parent(s):
5f1bd17
Update app.py
Browse files
app.py
CHANGED
@@ -123,23 +123,28 @@ net.cuda()
|
|
123 |
|
124 |
print('Model successfully loaded!')
|
125 |
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
129 |
|
130 |
-
|
131 |
-
hist = exposure.histogram(gray_image)
|
132 |
-
low_exposure = hist[0][:5].sum() > 0.5 * hist[0].sum() # Significant pixels in dark range
|
133 |
-
high_exposure = hist[0][-5:].sum() > 0.5 * hist[0].sum() # Significant pixels in bright range
|
134 |
|
135 |
-
|
136 |
-
sharpness = cv2.Laplacian(np.array(image), cv2.CV_64F).var()
|
137 |
-
low_sharpness = sharpness < 70 # Threshold for sharpness
|
138 |
|
139 |
-
|
140 |
-
if low_exposure or high_exposure or low_sharpness:
|
141 |
-
return False # Image quality is insufficient
|
142 |
-
return True # Image quality is sufficient
|
|
|
|
|
|
|
143 |
|
144 |
# Functions for face and mouth region
|
145 |
def get_face_region(image):
|
@@ -278,9 +283,9 @@ def process_image(uploaded_image):
|
|
278 |
|
279 |
# Gradio Interface
|
280 |
def show_results(uploaded_image):
|
281 |
-
|
282 |
-
if not check_image_quality(uploaded_image):
|
283 |
-
return None, None, "Not_Allowed"
|
284 |
|
285 |
# If quality is acceptable, continue with processing
|
286 |
aged_image_good_teeth, aged_image_bad_teeth, predicted_age, target_age = process_image(uploaded_image)
|
|
|
123 |
|
124 |
print('Model successfully loaded!')
|
125 |
|
126 |
+
####### Image quality checking func ######################
|
127 |
+
|
128 |
+
#def check_image_quality(image):
|
129 |
+
### Convert the image to grayscale
|
130 |
+
##gray_image = np.array(image.convert("L"))
|
131 |
|
132 |
+
### Check for under/over-exposure using histogram
|
133 |
+
#hist = exposure.histogram(gray_image)
|
134 |
+
#low_exposure = hist[0][:5].sum() > 0.5 * hist[0].sum() # Significant pixels in dark range
|
135 |
+
#high_exposure = hist[0][-5:].sum() > 0.5 * hist[0].sum() # Significant pixels in bright range
|
136 |
|
137 |
+
### Check sharpness using Laplacian variance
|
138 |
+
#sharpness = cv2.Laplacian(np.array(image), cv2.CV_64F).var()
|
139 |
+
#low_sharpness = sharpness < 70 # Threshold for sharpness
|
140 |
|
141 |
+
### Check overall quality
|
142 |
+
#if low_exposure or high_exposure or low_sharpness:
|
143 |
+
#return False # Image quality is insufficient
|
144 |
+
#return True # Image quality is sufficient
|
145 |
+
|
146 |
+
############################################################
|
147 |
+
|
148 |
|
149 |
# Functions for face and mouth region
|
150 |
def get_face_region(image):
|
|
|
283 |
|
284 |
# Gradio Interface
|
285 |
def show_results(uploaded_image):
|
286 |
+
### Perform quality check
|
287 |
+
#if not check_image_quality(uploaded_image):
|
288 |
+
#return None, None, "Not_Allowed"
|
289 |
|
290 |
# If quality is acceptable, continue with processing
|
291 |
aged_image_good_teeth, aged_image_bad_teeth, predicted_age, target_age = process_image(uploaded_image)
|