def estimate_disp(args):

    B = np.array([[np.sqrt(3) / 2, 0.5], [0, 1]]).T

    rings = [int(i) for i in args.use_rings.split(',')]

    nb_offsets = []
    for i in rings:
        nb_offsets.extend(rtxhexgrid.HEX_OFFSETS[i])

    lenses, scene_type = rtxIO.load_scene(args.filename)

    diam = lenses[0, 0].diameter
    max_disp = float(args.max_disp)
    min_disp = float(args.min_disp)
    num_disp = float(args.num_disp)

    #max_lens_dist = np.linalg.norm(np.dot(B, rtxhexgrid.HEX_OFFSETS[args.max_ring][0]))

    disparities = np.arange(min_disp, max_disp, (max_disp - min_disp) /
                            num_disp)  #16.0 / max_lens_dist)
    #disparities = np.arange(min_disp, 0.7 * diam, 4.0 / max_lens_dist)
    print("Disparities: {0}".format(disparities))

    strategy_args = dict()
    selection_strategy = None

    if args.method == 'plain':
        fine_costs, coarse_costs, coarse_costs_merged, lens_variance, num_comparisons = calc_costs_plain(
            lenses, disparities, nb_offsets, args.max_cost, technique)
    elif args.method == 'real_lut':
        strategy_args = dict()
        strategy_args['target_lenses'] = _precalc_angular()
        strategy_args['min_disp'] = min_disp
        strategy_args['max_disp'] = max_disp
        strategy_args['trade_off'] = args.lut_trade_off
        selection_strategy = real_lut

    if selection_strategy is not None:
        print("Selection strategy: {0}".format(selection_strategy))
        fine_costs, coarse_costs, coarse_costs_merged, lens_variance, num_comparisons, disp_avg = calc_costs_selective_with_lut(
            lenses,
            disparities,
            selection_strategy,
            args.technique,
            nb_args=strategy_args,
            refine=args.refine,
            max_cost=args.max_cost)

    if args.coarse is True:
        coarse_disp = regularize_coarse(lenses,
                                        coarse_costs_merged,
                                        disparities,
                                        penalty1=args.coarse_penalty1,
                                        penalty2=args.coarse_penalty2)
        fine_costs = augment_costs_coarse(fine_costs,
                                          coarse_disp,
                                          lens_variance,
                                          disparities,
                                          coarse_weight=args.coarse_weight,
                                          struct_var=args.struct_var)

    fine_disps, fine_disps_interp, fine_val, wta_depths, wta_depths_interp, wta_val, confidence = regularized_fine(
        lenses,
        fine_costs,
        disparities,
        args.penalty1,
        args.penalty2,
        args.max_cost,
        conf_sigma=args.conf_sigma)

    Dsgm = rtxrender.render_lens_imgs(lenses, fine_disps_interp)
    Dwta = rtxrender.render_lens_imgs(lenses, wta_depths_interp)

    lens_data = dict()
    col_data = dict()
    if scene_type == 'synth':
        gt_disp = dict()

    for lcoord in lenses:
        lens_data[lcoord] = lenses[lcoord].img
        col_data[lcoord] = lenses[lcoord].col_img
        if scene_type == 'synth':
            gt_disp[lcoord] = lenses[lcoord].disp_img

    I = rtxrender.render_lens_imgs(lenses, lens_data)
    Dconf = rtxrender.render_lens_imgs(lenses, confidence)
    Icol = rtxrender.render_lens_imgs(lenses, col_data)
    #pdb.set_trace()
    new_offset = [
        lenses[0, 0].pcoord[0] - (Icol.shape[0] / 2),
        lenses[0, 0].pcoord[1] - (Icol.shape[1] / 2)
    ]

    Dcoarse = None
    if args.coarse is True:
        Dcoarse = rtxrender.render_lens_imgs(lenses, coarse_disp)

    if scene_type == 'synth':
        Dgt = rtxrender.render_lens_imgs(lenses, gt_disp)
        error_measurements = analyze_disp(lenses, fine_disps_interp, True)
    else:
        Dgt = None
        sgm_err = None
        wta_err = None
        sgm_err_mask = None
        sgm_err_mse = None
        err_img_r = None
        img_s = None
        error_measurements = None

    return Icol, Dsgm, Dwta, Dgt, Dconf, Dcoarse, disparities, num_comparisons, disp_avg, new_offset, error_measurements
Exemple #2
0
import plenopticIO.imgIO as imgIO
import rendering.render as rnd
import matplotlib.pyplot as plt
import sys

path = sys.argv[1]

# read the image and store it into a dictionary with all informations
lenses, scene_type = imgIO.load_scene(path)

# create another dictionary with only colored image (no other informations stored)
lens_imgs = dict()

for key in lenses:
    lens_imgs[key] = lenses[key].col_img
    
# render the iamge
img = rnd.render_lens_imgs(lenses, lens_imgs)
    
# show the image
plt.imshow(img)
plt.show()    
Exemple #3
0
import plenopticIO.imgIO as imgIO
import rendering.render as rnd
import matplotlib.pyplot as plt
import sys

path = sys.argv[1]

# read the image and store it into a dictionary with all informations
lenses = imgIO.load_scene(path)

# create another dictionary with only colored image (no other informations stored)
lens_imgs = dict()

for key in lenses:
    lens_imgs[key] = lenses[key].col_img
    
# render the iamge
img = rnd.render_lens_imgs(lenses, lens_imgs)
    
# show the image
plt.imshow(img)
plt.show()