Skip to content

Commit 873ba40

Browse files
author
ratan
committed
edge_detection algorithms added
1 parent 96eeb3d commit 873ba40

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Import necessary libararies
2+
from matplotlib import pyplot as plt
3+
from skimage.io import imread
4+
from skimage.color import rgb2gray
5+
from skimage.feature import corner_harris, corner_subpix, corner_peaks
6+
7+
8+
def main(inputfilename, oututfilename):
9+
# Load image
10+
image = imread(inputfilename)
11+
image = rgb2gray(image)
12+
13+
# Apply corner detection algorithm
14+
corners = corner_harris(image)
15+
coords = corner_peaks(corners, min_distance=5)
16+
coords_subpix = corner_subpix(image, coords, window_size=13)
17+
18+
# Diplay the image
19+
fig, ax = plt.subplots()
20+
ax.imshow(image, interpolation='nearest', cmap=plt.cm.gray)
21+
ax.plot(coords[:, 1], coords[:, 0], '.b', markersize=3)
22+
ax.plot(coords_subpix[:, 1], coords_subpix[:, 0], '+r', markersize=15)
23+
ax.axis((0, 350, 350, 0))
24+
plt.savefig(oututfilename)
25+
26+
27+
if __name__ == "__main__":
28+
inputfilename = input("Enter a input filename:\t")
29+
oututfilename = input("Enter a output filename:\t")
30+
main(inputfilename, oututfilename)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import cv2
2+
import numpy as np
3+
4+
5+
def main(inputfilename, oututfilename):
6+
img = cv2.imread(inputfilename)
7+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
8+
9+
edges = cv2.Canny(gray, 100, 200, apertureSize=3)
10+
cv2.imshow('edges', edges)
11+
cv2.waitKey(0)
12+
13+
minLineLength = 30
14+
maxLineGap = 10
15+
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 15, minLineLength, maxLineGap)
16+
for x in range(0, len(lines)):
17+
for x1, y1, x2, y2 in lines[x]:
18+
cv2.line(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
19+
20+
cv2.imwrite(oututfilename, img)
21+
22+
23+
if __name__ == "__main__":
24+
inputfilename = input("Enter a input filename:\t")
25+
oututfilename = input("Enter a output filename:\t")
26+
main(inputfilename, oututfilename)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Import neccessary libraries
2+
from skimage import io, filters, color
3+
4+
5+
def main(inputfilename, oututfilename):
6+
7+
# Read image
8+
img = io.imread(inputfilename)
9+
10+
# Convert RGB to gray
11+
img = color.rgb2gray(img)
12+
13+
# For edge detection
14+
edge = filters.sobel(img)
15+
16+
# Display and save image
17+
io.imshow(edge)
18+
io.imsave(oututfilename, edge)
19+
20+
21+
if __name__ == "__main__":
22+
inputfilename = input("Enter a input filename:\t")
23+
oututfilename = input("Enter a output filename:\t")
24+
io = main(inputfilename, oututfilename)

0 commit comments

Comments
 (0)