Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Border Extraction/Border_extraction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import cv2
import numpy as np
import tkinter as tk
from tkinter.filedialog import *

window = tk.Tk()
window.title("Border extraction")
window.geometry('300x100')
label = tk.Label(window, text="Choose an image").grid(row=0, column=0)

photo = askopenfilename()
img = cv2.imread(photo)
n,l,m = img.shape
size = (n,l)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

threshold_value = 20 # this value needs to be adjusted for every image
ret, thresh = cv2.threshold(gray, threshold_value, 255, 0)

kernel = np.ones((5,5),np.uint8)
# dilation and erosion are applied to binary images
dilated = cv2.dilate(thresh, kernel, iterations=1)
eroded = cv2.erode(thresh, kernel, iterations=1)

bordered = dilated - eroded
bordered = cv2.resize(bordered, size)
cv2.imshow("Border/outline", bordered)
cv2.imwrite("Output.png", bordered)
cv2.waitKey(0)
cv2.destroyAllWindows()

window.mainloop()
Binary file added Border Extraction/Output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions Border Extraction/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Border extraction
This python script will allow us to extract borders of objects in an image.

## Setup Instructions
### Install python3
sudo apt-get install python3
### Install pip (package installer for python)
sudo apt-get install python3-pip
### Install Numpy library with pip
pip3 install numpy
### Install OpenCV library with pip
pip3 install opencv-python
### Install tkinter library
sudo apt-get install python3-tk

## Details/Output
User should select an image and the script returns an output image of borders of the objects in it.
The input image is converted into binary format and then we use morphological transformation of dilation minus erosion.
**Note** The threshold value while converting an image into binary format needs to be adjusted for every image.

## Author
Github: invigorzz313
Binary file added Border Extraction/sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.