コード例 #1
0
    def test(i, j, Type):
        if cached[i][j]:
            return True
        elif Type == "elevation":
            cached[i][j] = cached[j][i] = True
            curvature_tol = parameters.MAX_LINEAR_ACCEL / \
                            parameters.MAX_SPEED**2

            def curvature(i, j):  # Computes the curvature of the clothoid
                x0, x1 = [s[i], s[j]]
                y0, y1 = [z[i], z[j]]
                tht0, tht1 = [0, 0]
                k, K, L = clothoid.build_clothoid(x0, y0, tht0, x1, y1, tht1)
                extremal_curvatures = [k + L * K, k]
                return max(np.absolute(extremal_curvatures))
            return curvature(i, j) > curvature_tol

        elif Type == "velocity":
            cached[i][j] = cached[j][i] = True
            dz = np.absolute(z[j] - z[i])
            ds = s[j] - s[i]
            v = (z[j] + z[i]) / 2

            C = parameters.MAX_LINEAR_ACCEL / v
            D = parameters.JERK_TOL / v**2

            def dz_tol(s):
                if s < 2 * C / D:
                    return (s / 2)**2 * D
                else:
                    return (s - C / D) * C
            return dz > dz_tol(ds)
コード例 #2
0
ファイル: ialis.py プロジェクト: mmssouza/Curvature
    aux = str_path + prefix_path[i+2] + prefix_str + str(j) + postfix_str[i]
    fil.append(aux)  

# Para cada imagem, coleta dados dos arquivos
for fi_lst,fdo in zip(file_in_list[3:],file_out_list):
 
 for fcx,fcy,fgt,fi in zip(file_in_list[0],file_in_list[1],file_in_list[2],fi_lst):
  # Determina pontos do contorno
 # print "{0}, {1}, {2}, {3}, {4}".format(fcx,fcy,fgt,fi,fo)
  cix = np.genfromtxt(fcx,dtype=int)
  ciy = np.genfromtxt(fcy,dtype=int)
  z = np.ndarray((cix.size),dtype = complex)
  for i,x,y in zip(arange(z.size),cix,ciy):
    z[i] = complex(x,y) 
  # Determina ground truth
  gt  = np.genfromtxt(fgt,dtype=int)
  gt  = gt - 1
  # Determina resposta do metodo
  dm = np.genfromtxt(fi,dtype=int)
  dm = dm - 1
  # Calcula curvatura
  k = curvature(z,sigma_range)
  E_gt = msbe(k,gt,sigma)
  E_metodo = msbe(k,dm,sigma)

  print >> fdo,"{0}\t{1}".format(E_metodo, E_gt)
  #print "{0}, {1}, {2}, {3}, {4} -> E_gt = {5}, E_metodo = {6}".format(fcx,fcy,fgt,fi,fo,E_gt,E_metodo)
  #print "z.size = {0}, k.curvs.shape = {1}".format(z.size,k.curvs.shape)
 fdo.close()
 
コード例 #3
0
import glob
from numpy import *
from scipy.interpolate import interp1d
from matplotlib.pyplot import *
from curvature import *

lwidth = 2.
fsize = 10
N = 5
# s = vetor que armazena diferentes valores de desvio padrao sigma da gaussiana
# utilizada para janela de suavizacao 
sigma_range = logspace(-0.05,0.7,N)
s = sigma_range

# Instancializa objeto
c1 = curvature(sys.argv[1],sigma_range,smooth="Gaussian",order = 1)
c2 = curvature(sys.argv[1],sigma_range,smooth="Average",order = 1)
c3 = curvature(sys.argv[1],sigma_range,smooth="Average",order = 10)
c4 = curvature(sys.argv[1],sigma_range,smooth="Average",order = 20)
figure(1)

subplot(221)
#plot(c1.z.real,c1.z.imag,lw=lwidth)
xlabel('x',fontsize=fsize)
ylabel('y',fontsize=fsize)
caux = c1.z - c1.rcontours[0]
for i in arange(1,N):
 c2[ = c1.rcontours[i]-c1.rcontours[i-1]
 plot(caux.real,caux.imag,lw=lwidth)
 
 
コード例 #4
0
ファイル: ialis.py プロジェクト: mutual-ai/Curvature
                                     2] + prefix_str + str(j) + postfix_str[i]
        fil.append(aux)

