Skip to content

Commit 8c0d29d

Browse files
committed
Blur Detection Final Added
1 parent bce2d96 commit 8c0d29d

7 files changed

+57
-23
lines changed
1.21 KB
Binary file not shown.
299 Bytes
Binary file not shown.
-220 Bytes
Binary file not shown.
-36 Bytes
Binary file not shown.

blur_detection.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
11
import cv2
2+
import os
23

34

4-
def variance_of_laplacian(image):
5-
return cv2.Laplacian(image, cv2.CV_64F).var()
5+
def main(blur_thresh=7):
6+
folder_list = []
7+
if len(os.listdir("Data")) == 0:
8+
print("[Data] folder is empty!\n")
9+
exit()
10+
else:
11+
for entry_name in os.listdir("Data"):
12+
folder_list.append(entry_name)
13+
14+
counter = 0
15+
for folder in folder_list:
16+
folder_path = "Data/" + folder
17+
for file_name in os.listdir(folder_path):
18+
img = cv2.imread(os.path.join(folder_path, file_name), cv2.IMREAD_COLOR)
619

20+
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
21+
var = variance_of_laplacian(img_gray)
722

8-
def main():
9-
image = cv2.imread("sharp.jpg")
10-
cv2.imshow("Image", image)
11-
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
12-
fm = variance_of_laplacian(gray)
23+
if var < blur_thresh:
24+
counter += 1
25+
'''cv2.imshow("Image", img)
26+
cv2.waitKey(0)
27+
cv2.destroyAllWindows()'''
28+
os.remove(os.path.join(folder_path, file_name))
29+
print("File Name: " + str(file_name) + " >> Blur detected >> Removed!")
30+
print("Original Var: " + str(var))
31+
print('--------------------------------')
32+
print("Total " + str(counter) + " files removed because of BLUR!")
1333

14-
print(fm)
15-
cv2.waitKey(0)
34+
35+
def variance_of_laplacian(image):
36+
return cv2.Laplacian(image, cv2.CV_64F).var()
1637

1738

1839
# Main Call Func. >>>

melNET.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def main():
1616
global applied
1717
applied = False
1818

19-
def apply_button_applied():
19+
def apply_but ton_applied():
2020
root.destroy()
2121
global applied
2222
applied = True

melNET_augData.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
from tkinter import *
77
import shutil
8+
import blur_detection
89

910

1011
# Main >>>
@@ -26,6 +27,7 @@ def quit_button_pressed():
2627
pressed = False
2728

2829
# Check Box variables
30+
_del_blur = BooleanVar()
2931
_original = BooleanVar()
3032
_histEqualization = BooleanVar()
3133
_dilation = BooleanVar()
@@ -36,30 +38,34 @@ def quit_button_pressed():
3638
_rotate = BooleanVar()
3739
_five_fold = BooleanVar()
3840
_rotate_ang = IntVar(0)
41+
_blur_thresh = IntVar(0)
3942

4043
# UI Creation
41-
Checkbutton(root, text="Original", variable=_original).grid(row=0, sticky=W)
42-
Checkbutton(root, text="Hist. Equalization", variable=_histEqualization).grid(row=1, sticky=W)
43-
Checkbutton(root, text="Dilation", variable=_dilation).grid(row=2, sticky=W)
44-
Checkbutton(root, text="Erosion", variable=_erosion).grid(row=3, sticky=W)
45-
Checkbutton(root, text="Blur", variable=_blur).grid(row=4, sticky=W)
46-
Checkbutton(root, text="Sharpen", variable=_sharpen).grid(row=5, sticky=W)
47-
Checkbutton(root, text="Mirror", variable=_mirror).grid(row=6, sticky=W)
48-
Checkbutton(root, text="Rotate All", variable=_rotate).grid(row=7, sticky=W)
49-
50-
Label(root, text="Angle Span in Degrees: ").grid(row=7, column=2)
51-
Label(root, text="(Default: 45)").grid(row=8, column=2)
52-
Entry(root, textvariable=_rotate_ang).grid(row=7, column=3)
44+
Checkbutton(root, text="Detect & Delete Blurry Images", variable=_del_blur).grid(row=0, sticky=W)
45+
Checkbutton(root, text="Original", variable=_original).grid(row=1, sticky=W)
46+
Checkbutton(root, text="Hist. Equalization", variable=_histEqualization).grid(row=2, sticky=W)
47+
Checkbutton(root, text="Dilation", variable=_dilation).grid(row=3, sticky=W)
48+
Checkbutton(root, text="Erosion", variable=_erosion).grid(row=4, sticky=W)
49+
Checkbutton(root, text="Blur", variable=_blur).grid(row=5, sticky=W)
50+
Checkbutton(root, text="Sharpen", variable=_sharpen).grid(row=6, sticky=W)
51+
Checkbutton(root, text="Mirror", variable=_mirror).grid(row=7, sticky=W)
52+
Checkbutton(root, text="Rotate All", variable=_rotate).grid(row=8, sticky=W)
53+
54+
Label(root, text="Angle Span in Degrees: ").grid(row=8, column=2)
55+
Label(root, text="(Default: 45)").grid(row=9, column=2)
56+
Entry(root, textvariable=_rotate_ang).grid(row=8, column=3)
57+
Label(root, text="Blur Threshold (Default=7):").grid(row=0, column=2)
58+
Entry(root, textvariable=_blur_thresh).grid(row=0, column=3)
5359

5460
Checkbutton(root, text="Five-Fold (Default: Single-Fold)", variable=_five_fold).grid(row=10, sticky=W)
5561
Button(root, text="Quit", command=quit_button_pressed, width=15).grid(row=11, column=2, sticky=W)
5662
Button(root, text="Apply", command=apply_button_pressed, width=15).grid(row=11, column=3, sticky=W)
5763

5864
root.mainloop()
5965

60-
6166
# Checking [Start] status
6267
if pressed:
68+
del_blur = _del_blur.get()
6369
original = _original.get()
6470
histEqualization = _histEqualization.get()
6571
dilation = _dilation.get()
@@ -71,6 +77,7 @@ def quit_button_pressed():
7177
global five_fold
7278
five_fold = _five_fold.get()
7379
rot_ang = _rotate_ang.get()
80+
blur_thresh = _blur_thresh.get()
7481

7582
if (original is False and histEqualization is False and dilation is False and
7683
erosion is False and blur is False and sharpen is False and mirror is False):
@@ -90,6 +97,12 @@ def quit_button_pressed():
9097
else:
9198
rotationAngle = None
9299

100+
# Detect and Delete blurry images
101+
if del_blur:
102+
if blur_thresh is 0:
103+
blur_thresh = 7
104+
blur_detection.main(blur_thresh)
105+
93106
# Number of folds
94107
global fold_num
95108
fold_num = 5 # For 5Folds

0 commit comments

Comments
 (0)