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 61b28d4

Browse files
border extraction
1 parent c0b68a7 commit 61b28d4

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import cv2
2+
import numpy as np
3+
import tkinter as tk
4+
from tkinter.filedialog import *
5+
6+
window = tk.Tk()
7+
window.title("Border extraction")
8+
window.geometry('300x100')
9+
label = tk.Label(window, text="Choose an image").grid(row=0, column=0)
10+
11+
photo = askopenfilename()
12+
img = cv2.imread(photo)
13+
n,l,m = img.shape
14+
size = (n,l)
15+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
16+
17+
threshold_value = 20 # this value needs to be adjusted for every image
18+
ret, thresh = cv2.threshold(gray, threshold_value, 255, 0)
19+
20+
kernel = np.ones((5,5),np.uint8)
21+
# dilation and erosion are applied to binary images
22+
dilated = cv2.dilate(thresh, kernel, iterations=1)
23+
eroded = cv2.erode(thresh, kernel, iterations=1)
24+
25+
bordered = dilated - eroded
26+
bordered = cv2.resize(bordered, size)
27+
cv2.imshow("Border/outline", bordered)
28+
cv2.imwrite("Output.png", bordered)
29+
cv2.waitKey(0)
30+
cv2.destroyAllWindows()
31+
32+
window.mainloop()

‎Border Extraction/Output.png‎

40.9 KB
Loading[フレーム]

‎Border Extraction/ReadMe.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Border extraction
2+
This python script will allow us to extract borders of objects in 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 Numpy library with pip
10+
pip3 install numpy
11+
### Install OpenCV library with pip
12+
pip3 install opencv-python
13+
### Install tkinter library
14+
sudo apt-get install python3-tk
15+
16+
## Details/Output
17+
User should select an image and the script returns an output image of borders of the objects in it.
18+
The input image is converted into binary format and then we use morphological transformation of dilation minus erosion.
19+
**Note** The threshold value while converting an image into binary format needs to be adjusted for every image.
20+
21+
## Author
22+
Github: invigorzz313

‎Border Extraction/sample.png‎

91.8 KB
Loading[フレーム]

0 commit comments

Comments
(0)

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