-
Notifications
You must be signed in to change notification settings - Fork 41
/
edge_sharpen.py
executable file
·45 lines (37 loc) · 1.23 KB
/
edge_sharpen.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
import cv2
import numpy as np
import matplotlib.pyplot as plt
from skimage.morphology import opening, disk, closing
def auto_canny(image, sigma=0.33):
# compute the median of the single channel pixel intensities
v = np.median(image)
# apply automatic Canny edge detection using the computed median
lower = int(max(0, (1.0 - sigma) * v))
upper = int(min(255, (1.0 + sigma) * v))
edged = cv2.Canny(image, lower, upper)
# return the edged image
return edged
def equalize(img):
ycrcb = cv2.cvtColor(img, cv2.COLOR_BGR2YCR_CB)
channels = cv2.split(ycrcb)
cv2.equalizeHist(channels[0], channels[0])
cv2.merge(channels, ycrcb)
cv2.cvtColor(ycrcb, cv2.COLOR_YCR_CB2BGR, img)
return img
# 28.539901_77.205472.png
img = cv2.imread('build1.jpg')
# imm = equalize(img)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
plt.imshow(gray, cmap='gray')
blur = cv2.bilateralFilter(gray, 5, 75, 75)
kernel_sharp = np.array((
[-2, -2, -2],
[-2, 17, -2],
[-2, -2, -2]), dtype='int')
im = cv2.filter2D(blur, -1, kernel_sharp)
plt.figure()
plt.imshow(im, cmap='gray')
canny = auto_canny(im)
plt.figure()
plt.imshow(canny, cmap='gray')
plt.show()