# Para cada imagem, coleta dados dos arquivos
for fi_lst, fdo in zip(file_in_list[3:], file_out_list):

    for fcx, fcy, fgt, fi in zip(file_in_list[0], file_in_list[1],
                                 file_in_list[2], fi_lst):
        # Determina pontos do contorno
        # print "{0}, {1}, {2}, {3}, {4}".format(fcx,fcy,fgt,fi,fo)
        cix = np.genfromtxt(fcx, dtype=int)
        ciy = np.genfromtxt(fcy, dtype=int)
        z = np.ndarray((cix.size), dtype=complex)
        for i, x, y in zip(arange(z.size), cix, ciy):
            z[i] = complex(x, y)
        # Determina ground truth
        gt = np.genfromtxt(fgt, dtype=int)
        gt = gt - 1
        # Determina resposta do metodo
        dm = np.genfromtxt(fi, dtype=int)
        dm = dm - 1
        # Calcula curvatura
        k = curvature(z, sigma_range)
        E_gt = msbe(k, gt, sigma)
        E_metodo = msbe(k, dm, sigma)

        print >> fdo, "{0}\t{1}".format(E_metodo, E_gt)
        #print "{0}, {1}, {2}, {3}, {4} -> E_gt = {5}, E_metodo = {6}".format(fcx,fcy,fgt,fi,fo,E_gt,E_metodo)
        #print "z.size = {0}, k.curvs.shape = {1}".format(z.size,k.curvs.shape)
    fdo.close()
コード例 #5
0
# curve evolution with data term
num_of_iterations = 20
num_of_class_conf = {'aircraft': 1, 'MNIST': 10}
num_of_classes = num_of_class_conf[dataset_name]
num_of_shapes_in_each_class = 10

pose_for_each_class = np.zeros((num_of_classes, 4))
pose_for_each_class[:, 3] = 1
dt = 0.2  # gradient step size

for i in range(num_of_iterations):
    print('iters %d' % i)
    narrow_band = create_narrow_band(psi, 5)

    kappa = curvature(test_image_file['testImage'])
    psi, pose_for_each_class = evolve_with_data_term(
        test_image_file['testImage'].flatten(), psi.flatten(),
        narrow_band.flatten(), training_matrix.flatten(),
        pose_for_each_class.flatten(), num_of_classes,
        num_of_shapes_in_each_class, dt, i + 1, num_of_iterations,
        kappa.flatten(), size_i, size_j)

    psi = psi.reshape((size_i, size_j))
    pose_for_each_class = pose_for_each_class.reshape((4, num_of_classes))

plt.imshow(test_image_file['testImage'], cmap='gray')
plt.contour(psi, levels=[0], colors='r')
plt.hold(True)
plt.show()
コード例 #6
0
from os.path import *
from re import *
from numpy import *
from matplotlib.pyplot import *
import matplotlib.image as img

sys.path.append("../")
from curvature import *
from BendEnergy import *

figure()
ax = subplot(121)
sigma = logspace(-0.3,1.8,200)
for im_file in sys.argv[1:]:
 if isfile(im_file):
  k = curvature(im_file,sigma)
  nmbe  = BendEnergy(k)
  ax.plot(log(nmbe.sigma),log(nmbe()),linewidth = 3.0,label = im_file)
  r = compile("bmp$")
  if r.search(im_file):
   aux = r.sub("dat",im_file) 
   fout = open(aux,"w")
   print >>fout,"%",im_file,"\n"
   print >>fout,"Col1 : nmbe   Col2: log(nmbe)\n\n"
   for a in nmbe.phi:
    print >> fout,"{0}\t{1}".format(a,log(a))
   fout.close() 
h,l = ax.get_legend_handles_labels()
ax.legend(h[::-1],l[::-1],loc=3)
ylabel('NMBE',fontsize=15)
xlabel('Scale',fontsize=15)
コード例 #7
0
ファイル: curvograma.py プロジェクト: mmssouza/Curvature
from curvature import *

lwidth = 2.
fsize = 20
# s = vetor que armazena diferentes valores de desvio padrao sigma da gaussiana
# utilizada para janela de suavizacao 
sigma_range = linspace(0.5,30.0,20)
s = sigma_range

# Le a curvatura analitica do arquivo de entrada
ana = fromfile(sys.argv[1],dtype=float,sep="\n")

tf = arange(ana.size)/float(ana.size-1)

# Instancializa objeto
c = curvature(sys.argv[2],sigma_range)

# Curvograma k(sigma,t)
curvs = ndarray((s.size,c.t.size),dtype="float")
for i in arange(s.size):
  curvs[i] = copy(c(i))

###########################################
# Apresentacao dos resultados em figuras
###########################################
# Figura 1 : Contorno original e reconstruido
# para o menor valor de sigma
###########################################
figure(1)

subplot(331)
コード例 #8
0
ファイル: curvograma.py プロジェクト: mutual-ai/Curvature
from curvature import *

lwidth = 2.
fsize = 20
# s = vetor que armazena diferentes valores de desvio padrao sigma da gaussiana
# utilizada para janela de suavizacao
sigma_range = linspace(0.5, 30.0, 20)
s = sigma_range

# Le a curvatura analitica do arquivo de entrada
ana = fromfile(sys.argv[1], dtype=float, sep="\n")

tf = arange(ana.size) / float(ana.size - 1)

# Instancializa objeto
c = curvature(sys.argv[2], sigma_range)

# Curvograma k(sigma,t)
curvs = ndarray((s.size, c.t.size), dtype="float")
for i in arange(s.size):
    curvs[i] = copy(c(i))

###########################################
# Apresentacao dos resultados em figuras
###########################################
# Figura 1 : Contorno original e reconstruido
# para o menor valor de sigma
###########################################
figure(1)

subplot(331)