-
Notifications
You must be signed in to change notification settings - Fork 38
/
CrackDetection.py
49 lines (37 loc) · 1.35 KB
/
CrackDetection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# importing necessary libraries
import numpy as np
import cv2
from matplotlib import pyplot as plt
# read a cracked sample image
img = cv2.imread('Input-Set/Cracked_07.jpg')
# Convert into gray scale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Image processing ( smoothing )
# Averaging
blur = cv2.blur(gray,(3,3))
# Apply logarithmic transform
img_log = (np.log(blur+1)/(np.log(1+np.max(blur))))*255
# Specify the data type
img_log = np.array(img_log,dtype=np.uint8)
# Image smoothing: bilateral filter
bilateral = cv2.bilateralFilter(img_log, 5, 75, 75)
# Canny Edge Detection
edges = cv2.Canny(bilateral,100,200)
# Morphological Closing Operator
kernel = np.ones((5,5),np.uint8)
closing = cv2.morphologyEx(edges, cv2.MORPH_CLOSE, kernel)
# Create feature detecting method
# sift = cv2.xfeatures2d.SIFT_create()
# surf = cv2.xfeatures2d.SURF_create()
orb = cv2.ORB_create(nfeatures=1500)
# Make featured Image
keypoints, descriptors = orb.detectAndCompute(closing, None)
featuredImg = cv2.drawKeypoints(closing, keypoints, None)
# Create an output image
cv2.imwrite('Output-Set/CrackDetected-7.jpg', featuredImg)
# Use plot to show original and output image
plt.subplot(121),plt.imshow(img)
plt.title('Original'),plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(featuredImg,cmap='gray')
plt.title('Output Image'),plt.xticks([]), plt.yticks([])
plt.show()