pose_estimation/blender/functions.py
def compute_gramian_object(render_props):
    '''
    compute the empirical observability Gramian for each render
    '''

    # scalars, vectors, and arrays
    n_states = 6 # x, y, z, x-rot, y-rot, z-rot
    n_el = 3*render_props.pix_width*render_props.pix_height
    mat = np.full((n_el, n_states), np.nan) # matrix of y^+ - y^- vectors
    # gramian for all renders
    gram = np.full((n_states, n_states, render_props.n_renders), np.nan)

    # check if background images are to be used load background image
    if render_props.bkgd_image_list is None:
        use_bkgd_image = False
    else:
        use_bkgd_image = True

    # generic save files
    temp_file_neg = os.path.join(dirs.gramian_image_save_dir,
                                 'temp_%d_neg.png')
    temp_file_pos = os.path.join(dirs.gramian_image_save_dir,
                                 'temp_%d_pos.png')

    # loop through renders
    for i in range(0, render_props.n_renders):

        # i'th position, quaternion, and perturbations
        xyz_i = render_props.xyz[:,i]
        quat_i = render_props.quat[:,i]
        if render_props.pert_xyz is None and render_props.pert_quat is None:
            pert_xyz_i, pert_quat_i = gf.standard_pert(xyz_i, quat_i,
                                                       render_props.eps)
        else:
            pert_xyz_i = render_props.pert_xyz[:,:,i]
            pert_quat_i = render_props.pert_quat[:,:,i]

        # if we are using a background image, get it
        if use_bkgd_image:
            bkgd_image = ti.load_im_np(render_props.bkgd_image_list[i])

        # set world_RGB for i'th render
        if render_props.world_RGB is None:
            world_RGB_i = None
        else:
            world_RGB_i = render_props.world_RGB[:,i]

        # loop through states
        for j in range(0, n_states):

            # perturbations in the negative direction
            temp_file_neg_j = temp_file_neg % j 
            temp_file_pos_j = temp_file_pos % j 
            pert_xyz_minus_ij = pert_xyz_i[:,2*j]
            pert_quat_minus_ij = pert_quat_i[:,2*j]
            pert_xyz_plus_ij = pert_xyz_i[:,2*j+1]
            pert_quat_plus_ij = pert_quat_i[:,2*j+1]

            # render positive & negative images
            render_image(
                cam_ob=render_props.cam_ob,
                cam_pos=render_props.cam_xyz,
                cam_quat=render_props.cam_quat,
                ob=render_props.ob,
                ob_pos=pert_xyz_minus_ij,
                ob_quat=pert_quat_minus_ij,
                image_file=temp_file_neg_j,
                world_RGB=world_RGB_i,
                alpha=render_props.alpha)

            render_image(
                cam_ob=render_props.cam_ob,
                cam_pos=render_props.cam_xyz,
                cam_quat=render_props.cam_quat,
                ob=render_props.ob,
                ob_pos=pert_xyz_plus_ij,
                ob_quat=pert_quat_plus_ij,
                image_file=temp_file_pos_j,
                world_RGB=world_RGB_i,
                alpha=render_props.alpha)

            # overlay render on background image?
            if use_bkgd_image:
                # negative
                # entries from 0 to 1
                overlay_image = ti.load_im_np(temp_file_neg_j)
                bkgd_image = ti.load_im_np(render_props.bkgd_image_list[i])
                y_minus = ti.overlay(overlay_image, bkgd_image)

                # positive
                # entries from 0 to 1
                overlay_image = ti.load_im_np(temp_file_pos_j)
                bkgd_image = ti.load_im_np(render_props.bkgd_image_list[i])
                y_plus = ti.overlay(overlay_image, bkgd_image)

            else:
                # negative
                y_minus = ti.load_im_np(temp_file_neg_j)[:,:,:3] # no alpha

                # positive
                y_plus = ti.load_im_np(temp_file_pos_j)[:,:,:3] # no alpha
            
            # compare positive to negative perturbations
            y_diff = y_plus - y_minus
            y_diff_vec = np.reshape(y_diff, n_el)
            mat[:,j] = y_diff_vec

        # compute gramian
        gram[:, :, i] = (1/(4*render_props.eps**2))*mat.T @ mat
    return gram

    compute the empirical observability Gramian for each render
    
