forked from Dt-Pham/Advanced-Lane-Lines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThresholding.py
47 lines (36 loc) · 1.25 KB
/
Thresholding.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
import cv2
import numpy as np
def threshold_rel(img, lo, hi):
vmin = np.min(img)
vmax = np.max(img)
vlo = vmin + (vmax - vmin) * lo
vhi = vmin + (vmax - vmin) * hi
return np.uint8((img >= vlo) & (img <= vhi)) * 255
def threshold_abs(img, lo, hi):
return np.uint8((img >= lo) & (img <= hi)) * 255
class Thresholding:
""" This class is for extracting relevant pixels in an image.
"""
def __init__(self):
""" Init Thresholding."""
pass
def forward(self, img):
""" Take an image and extract all relavant pixels.
Parameters:
img (np.array): Input image
Returns:
binary (np.array): A binary image represent all positions of relavant pixels.
"""
hls = cv2.cvtColor(img, cv2.COLOR_RGB2HLS)
hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
h_channel = hls[:,:,0]
l_channel = hls[:,:,1]
s_channel = hls[:,:,2]
v_channel = hsv[:,:,2]
right_lane = threshold_rel(l_channel, 0.8, 1.0)
right_lane[:,:750] = 0
left_lane = threshold_abs(h_channel, 10, 100)
left_lane &= threshold_rel(v_channel, 0.7, 1.0)
left_lane[:,550:] = 0
img2 = left_lane | right_lane
return img2