ground truth comparision

def tryAllWSize(image_L,image_R,L_truth,R_truth,disparity_func,dmax,folder):
    L_best = None
    L_best_score = None
    L_w_size_best = None
    R_best = None
    R_best_score = None
    R_w_size_best = None
    for w_size in range(min_w_size,max_w_size+1,2):
        start = time.time()
        D_L = disparity_func(image_L, image_R, 1, w_size, dmax)
        D_R = disparity_func(image_R, image_L, 0, w_size, dmax)
        finish = time.time()
        L_score = ((L_truth-D_L)**2).mean()
        R_score = ((R_truth-D_R)**2).mean()
        if L_best_score is None or L_score < L_best_score:
            L_best = D_L
            L_best_score = L_score
            L_w_size_best = w_size
        if R_best_score is None or R_score < R_best_score:
            R_best = D_R
            R_best_score = R_score
            R_w_size_best = w_size
        print((folder, finish-start, w_size, L_score, R_score))
        D_L1 = disparityTo255(D_L, dmax)
        D_R1 = disparityTo255(D_R, dmax)
        DL_diff = abs(D_L - L_truth) / dmax * 255 #disparityDiff(D_L, L_truth, dmax)
        DR_diff = abs(D_R - R_truth) / dmax * 255 #disparityDiff(D_R, R_truth, dmax)
        cv2.imwrite(os.path.join(output_dir, folder, str(w_size)+'-l-diff.png'), DL_diff)
        cv2.imwrite(os.path.join(output_dir, folder, str(w_size)+'-r-diff.png'), DR_diff)
        cv2.imwrite(os.path.join(output_dir, folder, str(w_size)+'-l.png'), D_L1)
        cv2.imwrite(os.path.join(output_dir, folder, str(w_size)+'-r.png'), D_R1)
    return L_best, R_best