|
2 | 2 | import tkinter as tk |
3 | 3 | from tkinter.filedialog import * |
4 | 4 |
|
5 | | -def choose_image(): # reading the image |
| 5 | + |
| 6 | +def choose_image(): # reading the image |
6 | 7 | photo = askopenfilename() |
7 | 8 | global img |
8 | 9 | img = cv2.imread(photo) |
9 | | - img = cv2.resize(img,(500,500)) |
| 10 | + img = cv2.resize(img, (500, 500)) |
10 | 11 |
|
11 | 12 | # functions for every border type |
| 13 | + |
| 14 | + |
12 | 15 | def constant_border(): |
13 | | - bordered = cv2.copyMakeBorder(img,50,50,50,50,cv2.BORDER_CONSTANT) |
| 16 | + bordered = cv2.copyMakeBorder(img, 50, 50, 50, 50, cv2.BORDER_CONSTANT) |
14 | 17 | cv2.imshow("Constant border", bordered) |
15 | 18 | cv2.waitKey(0) |
16 | 19 | cv2.destroyAllWindows() |
17 | 20 |
|
| 21 | + |
18 | 22 | def reflection_border(): |
19 | | - bordered = cv2.copyMakeBorder(img,50,50,50,50,cv2.BORDER_REFLECT) |
| 23 | + bordered = cv2.copyMakeBorder(img, 50, 50, 50, 50, cv2.BORDER_REFLECT) |
20 | 24 | cv2.imshow("Reflection border", bordered) |
21 | 25 | cv2.waitKey(0) |
22 | 26 | cv2.destroyAllWindows() |
23 | 27 |
|
| 28 | + |
24 | 29 | def default_border(): |
25 | | - bordered = cv2.copyMakeBorder(img,50,50,50,50,cv2.BORDER_DEFAULT) |
| 30 | + bordered = cv2.copyMakeBorder(img, 50, 50, 50, 50, cv2.BORDER_DEFAULT) |
26 | 31 | cv2.imshow("Default border", bordered) |
27 | 32 | cv2.waitKey(0) |
28 | 33 | cv2.destroyAllWindows() |
29 | 34 |
|
| 35 | + |
30 | 36 | def replicate_border(): |
31 | | - bordered = cv2.copyMakeBorder(img,50,50,50,50,cv2.BORDER_REPLICATE) |
| 37 | + bordered = cv2.copyMakeBorder(img, 50, 50, 50, 50, cv2.BORDER_REPLICATE) |
32 | 38 | cv2.imshow("Replicate border", bordered) |
33 | 39 | cv2.waitKey(0) |
34 | 40 | cv2.destroyAllWindows() |
35 | 41 |
|
| 42 | + |
36 | 43 | def wrap_border(): |
37 | | - bordered = cv2.copyMakeBorder(img,50,50,50,50,cv2.BORDER_WRAP) |
| 44 | + bordered = cv2.copyMakeBorder(img, 50, 50, 50, 50, cv2.BORDER_WRAP) |
38 | 45 | cv2.imshow("Wrap border", bordered) |
39 | 46 | cv2.waitKey(0) |
40 | 47 | cv2.destroyAllWindows() |
41 | 48 |
|
42 | | -window = tk.Tk() # displaying menu and options |
| 49 | + |
| 50 | +window = tk.Tk() # displaying menu and options |
43 | 51 | window.title("Borders on images") |
44 | 52 | window.geometry('320x220') |
45 | | -label = tk.Label(window, text="Select an image and then choose an option").grid(row=0, column=0) |
46 | | -b = tk.Button(window, text="Choose image", command=choose_image).grid(row=1,column=0) |
| 53 | +label = tk.Label(window, text="Select an image and then choose an option").grid( |
| 54 | + row=0, column=0) |
| 55 | +b = tk.Button(window, text="Choose image", |
| 56 | + command=choose_image).grid(row=1, column=0) |
47 | 57 |
|
48 | | -rad1 = tk.Radiobutton(window, text='Constant border', value=1, command=constant_border) |
49 | | -rad2 = tk.Radiobutton(window, text='reflection border', value=2, command=reflection_border) |
50 | | -rad3 = tk.Radiobutton(window, text='default border', value=3, command=default_border) |
51 | | -rad4 = tk.Radiobutton(window, text='replicate border', value=4, command=replicate_border) |
| 58 | +rad1 = tk.Radiobutton(window, text='Constant border', |
| 59 | + value=1, command=constant_border) |
| 60 | +rad2 = tk.Radiobutton(window, text='reflection border', |
| 61 | + value=2, command=reflection_border) |
| 62 | +rad3 = tk.Radiobutton(window, text='default border', |
| 63 | + value=3, command=default_border) |
| 64 | +rad4 = tk.Radiobutton(window, text='replicate border', |
| 65 | + value=4, command=replicate_border) |
52 | 66 | rad5 = tk.Radiobutton(window, text='wrap border', value=5, command=wrap_border) |
53 | 67 |
|
54 | 68 | rad1.grid(row=2, column=0) |
|
0 commit comments