Example #1
0
def save_xml(filename, lenses):
    """
    Saves a synthetic dataset in the Raytrix Format: PNG Image file + xml config
    
    Attention: The PNG File is saved as a 4 channel PNG

    Parameters
    ----------

    filename: string
      The filename for the target files. If filename
      is <path>/file the target files are <path>/file.png, <path>/file.xml

    lenses: dictionary
      Dictionary of lenses, keys are axial coordinates
      
    """

    # extract the images as a seperate dictionary for the rendering process
    lens_data = dict()
    disp_data = dict()
    for lcoord in lenses:
        lens_data[lcoord] = lenses[lcoord].col_img
        disp_data[lcoord] = lenses[lcoord].disp_img

    # render the MLA image
    img = rtxrnd.render_lens_imgs(lenses, lens_data)
    disp = rtxrnd.render_lens_imgs(lenses, disp_data)

    h, w = img.shape[0], img.shape[1]
    m = ((h - 1) / 2.0, (w - 1) / 2.0)
    offset = lenses[0, 0].pcoord - np.array(m)

    l = lenses[0, 0]
    config_template = _xml_template()
    config = config_template.substitute(offset_y=offset[0],
                                        offset_x=offset[1],
                                        diam=l.diameter,
                                        angle=0,
                                        lens_border=1.0)

    img_filename = "{0}.png".format(filename)
    disp_filename = "{0}_disp.png".format(filename)
    config_filename = "{0}.xml".format(filename)

    with open(config_filename, "w") as f:
        f.write(config)

    plt.imsave(img_filename, img)
    plt.imsave(disp_filename, disp, cmap='jet')

    return config
Example #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()    
Example #3
0
    lenses = rtxsio.load_from_json(lensespath)
    #..synthetic_images/
    real_path = "/data1/palmieri/2018/October/testplenoptic/{0}".format(
        picname)

    # save the .xml file
    rtxsio.save_xml(real_path, lenses)

    lens_imgs = dict()
    disp_imgs = dict()

    for key in lenses:
        lens_imgs[key] = lenses[key].col_img
        disp_imgs[key] = lenses[key].disp_img

    img = rtxrnd.render_lens_imgs(lenses, lens_imgs)
    disp = rtxrnd.render_lens_imgs(lenses, disp_imgs)

    # save the colored image
    plt.imsave(
        "/data1/palmieri/2018/October/testplenoptic/{0}.png".format(picname),
        img)
    plt.imsave(
        "/data1/palmieri/2018/October/testplenoptic/{0}_disp.png".format(
            picname),
        disp,
        vmin=np.min(disp),
        vmax=np.max(disp),
        cmap='jet')
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
Example #5
0
    parser.add_argument(dest='input_filename', nargs=1, help="Name of the lens config file")
    parser.add_argument('-o', dest='output_path', default='./')
    
    args = parser.parse_args()

    filename, ext = args.input_filename[0].split(".")
    config_file = filename + ".xml"
    
    if os.path.exists(args.output_path) is False:
        raise OSError('Path {0} does not exist'.format(args.output_path))

    lenses = imgio.load_from_xml(args.input_filename[0], config_file)

    lens_imgs = dict()
    for key in lenses:
        lens_imgs[key] = lenses[key].col_img
    microimg = imgrend.render_lens_imgs(lenses, lens_imgs)    
    subapertimg, dimensions, shape = map_from_micro_images_to_subaperture_images(lenses, lens_imgs) 
    plt.subplot(121)
    plt.title("MicroImages")
    plt.imshow(microimg)
    plt.subplot(122)
    plt.title("Subaperture Views")
    plt.imshow(subapertimg)
    plt.show()
    
    subapertureimg = filename + "_subarpertureimages.png"
    plt.imsave(subapertureimg, subapertimg)