compute the empirical observability Gramian for each render
compute the empirical observability Gramian for each render
def compute_gramian_object(render_props):
    n_states = 6 
    n_el = 3*render_props.pix_width*render_props.pix_height
    mat = np.full((n_el, n_states), np.nan) 
    gram = np.full((n_states, n_states, render_props.n_renders), np.nan)
    if render_props.bkgd_image_list is None:
        use_bkgd_image = False
    else:
        use_bkgd_image = True
    temp_file_neg = os.path.join(dirs.gramian_image_save_dir,
                                 'temp_%d_neg.png')
    temp_file_pos = os.path.join(dirs.gramian_image_save_dir,
                                 'temp_%d_pos.png')
    for i in range(0, render_props.n_renders):
        xyz_i = render_props.xyz[:,i]
        quat_i = render_props.quat[:,i]
        if render_props.pert_xyz is None and render_props.pert_quat is None:
            pert_xyz_i, pert_quat_i = gf.standard_pert(xyz_i, quat_i,
                                                       render_props.eps)
        else:
            pert_xyz_i = render_props.pert_xyz[:,:,i]
            pert_quat_i = render_props.pert_quat[:,:,i]
        if use_bkgd_image:
            bkgd_image = ti.load_im_np(render_props.bkgd_image_list[i])
        if render_props.world_RGB is None:
            world_RGB_i = None
        else:
            world_RGB_i = render_props.world_RGB[:,i]
        for j in range(0, n_states):
            temp_file_neg_j = temp_file_neg % j 
            temp_file_pos_j = temp_file_pos % j 
            pert_xyz_minus_ij = pert_xyz_i[:,2*j]
            pert_quat_minus_ij = pert_quat_i[:,2*j]
            pert_xyz_plus_ij = pert_xyz_i[:,2*j+1]
            pert_quat_plus_ij = pert_quat_i[:,2*j+1]
            render_image(
                cam_ob=render_props.cam_ob,
                cam_pos=render_props.cam_xyz,
                cam_quat=render_props.cam_quat,
                ob=render_props.ob,
                ob_pos=pert_xyz_minus_ij,
                ob_quat=pert_quat_minus_ij,
                image_file=temp_file_neg_j,
                world_RGB=world_RGB_i,
                alpha=render_props.alpha)
            render_image(
                cam_ob=render_props.cam_ob,
                cam_pos=render_props.cam_xyz,
                cam_quat=render_props.cam_quat,
                ob=render_props.ob,
                ob_pos=pert_xyz_plus_ij,
                ob_quat=pert_quat_plus_ij,
                image_file=temp_file_pos_j,
                world_RGB=world_RGB_i,
                alpha=render_props.alpha)
            if use_bkgd_image:
                overlay_image = ti.load_im_np(temp_file_neg_j)
                bkgd_image = ti.load_im_np(render_props.bkgd_image_list[i])
                y_minus = ti.overlay(overlay_image, bkgd_image)
                overlay_image = ti.load_im_np(temp_file_pos_j)
                bkgd_image = ti.load_im_np(render_props.bkgd_image_list[i])
                y_plus = ti.overlay(overlay_image, bkgd_image)
            else:
                y_minus = ti.load_im_np(temp_file_neg_j)[:,:,:3] 
                y_plus = ti.load_im_np(temp_file_pos_j)[:,:,:3] 
            y_diff = y_plus - y_minus
            y_diff_vec = np.reshape(y_diff, n_el)
            mat[:,j] = y_diff_vec
        gram[:, :, i] = (1/(4*render_props.eps**2))*mat.T @ mat
    return gram
