Skip to content

Commit a7eb146

Browse files
style: format code with autopep8
Format code with autopep8 This commit fixes the style issues introduced in 8890205 according to the output from Autopep8. Details: None
1 parent 8890205 commit a7eb146

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

Morphological_transforms/morph_transforms.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,82 +2,95 @@
22
import tkinter as tk
33
import cv2
44

5-
def select_image(): # selecting image and thresholding it to binary format
5+
6+
def select_image(): # selecting image and thresholding it to binary format
67
photo = askopenfilename()
78
global img, thresh
89
img = cv2.imread(photo)
910
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
10-
threshold_value = 125 # this value needs to be adjusted for every image
11+
threshold_value = 125 # this value needs to be adjusted for every image
1112
ret, thresh = cv2.threshold(gray, threshold_value, 255, 0)
1213

14+
1315
def erosion():
14-
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
16+
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
1517
eroded = cv2.erode(thresh, kernel, iterations=1)
16-
eroded = cv2.resize(eroded,(300,300))
18+
eroded = cv2.resize(eroded, (300, 300))
1719
cv2.imshow("Erosion", eroded)
1820
cv2.waitKey(0)
1921
cv2.destroyAllWindows()
2022

23+
2124
def dilation():
22-
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5)) # elliptic kernel
25+
kernel = cv2.getStructuringElement(
26+
cv2.MORPH_ELLIPSE, (5, 5)) # elliptic kernel
2327
dilated = cv2.dilate(thresh, kernel, iterations=1)
24-
dilated = cv2.resize(dilated,(300,300))
28+
dilated = cv2.resize(dilated, (300, 300))
2529
cv2.imshow("Dilation", dilated)
2630
cv2.waitKey(0)
2731
cv2.destroyAllWindows()
2832

33+
2934
def opening():
30-
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
35+
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
3136
opened = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)
32-
opened = cv2.resize(opened,(300,300))
37+
opened = cv2.resize(opened, (300, 300))
3338
cv2.imshow("Opening", opened)
3439
cv2.waitKey(0)
3540
cv2.destroyAllWindows()
3641

42+
3743
def closing_opn():
38-
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
44+
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
3945
closed = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
40-
closed = cv2.resize(closed,(300,300))
46+
closed = cv2.resize(closed, (300, 300))
4147
cv2.imshow("Closing", closed)
4248
cv2.waitKey(0)
4349
cv2.destroyAllWindows()
4450

51+
4552
def morph_grad():
46-
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
53+
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
4754
grad = cv2.morphologyEx(thresh, cv2.MORPH_GRADIENT, kernel)
48-
grad = cv2.resize(grad,(300,300))
55+
grad = cv2.resize(grad, (300, 300))
4956
cv2.imshow("Morph gradient", grad)
5057
cv2.waitKey(0)
5158
cv2.destroyAllWindows()
5259

60+
5361
def top_hat():
54-
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
62+
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
5563
tophat = cv2.morphologyEx(thresh, cv2.MORPH_TOPHAT, kernel)
56-
tophat = cv2.resize(tophat,(300,300))
64+
tophat = cv2.resize(tophat, (300, 300))
5765
cv2.imshow("Top hat", tophat)
5866
cv2.waitKey(0)
5967
cv2.destroyAllWindows()
6068

69+
6170
def black_hat():
62-
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(5,5))
71+
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
6372
blackhat = cv2.morphologyEx(thresh, cv2.MORPH_BLACKHAT, kernel)
64-
blackhat = cv2.resize(blackhat,(300,300))
73+
blackhat = cv2.resize(blackhat, (300, 300))
6574
cv2.imshow("Black hat", blackhat)
6675
cv2.waitKey(0)
6776
cv2.destroyAllWindows()
6877

78+
6979
window = tk.Tk()
7080
window.title("Morphological transformations")
7181
window.geometry('320x220')
72-
label = tk.Label(window, text="Select an image and then choose an option").grid(row=0, column=0)
73-
b = tk.Button(window, text="Select image", command=select_image).grid(row=1,column=0)
82+
label = tk.Label(window, text="Select an image and then choose an option").grid(
83+
row=0, column=0)
84+
b = tk.Button(window, text="Select image",
85+
command=select_image).grid(row=1, column=0)
7486

7587

7688
rad1 = tk.Radiobutton(window, text='erosion', value=1, command=erosion)
7789
rad2 = tk.Radiobutton(window, text='dilation', value=2, command=dilation)
7890
rad3 = tk.Radiobutton(window, text='opening', value=3, command=opening)
7991
rad4 = tk.Radiobutton(window, text='closing', value=4, command=closing_opn)
80-
rad5 = tk.Radiobutton(window, text='morph gradient', value=5, command=morph_grad)
92+
rad5 = tk.Radiobutton(window, text='morph gradient',
93+
value=5, command=morph_grad)
8194
rad6 = tk.Radiobutton(window, text='top hat', value=6, command=top_hat)
8295
rad7 = tk.Radiobutton(window, text='black hat', value=7, command=black_hat)
8396

0 commit comments

Comments
 (0)