Skip to content

Commit ec21bc1

Browse files
Merge pull request #2071 from invigorzz313/ImageBlur
Blurring an image
2 parents 2066bc1 + 68d89a9 commit ec21bc1

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

Blur an Image/BlurImage.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
# from re import X
3+
from tkinter.filedialog import *
4+
import tkinter as tk
5+
import cv2
6+
7+
window=tk.Tk()
8+
window.title("Image Blur")
9+
window.geometry('350x200')
10+
label = tk.Label(window, text="Choose an option").grid(row=0,column=1)
11+
12+
def blur1():
13+
photo = askopenfilename()
14+
img = cv2.imread(photo)
15+
avgblur = cv2.blur(img,(5,5))
16+
17+
cv2.imshow("Image", img)
18+
cv2.imshow("Average blur", avgblur)
19+
20+
cv2.waitKey(0)
21+
cv2.destroyAllWindows()
22+
23+
def fx(x):
24+
return
25+
26+
def blur2():
27+
photo = askopenfilename()
28+
img = cv2.imread(photo)
29+
30+
cv2.namedWindow("Gaussian Blur",cv2.WINDOW_NORMAL)
31+
32+
cv2.createTrackbar("kernelSize",'Gaussian Blur',1,7,fx) # we want trackbar to not call any function
33+
# thus calling an empty function
34+
35+
g = cv2.getTrackbarPos("kernelSize",'Gaussian Blur')
36+
37+
if g==3 or g==5 or g==7: # kernel size must be positive odd values
38+
gaussblur = cv2.GaussianBlur(img,(g,g),0)
39+
else:
40+
gaussblur = cv2.GaussianBlur(img,(3,3),0)
41+
42+
cv2.imshow("Image", img)
43+
cv2.imshow("Gaussian Blur", gaussblur)
44+
45+
cv2.waitKey(0)
46+
cv2.destroyAllWindows()
47+
48+
def blur3():
49+
photo = askopenfilename()
50+
img = cv2.imread(photo)
51+
medianblur = cv2.medianBlur(img,5)
52+
53+
cv2.imshow("Image", img)
54+
cv2.imshow("Median blur", medianblur)
55+
56+
cv2.waitKey(0)
57+
cv2.destroyAllWindows()
58+
59+
60+
rad1 = tk.Radiobutton(window,text='average blur', value=1, command=blur1)
61+
rad2 = tk.Radiobutton(window,text='gaussian blur', value=2, command=blur2)
62+
rad3 = tk.Radiobutton(window,text='median blur', value=3, command=blur3)
63+
64+
rad1.grid(row=1,column=0)
65+
rad2.grid(row=1,column=1)
66+
rad3.grid(row=1,column=2)
67+
68+
window.mainloop()

Blur an Image/ReadMe.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Blurring an Image
2+
This python script will allow us to blur an image depending on the user's choice to select one of the three blurring options
3+
4+
## Setup Instructions
5+
### Install python3
6+
sudo apt-get install python3
7+
### Install pip (package installer for python)
8+
sudo apt-get install python3-pip
9+
### Install OpenCV library with pip
10+
pip3 install opencv-python
11+
### Install tkinter library
12+
sudo apt-get install python3-tk
13+
14+
## Details/Output
15+
A dialog box appears with three blurring options, average, gaussian and median blurs.
16+
Selecting any one option prompts user to select an image and applies blur on it.
17+
18+
## Author
19+
Github: invigorzz313

0 commit comments

Comments
 (0)