Example #1
0
def point_shape_context(pt, cloud, hist_dim):
    cloud = np.atleast_2d(cloud) - np.atleast_2d(pt)

    r = math_utils.norms(cloud,1)
    r_med = np.median(r)
    
    if hist_dim == 2:
        
        num_r_bins = 4
        num_theta_bins = 9
        
        r_bin_edges = r_med/2**(num_r_bins-1) * 2**np.arange(0, num_r_bins+1)
        theta = np.arctan2(cloud[:,1], cloud[:,0])
        theta_bin_edges = np.linspace(-np.pi, np.pi, num_theta_bins+1, endpoint = True)

        hist,_,_ = np.histogram2d(r,theta, bins = (r_bin_edges, theta_bin_edges))
        
        areas = np.pi * (r_bin_edges[1:]**2 - r_bin_edges[:-1]**2)/num_theta_bins
        
        features = ((areas**(-1/2))[:,None] * hist).flatten()
        features /= features.sum()
        
        return features
        
        
    else:
        raise NotImplementedError
Example #2
0
def unif_resample(x,n,tol=1,deg=3):    
    x = np.atleast_2d(x)
    x = mu.remove_duplicate_rows(x)
    dl = mu.norms(x[1:] - x[:-1],1)
    l = np.cumsum(np.r_[0,dl])
    (tck,_) = si.splprep(x.T,k=deg,s = tol**2*len(x),u=l)
    
    newu = np.linspace(0,l[-1],n)
    return np.array(si.splev(newu,tck)).T
Example #3
0
def unif_resample(x,n,tol=0,deg=None):    
    if deg is None: deg = min(3, len(x) - 1)

    x = np.atleast_2d(x)
    x = math_utils.remove_duplicate_rows(x)
    dl = math_utils.norms(x[1:] - x[:-1],1)
    l = np.cumsum(np.r_[0,dl])
    
    (tck,_) = si.splprep(x.T,k=deg,s = tol**2*len(x),u=l)

    newu = np.linspace(0,l[-1],n)
    return np.array(si.splev(newu,tck)).T    
Example #4
0
def unif_resample(x,n,weights,tol=.001,deg=3):    
    x = np.atleast_2d(x)
    weights = np.atleast_2d(weights)
    x = mu.remove_duplicate_rows(x)
    x_scaled = x * weights
    dl = mu.norms(x_scaled[1:] - x_scaled[:-1],1)
    l = np.cumsum(np.r_[0,dl])
    (tck,_) = si.splprep(x_scaled.T,k=deg,s = tol**2*len(x),u=l)
    
    newu = np.linspace(0,l[-1],n)
    out_scaled = np.array(si.splev(newu,tck)).T
    out = out_scaled/weights
    return out