def plot_rsvl(rgb, name):
    r = rgb[:,:,0]
    req = cv2.equalizeHist(r)
    rmask = mask(req, (252, 255))
    dsp_images = [(name+'_req',req),('rmask', rmask)]
    
    hls,h,l,s = rgb2hls(rgb)
    seq = cv2.equalizeHist(s)
    smask = mask(seq, (253, 255))
    dsp_images += [(name+'_seq',seq),('smask', smask)]
    
    hsv,h,s,v = rgb2hsv(rgb)
    veq = cv2.equalizeHist(v)
    vmask = mask(veq, (252, 255))
    dsp_images += [(name+'_veq',veq),('vmask', vmask)]
    
    lab,l,a,b = rgb2lab(rgb)
    leq = cv2.equalizeHist(l)
    lmask = mask(leq, (252, 255))
    dsp_images += [(name+'_leq',leq),('lmask', lmask)]
    
    comb = np.zeros_like(r)
    comb[(rmask==1)|(vmask==1)|(lmask==1)] =1
    dsp_images += [('comb',comb)]
    plot_images(dsp_images)
    plt.show()
def plot_grayscale(rgb, name):
    gray = cv2.cvtColor(rgb, cv2.COLOR_RGB2GRAY)
    gray_eq = cv2.equalizeHist(gray)
    grdx = scale(gradient(gray, orient='x', ksize=7))
    grdmag = cv2.equalizeHist(scale(gradient_magnitude(gray_eq, ksize=7)))
    
    dsp_images= [(name+'_gray',gray),('gray_eq',gray_eq),('gradient',grdx),('gradient mag',grdmag)]
    plot_images(dsp_images)
    plt.show()
def plot_lab(rgb, name):
    lab,l,a,b = rgb2lab(rgb)
    gradl = scale(gradient(l, orient="x", ksize=11))
#     grdlow = mask(gradl,(0,100))
#     grdhigh = mask(gradl,(135,255))
#     comb = np.zeros_like(gradl)
#     comb[(grdlow==1)|(grdhigh==1)] = 1
    
    maskl = mask(l, (190,255))
    
    dsp_images= [(name+'_l',l),('maskl',maskl),('gradl',gradl)]
    plot_images(dsp_images)
    plt.show()
def plot_colorspaces(rgb,name):
    r = rgb[:,:,0]
    req = equalizeHist(r)
    g = rgb[:,:,1]
    b = rgb[:,:,2]
    dsp_images= [(name+'_rgb',rgb),('r',r),('req',req),('g',g),('b',b)]
    plot_images(dsp_images)
    plt.show()
    
    hls,h,l,s = rgb2hls(rgb)
    seq = cv2.equalizeHist(s)
    dsp_images= [(name+'_hls',hls),('h',h),('l',l),('s',s),('seq',seq)]
    plot_images(dsp_images)
    plt.show()
    
    hsv,h,s,v = rgb2hsv(rgb)
    veq = cv2.equalizeHist(v)
    dsp_images = [(name+'_hsv',hsv),('h',h),('s',s),('v',v),('veq',veq)]
    plot_images(dsp_images)
    plt.show()
    
    lab,l,a,b = rgb2lab(rgb)
    leq = cv2.equalizeHist(l)
    beq = cv2.equalizeHist(b)
    dsp_images= [(name+'_lab',lab),('l',l),('leq',leq),('a',a),('b',b),('beq',beq)]
    plot_images(dsp_images)
    plt.show()
#     image_names = ['test_images/straight_lines1.jpg','test_images/straight_lines2.jpg']
#     image_names = ['test_images/test2.jpg']
 
    for image_name in image_names:
        img = imread(image_name)
        img_und = undistorter.undistort(img)
        
#         plotter = plot_colorspaces
        plotter = plot_rsvl
#         plotter = plot_lab
        plotter = plot_grayscale
#         plotter(img_und, image_name)

        img_pt = per_trans.transform(img_und)
        img_lns = filter_image(img_pt)
        plot_images([("pic",img_und),("pt lane",img_lns)])
        plt.show()
        
        if False:
            timer = Timer()
            lf, rf = lane.get_current_fit()
            if lf != None:
                display_image_with_fits(img_lns, lf, rf)
            
            lane.process_lanes(img_lns)
               
            plt.show()
        
#         gray = cv2.cvtColor(img_pt, cv2.COLOR_RGB2GRAY)
#         grdx = scale(gradient(gray, orient="x", ksize=3))
#         grdx5 = scale(gradient(gray, orient="x", ksize=5))