def correct_video(image, mat, sequence_num): start_point = PATH.find_the_starting(mat) path1, path_cost1 = PATH.search_a_path(mat, start_point) path1 = gaussian_filter1d(path1, 3) img_corrected = VIDEO_PEOCESS.de_distortion(image, path1, sequence_num) show1 = mat #circular = cv2.linearPolar(img_corrected, (img_corrected.shape[0]/2, img_corrected.shape[1]/2), # 462, cv2.WARP_INVERSE_MAP) new_frame = cv2.rotate(img_corrected, rotateCode=2) circular = cv2.linearPolar( new_frame, (new_frame.shape[1] / 2, new_frame.shape[0] / 2), 200, cv2.WARP_INVERSE_MAP) cv2.imwrite(savedir_path + str(sequence_num) + ".jpg", circular) for i in range(len(path1)): show1[int(path1[i]), i] = 254 cv2.imshow('step_process', show1) cv2.imshow('original video', image) cv2.imshow('correcr video', img_corrected.astype(np.uint8)) cv2.imshow('rota video', new_frame.astype(np.uint8)) cv2.imshow('circular video', circular.astype(np.uint8)) return 0
def func2(self): start_time = time() print('NURD start') image1 = self.stream2[self.strmlen - 1, :, :] h, w = image1.shape window_wid = self.path_predictor.Original_window_Len self.costmatrix = np.zeros((window_wid, w)) self.costmatrix, self.shift_used2 = COSTMtrix.matrix_cal_corre_block_version3_3GPU( self.stream2[self.strmlen - 1, :, :], self.stream2[self.strmlen - 2, :, :], 0, block_wid=3, Down_sample_F=1, Down_sample_F2=2) #self.costmatrix2,self.shift_used2= COSTMtrix.matrix_cal_corre_block_version3_3GPU ( # self.stream2[self.strmlen-1,50:211,:] , # self.stream2[self.strmlen-2,50:211,:], 0, # block_wid = 3,Down_sample_F = 5,Down_sample_F2 = 5) ##self.costmatrix = self.costmatrix1 #self.costmatrix = 0.6*self.costmatrix1+ 0.4*self.costmatrix2 Hm, Wm = self.costmatrix.shape self.costmatrix = cv2.resize(self.costmatrix, (Wm, Standard_LEN), interpolation=cv2.INTER_AREA) self.costmatrix = myfilter.gauss_filter_s( self.costmatrix) # smooth matrix #self.costmatrix = cv2.GaussianBlur(self.costmatrix,(3,3),0) #self.costmatrix = self.costmatrix*1.5 +30 # down sample the materix and up sample #Hm,Wm= self.costmatrix.shape #self.costmatrix = cv2.resize(self.costmatrix, (int(Wm/2),int(Hm/2)), interpolation=cv2.INTER_AREA) #self.costmatrix = cv2.resize(self.costmatrix, (Wm,Hm), interpolation=cv2.INTER_AREA) # THE COST MATRIX COST 0.24 S if Graph_searching_flag == True: start_point = PATH.find_the_starting( self.costmatrix) # starting point for path searching self.path, pathcost1 = PATH.search_a_path(self.costmatrix, start_point) else: self.path = PATH.get_warping_vextor( self.costmatrix) # THIS COST 0.03S self.path = self.path * Window_LEN / Standard_LEN #self.path = self.path_predictor.predict(self.stream2[self.strmlen-1,:,:], self.stream2[self.strmlen-2,:,:]) end_time = time() print('NURD end ') print(" A time is [%f] " % (end_time - start_time))
def correct_video( image,corre_shifting,mat,shift_integral,sequence_num,addition_window_shift): H,W= mat.shape #get size of image show1 = mat.astype(float) path1 = np.zeros(W) #small the initial to speed path finding #mat = cv2.resize(mat, (Resample_size,H), interpolation=cv2.INTER_AREA) #mat = cv2.resize(mat, (Resample_size,Resample_size), interpolation=cv2.INTER_AREA) start_point= PATH.find_the_starting(mat) # starting point for path searching ##middle_point = PATH.calculate_ave_mid(mat) path1,path_cost1=PATH.search_a_path(mat,start_point) # get the path and average cost of the path #path1,path_cost1=PATH.search_a_path_deep_multiscal_small_window_fusion2(mat) # get the path and average cost of the path #path1 = corre_shifting + path1 #path1 =0.5 * path1 + 0.5 * corre_shifting path_cost1 = 0 path1 = gaussian_filter1d(path1,3) # smooth the path #path1 = path1 -(np.mean(path1) - int(Window_LEN/2)) # remove the meaning shifting #long_out = np.append(np.flip(path1),path1) # flip to make the the start point and end point to be perfect interpolit #long_out = np.append(long_out, np. flip ( path1)) #long_out = gaussian_filter1d (long_out ,1) #long_path_upsam = signal.resample(long_out, 3*W) #path_upsam = long_path_upsam[W:2*W] #path1 = path_upsam /Resample_size * H #path1,path_cost1=PATH.search_a_path_GPU (mat) # get the path and average cost of the path # applying the correct img_corrected,shift_integral = VIDEO_PEOCESS.de_distortion_integral (image,path1,shift_integral,sequence_num,addition_window_shift) #cv2.imshow('step_process',show1.astype(np.uint8)) #cv2.imshow('original video',image) #cv2.imshow('correcr video',img_corrected.astype(np.uint8)) #cv2.imshow('rota video',new_frame.astype(np.uint8)) #cv2.imshow('circular video',circular.astype(np.uint8)) return img_corrected,path1,shift_integral,path_cost1
def seg_process(self, Img_ini): gray = Img_ini H, W = gray.shape #gray = gray [: ,100: W -100] #Img = Img [: ,100: W -100] ave_line = self.calculate_the_average_line(gray) peaks = self.aline.find_4peak(ave_line) H, W = gray.shape original = gray #gray = cv2.blur(gray,(3,3)) #gray = cv2.medianBlur(gray,5) #gray = cv2.blur(gray,(5,5)) gray = cv2.GaussianBlur(gray, (3, 3), 0) #gray = cv2.bilateralFilter(gray,15,75,75) #gray = cv2.bilateralFilter(gray,15,75,75) ave_line = self.calculate_the_average_line(gray) peaks = self.aline.find_4peak(ave_line) #gray = cv2.blur(gray,(5,5),0) if self.display_flag == True: cv2.imshow('ini', Img_ini) cv2.imshow('blur', gray.astype(np.uint8)) x_kernel = np.asarray([ [-1, 0, 1], # Sobel kernel for x-direction [-2, 0, 2], [-1, 0, 1] ]) #y_kernel = np.asarray([[-2, -2, -2], # Sobel kernel for y-direction # [1, 1, 1], # [1, 1, 1]]) y_kernel = np.asarray([ [-1, -1, -1], # Sobel kernel for y-direction [-1, -1, -1], [-1, -1, -1], [6, 6, 6], [-1, -1, -1], [-1, -1, -1], [-1, -1, -1] ]) #y_kernel = np.asarray([ # Sobel kernel for y-direction # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [12,12], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # ]) y_kernel = np.asarray([ # Sobel kernel for y-direction [-1, 0], [-1, 0], [-1, 0], [-1, 0], [28, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], ]) y_kernel = y_kernel / 9 gray = gray.astype(np.float) #sobel_x = signal.convolve2d(gray, x_kernel) # sobel_y = signal.convolve2d(gray, y_kernel) # convolve kernels over images sobel_y = np.clip(sobel_y + 10, 1, 254) sobel_y = cv2.medianBlur(sobel_y.astype(np.uint8), 5) sobel_y = cv2.GaussianBlur(sobel_y, (5, 5), 0) sobel_y = cv2.blur(sobel_y, (5, 5)) #sobel_y = cv2.GaussianBlur(sobel_y,(5,5),0) #sobel_y = cv2.bilateralFilter(sobel_y.astype(np.uint8),9,175,175) #find the start 4 point #sobel_y=sobel_y[self.bias:H-self.bias, :] #Img=Img[self.bias:H-self.bias, :] ave_line = self.calculate_the_average_line(sobel_y) peaks = self.aline.find_4peak(ave_line) Rever_img = 255 - sobel_y #start_point = 596 peaks = np.clip(peaks, 1, Rever_img.shape[0] - 1) #new_peak = np.zeros(4) #new_peak=peaks #new_peak[3] = peaks[2]+35 #peaks = new_peak if Manual_start_flag == True: peaks[1] = peaks[0] + 472 - 293 peaks[2] = peaks[0] + 500 - 293 peaks[3] = peaks[0] + 677 - 293 path1, path_cost1 = PATH.search_a_path(Rever_img, int(peaks[0])) #path2,path_cost1=PATH.search_a_path(Rever_img,int(peaks[1])) #path3,path_cost1=PATH.search_a_path(Rever_img,int(peaks[2])) #path4,path_cost1=PATH.search_a_path(Rever_img,int(peaks[3])) path1 = gaussian_filter1d(path1, 6) #path2 =gaussian_filter1d(path2,2) #path3 =gaussian_filter1d(path3,2) #path4 =gaussian_filter1d(path4,2) #path4=path3 ##path2 = path3 #path3 = path2+35 #path2 = path2 - 5 #path3,path_cost1=PATH.search_a_path_based_on_path(Rever_img,path3) #path3 =gaussian_filter1d(path3,4) path1 = path1 #-10 path1 = np.clip(path1, 0, sobel_y.shape[0] - 1) #[path1,path2,path3,path4]=np.clip([path1,path2,path3,path4], # 0,sobel_y.shape[0]-1) for i in range(len(path1)): sobel_y[int(path1[i]), i] = 254 Dark_boundaries = sobel_y * 0 path1 = np.clip(path1, 0, Dark_boundaries.shape[0] - 2) for i in range(len(path1)): Dark_boundaries[int(path1[i]), i] = 254 for i in range(gray.shape[1]): gray[int(path1[i]) + 1, i] = gray[int(path1[i]), i] = 254 # corect tje RC #original = cv2.resize(original, (int(W/2),int(H/2)), interpolation=cv2.INTER_LINEAR) new = self.rc_corrector.correct(original, path1) if self.display_flag == True: cv2.imshow('revert', Rever_img.astype(np.uint8)) #cv2.imshow('path on blur',gray.astype(np.uint8)) cv2.imshow('Seg2', Img) #sobel_y = sobel_y*0.1 #edges = cv2.Canny(gray,50, 300,10) cv2.imshow('seg', sobel_y.astype(np.uint8)) cv2.imshow('correct', new.astype(np.uint8)) #cv2.imwrite(self.savedir_path + str(1) +".jpg",sobel_y .astype(np.uint8)) cv2.waitKey(1) return new # Img,sobel_y,Dark_boundaries,[path1,path2,path3,path4]
def validation(self, original_IMG, Shifted_IMG, path, Image_ID): #Costmatrix,shift_used = COSTMtrix.matrix_cal_corre_full_version3_2GPU(original_IMG,Shifted_IMG,0) #Costmatrix,shift_used = COSTMtrix.matrix_cal_corre_full_version3_2GPU(original_IMG,Shifted_IMG,0) Costmatrix, shift_used = COSTMtrix.matrix_cal_corre_full_version3_2GPU( original_IMG, Shifted_IMG, 0) #Costmatrix=cv2.blur(Costmatrix,(5,5)) Costmatrix = myfilter.gauss_filter_s(Costmatrix) # smooth matrix # Costmatrix =cv2.GaussianBlur(Costmatrix,(5,5),0) # down sample the materix and up sample #Hm,Wm= Costmatrix.shape #Costmatrix = cv2.resize(Costmatrix, (int(Wm/2),int(Hm/2)), interpolation=cv2.INTER_LINEAR) #Costmatrix = cv2.resize(Costmatrix, (Wm,Hm), interpolation=cv2.INTER_LINEAR) if Clip_matrix_flag == True: Costmatrix = np.clip(Costmatrix, 20, 254) #Costmatrix=self.random_min_clip_by_row(5,30,Costmatrix) #Costmatrix = self.add_lines_to_matrix(Costmatrix) #Costmatrix=np.clip(Costmatrix, 20, 255) # Costmatrix = myfilter.gauss_filter_s(Costmatrix) # smooth matrix #tradition way to find path ##middle_point = PATH.calculate_ave_mid(mat) #path1,path_cost1=PATH.search_a_path(mat,start_point) # get the path and average cost of the path show1 = np.zeros((Costmatrix.shape[0], Costmatrix.shape[1], 3)) show1[:, :, 0] = Costmatrix show1[:, :, 1] = Costmatrix show1[:, :, 2] = Costmatrix for i in range(len(path)): painter = np.clip(path[i], 1, Window_LEN - 2) show1[int(painter), i, :] = show1[int(painter) - 1, i, :] = [254, 254, 254] if Show_nurd_compare == True: start_point = PATH.find_the_starting( Costmatrix) # starting point for path searching path_tradition, pathcost1 = PATH.search_a_path( Costmatrix, start_point) # get the path and average cost of the path #path_tradition=(path_tradition -Window_LEN/2)* Down_sample_F2 +Window_LEN/2 #path_deep,path_cost2=PATH.search_a_path_Deep_Mat2longpath(Costmatrix) # get the path and average cost of the path path_deep, path_cost2 = PATH.search_a_path_GPU( Costmatrix) # get the path and average cost of the path #path_deep=(path_deep -Window_LEN/2)* Down_sample_F2 +Window_LEN/2 path_deep = gaussian_filter1d(path_deep, 3) # smooth the path show1 = np.clip(show1, 1, 190) for i in range(len(path)): painter = np.clip(path[i], 1, Window_LEN - 2) show1[int(painter), i, :] = show1[int(painter) - 1, i, :] = [254, 254, 254] painter2 = np.clip(path_tradition[i], 1, Window_LEN - 2) painter3 = np.clip(path_deep[i], 1, Window_LEN - 2) show1[int(painter2), i, :] = show1[int(painter2) - 1, i, :] = [0, 254, 0] show1[int(painter3), i, :] = show1[int(painter3) - 1, i, :] = [0, 0, 254] # save the matrix to fil dir cv2.imwrite(self.data_mat_root_origin + str(Image_ID) + ".jpg", Costmatrix) cv2.imwrite(self.data_mat_root + str(Image_ID) + ".jpg", show1) # show the signal comparison in visdom if visdom_show_flag == True: x = np.arange(0, len(path)) self.vis_ploter.plot_multi_arrays_append(x, path, title_name=str(Image_ID), legend='truth') self.vis_ploter.plot_multi_arrays_append(x, path_deep, title_name=str(Image_ID), legend='Deep Learning') self.vis_ploter.plot_multi_arrays_append(x, path_tradition, title_name=str(Image_ID), legend='Traditional') # save comparison signals to matlab if Save_matlab_flag == True: self.matlab.buffer_4(Image_ID, path, path_deep, path_tradition) self.matlab.save_mat() pass
def seg_process(self, Img,start_p ): gray = cv2.cvtColor(Img, cv2.COLOR_BGR2GRAY) H,W = gray.shape #gray = gray [: ,100: W -100] #Img = Img [: ,100: W -100] H,W = gray.shape #gray = cv2.blur(gray,(3,3)) #gray = cv2.medianBlur(gray,5) #gray = cv2.blur(gray,(5,5)) gray = cv2.GaussianBlur(gray,(3,3),0) #gray = cv2.bilateralFilter(gray,15,75,75) #gray = cv2.bilateralFilter(gray,15,75,75) ave_line = self.calculate_the_average_line(gray,start_p) #peaks = self.aline.find_4peak(ave_line) #gray = cv2.blur(gray,(5,5),0) if self.display_flag == True : cv2.imshow('ini',Img) cv2.imshow('blur',gray.astype(np.uint8)) x_kernel = np.asarray([[-1, 0, 1], # Sobel kernel for x-direction [-2, 0, 2], [-1, 0, 1]]) #y_kernel = np.asarray([[-2, -2, -2], # Sobel kernel for y-direction # [1, 1, 1], # [1, 1, 1]]) y_kernel = np.asarray([[-1,-1,-1], # Sobel kernel for y-direction [-1,-1,-1], [-1,-1,-1], [6,6,6], [-1,-1,-1], [-1,-1,-1], [ -1,-1,-1]]) #y_kernel = np.asarray([ # Sobel kernel for y-direction # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [12,12], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # ]) y_kernel = np.asarray([ # Sobel kernel for y-direction [-1,0 ], [-1,0 ], [-1,0 ], [-1,0 ], [28,0 ], [-1,0 ], [-1,0 ], [-1 ,0], [-1,0 ], [-1,0 ], [-1,0 ], [-1 ,0], [-1,0 ], [-1,0 ], [-1,0 ], [-1,0 ], [-1,0 ], [-1 ,0], [-1,0 ], [-1,0 ], [-1,0 ], [-1,0 ], [-1,0 ], [-1 ,0], [-1,0 ], [-1,0 ], [-1,0 ], [-1,0 ], [-1,0 ], ]) y_kernel = y_kernel/9 gray = gray.astype(np.float) #sobel_x = signal.convolve2d(gray, x_kernel) # sobel_y = signal.convolve2d(gray, y_kernel) # convolve kernels over images sobel_y = np.clip(sobel_y+10, 1,254) sobel_y = cv2.medianBlur(sobel_y.astype(np.uint8),5) sobel_y = cv2.GaussianBlur(sobel_y,(5,5),0) sobel_y = cv2.blur(sobel_y,(5,5)) #sobel_y = cv2.GaussianBlur(sobel_y,(5,5),0) #sobel_y = cv2.bilateralFilter(sobel_y.astype(np.uint8),9,175,175) #find the start 4 point sobel_y=sobel_y[self.bias:H-self.bias, :] Img=Img[self.bias:H-self.bias, :] Rever_img = 255 - sobel_y #ave_line = self.calculate_the_average_line(sobel_y) #peaks = self.aline.find_4peak(ave_line) ave_line = self.calculate_the_average_line(gray,start_p) peaks = self.aline.find_4peak(ave_line) #start_point = 596 peaks = np.clip(peaks, 1,Rever_img.shape[0]-1) #new_peak = np.zeros(4) #new_peak=peaks #new_peak[3] = peaks[2]+35 #peaks = new_peak path1,path_cost1=PATH.search_a_path(Rever_img,start_p- self.region + peaks[0]) path1 =gaussian_filter1d(path1,2) path1 = np.clip(path1, 0,sobel_y.shape[0]-1) for i in range ( len(path1)): sobel_y[int(path1[i]),i]=254 if self.display_flag == True: cv2.imshow('revert',Rever_img.astype(np.uint8)) #cv2.imshow('path on blur',gray.astype(np.uint8)) cv2.imshow('Seg2',Img) #sobel_y = sobel_y*0.1 #edges = cv2.Canny(gray,50, 300,10) cv2.imshow('seg',sobel_y.astype(np.uint8)) cv2.waitKey(1) return path1
def seg_process(self, Img): gray = cv2.cvtColor(Img, cv2.COLOR_BGR2GRAY) H, W = gray.shape #gray = gray [: ,100: W -100] #Img = Img [: ,100: W -100] ave_line = self.calculate_the_average_line(gray) peaks = self.aline.find_4peak(ave_line) H, W = gray.shape #gray = cv2.blur(gray,(3,3)) #gray = cv2.medianBlur(gray,5) #gray = cv2.blur(gray,(5,5)) gray = cv2.GaussianBlur(gray, (3, 3), 0) #gray = cv2.bilateralFilter(gray,15,75,75) #gray = cv2.bilateralFilter(gray,15,75,75) ave_line = self.calculate_the_average_line(gray) peaks = self.aline.find_4peak(ave_line) #gray = cv2.blur(gray,(5,5),0) if self.display_flag == True: cv2.imshow('ini', Img) cv2.imshow('blur', gray.astype(np.uint8)) x_kernel = np.asarray([ [-1, 0, 1], # Sobel kernel for x-direction [-2, 0, 2], [-1, 0, 1] ]) #y_kernel = np.asarray([[-2, -2, -2], # Sobel kernel for y-direction # [1, 1, 1], # [1, 1, 1]]) y_kernel = np.asarray([ [-1, -1, -1], # Sobel kernel for y-direction [-1, -1, -1], [-1, -1, -1], [6, 6, 6], [-1, -1, -1], [-1, -1, -1], [-1, -1, -1] ]) #y_kernel = np.asarray([ # Sobel kernel for y-direction # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [12,12], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # [-1,-1], # ]) y_kernel = np.asarray([ # Sobel kernel for y-direction [-1, 0], [-1, 0], [-1, 0], [-1, 0], [28, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], [-1, 0], ]) y_kernel = y_kernel / 9 gray = gray.astype(np.float) #sobel_x = signal.convolve2d(gray, x_kernel) # sobel_y = signal.convolve2d(gray, y_kernel) # convolve kernels over images sobel_y = np.clip(sobel_y + 10, 1, 254) sobel_y = cv2.medianBlur(sobel_y.astype(np.uint8), 5) sobel_y = cv2.GaussianBlur(sobel_y, (5, 5), 0) sobel_y = cv2.blur(sobel_y, (5, 5)) #sobel_y = cv2.GaussianBlur(sobel_y,(5,5),0) #sobel_y = cv2.bilateralFilter(sobel_y.astype(np.uint8),9,175,175) #find the start 4 point sobel_y = sobel_y[self.bias:H - self.bias, :] Img = Img[self.bias:H - self.bias, :] ave_line = self.calculate_the_average_line(sobel_y) peaks = self.aline.find_4peak(ave_line) Rever_img = 255 - sobel_y #start_point = 596 peaks = np.clip(peaks, 1, Rever_img.shape[0] - 1) #new_peak = np.zeros(4) #new_peak=peaks #new_peak[3] = peaks[2]+35 #peaks = new_peak if Manual_start_flag == True: peaks[1] = peaks[0] + 472 - 293 peaks[2] = peaks[0] + 500 - 293 peaks[3] = peaks[0] + 677 - 293 path1, path_cost1 = PATH.search_a_path(Rever_img, int(peaks[0])) path2, path_cost1 = PATH.search_a_path(Rever_img, int(peaks[1])) path3, path_cost1 = PATH.search_a_path(Rever_img, int(peaks[2])) path4, path_cost1 = PATH.search_a_path(Rever_img, int(peaks[3])) path1 = gaussian_filter1d(path1, 2) path2 = gaussian_filter1d(path2, 2) path3 = gaussian_filter1d(path3, 2) path4 = gaussian_filter1d(path4, 2) path4 = path3 #path2 = path3 path3 = path2 + 35 path2 = path2 - 5 path3, path_cost1 = PATH.search_a_path_based_on_path(Rever_img, path3) path3 = gaussian_filter1d(path3, 4) [path1, path2, path3, path4] = np.clip([path1, path2, path3, path4], 0, sobel_y.shape[0] - 1) for i in range(len(path1)): sobel_y[int(path1[i]), i] = 254 sobel_y[int(path2[i]), i] = 254 sobel_y[int(path3[i]), i] = 254 sobel_y[int(path4[i]), i] = 254 Dark_boundaries = sobel_y * 0 [path1, path2, path3, path4] = np.clip([path1, path2, path3, path4], 0, Dark_boundaries.shape[0] - 2) for i in range(len(path1)): Dark_boundaries[int(path1[i]), i] = 254 Dark_boundaries[int(path2[i]), i] = 220 Dark_boundaries[int(path3[i]), i] = 199 Dark_boundaries[int(path4[i]), i] = 180 [path1, path2, path3, path4] = np.clip([path1, path2, path3, path4], 0, Img.shape[0] - 2) for i in range(Img.shape[1]): Img[int(path1[i]) + 1, i, :] = Img[int(path1[i]), i, :] = [254, 0, 0] Img[int(path2[i]) + 1, i, :] = Img[int(path2[i]), i, :] = [0, 254, 0] Img[int(path3[i]) + 1, i, :] = Img[int(path3[i]), i, :] = [0, 0, 254] Img[int(path4[i]) + 1, i, :] = Img[int(path4[i]), i, :] = [0, 0, 0] if self.display_flag == True: cv2.imshow('revert', Rever_img.astype(np.uint8)) #cv2.imshow('path on blur',gray.astype(np.uint8)) cv2.imshow('Seg2', Img) #sobel_y = sobel_y*0.1 #edges = cv2.Canny(gray,50, 300,10) cv2.imshow('seg', sobel_y.astype(np.uint8)) cv2.imwrite(self.savedir_path + str(1) + ".jpg", sobel_y.astype(np.uint8)) cv2.waitKey(1) return Img, sobel_y, Dark_boundaries, [path1, path2, path3, path4]