def compute_gramian_object ( render_props ) : n_states = 6 n_el = 3 * render_props . pix_width * render_props . pix_height mat = np . full ( ( n_el , n_states ) , np . nan ) gram = np . full ( ( n_states , n_states , render_props . n_renders ) , np . nan ) if render_props . bkgd_image_list is None : use_bkgd_image = False else : use_bkgd_image = True temp_file_neg = os . path . join ( dirs . gramian_image_save_dir , 'temp_%d_neg.png' ) temp_file_pos = os . path . join ( dirs . gramian_image_save_dir , 'temp_%d_pos.png' ) for i in range ( 0 , render_props . n_renders ) : xyz_i = render_props . xyz [ : , i ] quat_i = render_props . quat [ : , i ] if render_props . pert_xyz is None and render_props . pert_quat is None : pert_xyz_i , pert_quat_i = gf . standard_pert ( xyz_i , quat_i , render_props . eps ) else : pert_xyz_i = render_props . pert_xyz [ : , : , i ] pert_quat_i = render_props . pert_quat [ : , : , i ] if use_bkgd_image : bkgd_image = ti . load_im_np ( render_props . bkgd_image_list [ i ] ) if render_props . world_RGB is None : world_RGB_i = None else : world_RGB_i = render_props . world_RGB [ : , i ] for j in range ( 0 , n_states ) : temp_file_neg_j = temp_file_neg % j temp_file_pos_j = temp_file_pos % j pert_xyz_minus_ij = pert_xyz_i [ : , 2 * j ] pert_quat_minus_ij = pert_quat_i [ : , 2 * j ] pert_xyz_plus_ij = pert_xyz_i [ : , 2 * j + 1 ] pert_quat_plus_ij = pert_quat_i [ : , 2 * j + 1 ] render_image ( cam_ob = render_props . cam_ob , cam_pos = render_props . cam_xyz , cam_quat = render_props . cam_quat , ob = render_props . ob , ob_pos = pert_xyz_minus_ij , ob_quat = pert_quat_minus_ij , image_file = temp_file_neg_j , world_RGB = world_RGB_i , alpha = render_props . alpha ) render_image ( cam_ob = render_props . cam_ob , cam_pos = render_props . cam_xyz , cam_quat = render_props . cam_quat , ob = render_props . ob , ob_pos = pert_xyz_plus_ij , ob_quat = pert_quat_plus_ij , image_file = temp_file_pos_j , world_RGB = world_RGB_i , alpha = render_props . alpha ) if use_bkgd_image : overlay_image = ti . load_im_np ( temp_file_neg_j ) bkgd_image = ti . load_im_np ( render_props . bkgd_image_list [ i ] ) y_minus = ti . overlay ( overlay_image , bkgd_image ) overlay_image = ti . load_im_np ( temp_file_pos_j ) bkgd_image = ti . load_im_np ( render_props . bkgd_image_list [ i ] ) y_plus = ti . overlay ( overlay_image , bkgd_image ) else : y_minus = ti . load_im_np ( temp_file_neg_j ) [ : , : , : 3 ] y_plus = ti . load_im_np ( temp_file_pos_j ) [ : , : , : 3 ] y_diff = y_plus - y_minus y_diff_vec = np . reshape ( y_diff , n_el ) mat [ : , j ] = y_diff_vec gram [ : , : , i ] = ( 1 / ( 4 * render_props . eps ** 2 ) ) * mat . T @ mat return gram
compute the empirical observability Gramian for each render
compute the empirical observability Gramian for each render
'''
    compute the empirical observability Gramian for each render
    ''' # scalars, vectors, and arrays # x, y, z, x-rot, y-rot, z-rot # matrix of y^+ - y^- vectors # gramian for all renders # check if background images are to be used load background image # generic save files # loop through renders # i'th position, quaternion, and perturbations # if we are using a background image, get it # set world_RGB for i'th render # loop through states # perturbations in the negative direction # render positive & negative images # overlay render on background image? # negative # entries from 0 to 1 # positive # entries from 0 to 1 # negative # no alpha # positive # no alpha # compare positive to negative perturbations # compute gramian
render_props