Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 26dba01

Browse files
applying borders to images
1 parent c0b68a7 commit 26dba01

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

‎Image borders/Image_border.py‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import cv2
2+
import tkinter as tk
3+
from tkinter.filedialog import *
4+
5+
def choose_image(): # reading the image
6+
photo = askopenfilename()
7+
global img
8+
img = cv2.imread(photo)
9+
img = cv2.resize(img,(500,500))
10+
11+
# functions for every border type
12+
def constant_border():
13+
bordered = cv2.copyMakeBorder(img,50,50,50,50,cv2.BORDER_CONSTANT)
14+
cv2.imshow("Constant border", bordered)
15+
cv2.waitKey(0)
16+
cv2.destroyAllWindows()
17+
18+
def reflection_border():
19+
bordered = cv2.copyMakeBorder(img,50,50,50,50,cv2.BORDER_REFLECT)
20+
cv2.imshow("Reflection border", bordered)
21+
cv2.waitKey(0)
22+
cv2.destroyAllWindows()
23+
24+
def default_border():
25+
bordered = cv2.copyMakeBorder(img,50,50,50,50,cv2.BORDER_DEFAULT)
26+
cv2.imshow("Default border", bordered)
27+
cv2.waitKey(0)
28+
cv2.destroyAllWindows()
29+
30+
def replicate_border():
31+
bordered = cv2.copyMakeBorder(img,50,50,50,50,cv2.BORDER_REPLICATE)
32+
cv2.imshow("Replicate border", bordered)
33+
cv2.waitKey(0)
34+
cv2.destroyAllWindows()
35+
36+
def wrap_border():
37+
bordered = cv2.copyMakeBorder(img,50,50,50,50,cv2.BORDER_WRAP)
38+
cv2.imshow("Wrap border", bordered)
39+
cv2.waitKey(0)
40+
cv2.destroyAllWindows()
41+
42+
window = tk.Tk() # displaying menu and options
43+
window.title("Borders on images")
44+
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)
47+
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)
52+
rad5 = tk.Radiobutton(window, text='wrap border', value=5, command=wrap_border)
53+
54+
rad1.grid(row=2, column=0)
55+
rad2.grid(row=3, column=0)
56+
rad3.grid(row=4, column=0)
57+
rad4.grid(row=5, column=0)
58+
rad5.grid(row=6, column=0)
59+
60+
window.mainloop()

‎Image borders/ReadMe.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Borders on image
2+
This python script will allow us to apply different borders on an image.
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 option to select an image and choice of border to be applied.
16+
The bordered image is then displayed in a window.
17+
18+
## Author
19+
Github: invigorzz313

‎Image borders/exampleOutput.png‎

545 KB
Loading[フレーム]

‎Image borders/flower.jpg‎

9.19 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /