def apply_thresholing(self, image): parameters = self._thresh_params image_gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) # clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8)) # image_gray = clahe.apply(image_gray) gradx_thresh = (parameters['sobel_x_thresh_min'], parameters['sobel_x_thresh_max']) grady_thresh = (parameters['sobel_y_thresh_min'], parameters['sobel_y_thresh_max']) magnitude_thresh = (parameters['mag_thresh_min'], parameters['mag_thresh_max']) dir_thresh = (parameters['dir_thresh_min'], parameters['dir_thresh_max']) ksize = parameters['sobel_kernel'] # Apply each of the thresholding functions gradx = abs_sobel_thresh(image_gray, orient='x', sobel_kernel=ksize, thresh=gradx_thresh) grady = abs_sobel_thresh(image_gray, orient='y', sobel_kernel=ksize, thresh=grady_thresh) mag_binary = mag_thresh(image_gray, sobel_kernel=ksize, thresh=magnitude_thresh) dir_binary = dir_threshold(image_gray, sobel_kernel=ksize, thresh=dir_thresh) gradient_threshold = np.zeros_like(dir_binary) gradient_threshold[((gradx == 1) & (grady == 1)) | ((dir_binary == 1) & (mag_binary == 1))] = 1 color_threshold = create_binary_image(image) binary = np.zeros_like(gradient_threshold) binary[(color_threshold == 1) | (gradient_threshold == 1)] = 1 # binary[(gradient_threshold == 1)] = 1 return binary
def thresholding(img): #print(img.shape) #setting all sorts of thresholds #cv2.imshow("orig", img) x_thresh = utils.abs_sobel_thresh(img, orient='x', thresh_min=10, thresh_max=230) #cv2.imshow("x_thresh",x_thresh*255) mag_thresh = utils.mag_thresh(img, sobel_kernel=3, mag_thresh=(30, 150)) #cv2.imshow("mag_thresh",mag_thresh*255) dir_thresh = utils.dir_threshold(img, sobel_kernel=3, thresh=(0.7, 1.3)) #cv2.imshow("dir_thresh",dir_thresh*255) hls_thresh = utils.hls_select(img, thresh=(180, 255)) #cv2.imshow("hls_thresh",hls_thresh*255) lab_thresh = utils.lab_select(img, thresh=(155, 200)) #cv2.imshow("lab_thresh",lab_thresh*255) luv_thresh = utils.luv_select(img, thresh=(225, 255)) #cv2.imshow("luv_thresh",luv_thresh) #Thresholding combination threshholded = np.zeros_like(x_thresh) threshholded[((x_thresh == 1) & (mag_thresh == 1)) | ((dir_thresh == 1) & (hls_thresh == 1)) | (lab_thresh == 1) | (luv_thresh == 1)] = 1 #cv2.imshow("threshholded", threshholded*255) #cv2.waitKey(0) return threshholded
def thresholding(img): # x_thresh = utils.abs_sobel_thresh(img, orient='x', thresh_min=55, thresh_max=100) # mag_thresh = utils.mag_thresh(img, sobel_kernel=3, mag_thresh=(70, 255)) # dir_thresh = utils.dir_threshold(img, sobel_kernel=3, thresh=(0.7, 1.3)) # s_thresh = utils.hls_select(img,channel='s',thresh=(160, 255)) # s_thresh_2 = utils.hls_select(img,channel='s',thresh=(200, 240)) # # white_mask = utils.select_white(img) # yellow_mask = utils.select_yellow(img) x_thresh = utils.abs_sobel_thresh(img, orient='x', thresh_min=10, thresh_max=230) mag_thresh = utils.mag_thresh(img, sobel_kernel=3, mag_thresh=(30, 150)) dir_thresh = utils.dir_threshold(img, sobel_kernel=3, thresh=(0.7, 1.3)) hls_thresh = utils.hls_select(img, thresh=(180, 255)) lab_thresh = utils.lab_select(img, thresh=(155, 200)) luv_thresh = utils.luv_select(img, thresh=(225, 255)) #Thresholding combination threshholded = np.zeros_like(x_thresh) threshholded[((x_thresh == 1) & (mag_thresh == 1)) | ((dir_thresh == 1) & (hls_thresh == 1)) | (lab_thresh == 1) | (luv_thresh == 1)] = 1 # threshholded = np.zeros_like(x_thresh) # threshholded[((x_thresh == 1)) | ((mag_thresh == 1) & (dir_thresh == 1))| (white_mask>0)|(s_thresh == 1) ]=1 return threshholded
def process_video(self): test_image = self.input_image sobel_kernel = self.sobel_kernel.value sobel_x_thresh_min = self.sobel_x_thresh_min.value sobel_x_thresh_max = self.sobel_x_thresh_max.value sobel_y_thresh_min = self.sobel_y_thresh_min.value sobel_y_thresh_max = self.sobel_y_thresh_max.value mag_kernel = self.mag_kernel.value mag_thresh_min = self.mag_thresh_min.value mag_thresh_max = self.mag_thresh_max.value dir_kernel = self.dir_kernel.value dir_thresh_min = self.dir_thresh_min.value / 10 dir_thresh_max = self.dir_thresh_max.value / 10 sat_thresh_min = self.sat_thresh_min.value sat_thresh_max = self.sat_thresh_max.value # gradient_threshold = threshold_image(test_image, ksize=sobel_kernel, # gradx_thresh=(sobel_x_thresh_min, sobel_x_thresh_max), # grady_thresh=(sobel_y_thresh_min, sobel_y_thresh_max), # magnitude_thresh=(mag_thresh_min, mag_thresh_max), # dir_thresh=(dir_thresh_min, dir_thresh_max)) ksize = sobel_kernel # Apply each of the thresholding functions gradx = abs_sobel_thresh(test_image, orient='x', sobel_kernel=ksize, thresh=(sobel_x_thresh_min, sobel_x_thresh_max)) grady = abs_sobel_thresh(test_image, orient='y', sobel_kernel=ksize, thresh=(sobel_y_thresh_min, sobel_y_thresh_max)) mag_binary = mag_thresh(test_image, sobel_kernel=ksize, thresh=(mag_thresh_min, mag_thresh_max)) dir_binary = dir_threshold(test_image, sobel_kernel=ksize, thresh=(dir_thresh_min, dir_thresh_max)) gradient_threshold = np.zeros_like(dir_binary) # gradient_threshold[(gradx == 1)] = 1 gradient_threshold[((gradx == 1) & (grady == 1)) | ((dir_binary == 1) & (mag_binary == 1))] = 1 image_hsl = cv2.cvtColor(test_image, cv2.COLOR_RGB2HLS) s_channel = image_hsl[:, :, 2] color_threshold = np.zeros_like(s_channel) color_threshold[(s_channel >= sat_thresh_min) & (s_channel <= sat_thresh_max)] = 1 color_threshold = create_binary_image(test_image) binary = np.zeros_like(gradient_threshold) binary[(color_threshold == 1) | (gradient_threshold == 1)] = 1 # binary = np.zeros_like(gradient_threshold) # binary[(color_threshold == 1) | (gradient_threshold == 1)] = 1 # binary[(gradient_threshold == 1)] = 1 self._write_image(binary) self._binary = cv2.imread('out.jpg', 0) print('Created image') self._image.value = self._binary self._image.repaint()
def thresholding(img): x_thresh = utils.abs_sobel_thresh(img, orient='x', thresh_min=10, thresh_max=230) mag_thresh = utils.mag_thresh(img, sobel_kernel=3, mag_thresh=(30, 150)) dir_thresh = utils.dir_threshold(img, sobel_kernel=3, thresh=(0.7, 1.3)) hls_thresh = utils.hls_select(img, thresh=(180, 255)) lab_thresh = utils.lab_select(img, thresh=(155, 200)) luv_thresh = utils.luv_select(img, thresh=(225, 255)) #Thresholding combination threshholded = np.zeros_like(x_thresh) threshholded[((x_thresh == 1) & (mag_thresh == 1)) | ((dir_thresh == 1) & (hls_thresh == 1)) | (lab_thresh == 1) | (luv_thresh == 1)] = 1 return threshholded
undistorted.append(img) trans_on_test=[] for img in undistorted: src = np.float32([[(203, 720), (585, 460), (695, 460), (1127, 720)]]) dst = np.float32([[(320, 720), (320, 0), (960, 0), (960, 720)]]) M = cv2.getPerspectiveTransform(src, dst) trans = cv2.warpPerspective(img, M, img.shape[1::-1], flags=cv2.INTER_LINEAR) trans_on_test.append(trans) thresh = [] binary_wrapeds = [] histogram = [] for img in undistorted: x_thresh = utils.abs_sobel_thresh(img, orient='x', thresh_min=55, thresh_max=100) mag_thresh = utils.mag_thresh(img, sobel_kernel=3, mag_thresh=(70, 255)) dir_thresh = utils.dir_threshold(img, sobel_kernel=3, thresh=(0.7, 1.3)) s_thresh = utils.hls_select(img,channel='s',thresh=(160, 255)) s_thresh_2 = utils.hls_select(img,channel='s',thresh=(200, 240)) white_mask = utils.select_white(img) yellow_mask = utils.select_yellow(img) combined = np.zeros_like(mag_thresh) # combined[(x_thresh==1) | ((mag_thresh == 1) & (dir_thresh == 1)) | (s_thresh==1)] = 1 # combined[((mag_thresh == 1) & (dir_thresh == 1))] = 1 combined[((x_thresh == 1) | (s_thresh == 1)) | ((mag_thresh == 1) & (dir_thresh == 1))| (white_mask>0)|(s_thresh_2 == 1) ]=1 src = np.float32([[(203, 720), (585, 460), (695, 460), (1127, 720)]]) dst = np.float32([[(320, 720), (320, 0), (960, 0), (960, 720)]]) M = cv2.getPerspectiveTransform(src, dst)
plt.figure(figsize=(20, 40)) for i in range(0, (len(undistorted_test_images))): plt.subplot(len(undistorted_test_images), 2, 2 * i + 1) plt.title('original image') plt.imshow(test_imgs2[i]) plt.subplot(len(undistorted_test_images), 2, 2 * i + 2) plt.title('after x_thresh_method') plt.imshow(x_thresh_method[i], cmap='gray') plt.savefig('x_thresh_method.png') # In[12]: #mag_thresholding methdods mag_thresh_method = [] for img in test_imgs2: mag_thresh = utils.mag_thresh(img, sobel_kernel=9, mag_thresh=(50, 100)) mag_thresh_method.append(mag_thresh) # In[13]: plt.figure(figsize=(20, 40)) for i in range(0, (len(undistorted_test_images))): plt.subplot(len(undistorted_test_images), 2, 2 * i + 1) plt.title('original image') plt.imshow(test_imgs2[i]) plt.subplot(len(undistorted_test_images), 2, 2 * i + 2) plt.title('after mag_thresh_method') plt.imshow(mag_thresh_method[i], cmap='gray') plt.savefig('mag_thresh_method.png') # In[14]: