def distance_vs_roughness(n_init, gamma, ba): ''' Computing the distance between the target and the final curve with respect to roughness of circular wave. In this function we fix the number of initial points, gamma, beta/alpha and the peiodicity ''' lwr_lst = np.linspace(10, 50, 10) spl = spline_initialize(R=200, n_init=n_init) dist = np.zeros_like(lwr_lst) plt.rcParams["font.family"] = "serif" for i, data in enumerate(lwr_lst): spl_c = copy.deepcopy(spl) pts_ref = get_pts_from_sgeom_vague(R=50, lwr=data) img, _ = create_vague(R=50, lwr=data) opti = optimize(spline=spl_c, method='slsqp', img=img, jac=None, ba_ratio=data, gamma=gamma) lst = np.reshape(opti.x, (len(opti.x) / 2, 2)) spl.set_ctrl_pts(lst, only_free=True) pts = spl(np.linspace(0, 1, 10000)) dist[i] = distance_between_curves(pts_ref, pts) plt.plot(lwr_lst, dist) plt.title(u"Nombre de points de contrôle = " + str(n_init) + r', $\gamma = $' + str(gamma) + r', $\beta/\alpha = $' + str(ba)) plt.xlabel(u'Rugosité') plt.ylabel('Distance') plt.show()
def distance_vs_gamma(ba, n_init): ''' Computing the distance between the target and the final curve with respect to gamma. In this function we fix the beta/alpha and number of initial points ''' spl = spline_initialize(R=200, n_init=n_init) img, imsh = create_vague(R=50) gamma_lst = np.linspace(40, 200, 20) dist = np.zeros_like(gamma_lst) pts_ref = get_pts_from_sgeom_vague(R=50) plt.rcParams["font.family"] = "serif" for i, dat in enumerate(gamma_lst): spl_c = copy.deepcopy(spl) opti = optimize(spline=spl_c, method='slsqp', img=img, gamma=dat, ba_ratio=ba, jac=None) lst = np.reshape(opti.x, (len(opti.x) / 2, 2)) spl_c.set_ctrl_pts(lst, only_free=True) pts = spl_c(np.linspace(0, 1, 10000)) dist[i] = distance_between_curves(pts_ref, pts) plt.plot(gamma_lst, dist) plt.title(r"$\beta/\alpha = $" + str(ba) + u', nombre de points de contrôle = ' + str(n_init)) plt.xlabel(r'$\gamma$') plt.ylabel('Distance') plt.show()
def distance_vs_n_init(ba, gamma): ''' Computing the distance between the target and the final curve with respect to number of initial points. In this function we fix the beta/alpha and gamma ''' nbr_lst = np.linspace(5, 40, 20) img, _ = create_vague(R=50) dist = np.zeros_like(nbr_lst) nbr_lst = nbr_lst.astype(int) pts_ref = get_pts_from_sgeom_vague(R=50) plt.rcParams["font.family"] = "serif" for i, data in enumerate(nbr_lst): spl = spline_initialize(R=200, n_init=data) opti = optimize(spline=spl, method='slsqp', img=img, gamma=gamma, ba_ratio=ba, jac=None) lst = np.reshape(opti.x, (len(opti.x) / 2, 2)) spl.set_ctrl_pts(lst, only_free=True) pts = spl(np.linspace(0, 1, 10000)) dist[i] = distance_between_curves(pts_ref, pts) plt.plot(nbr_lst, dist) plt.title(r"$\beta/\alpha = $" + str(ba) + r', $\gamma = $' + str(gamma)) plt.xlabel(u'Nombre de points de contrôle') plt.ylabel('Distance') plt.show()
def optimize_image(jaco): ''' A module of optimisation for the Active Contour. However, it is only effective for the traditional method of jacobian ''' spl = spline_initialize(R=200, n_init=7) img, imsh = create_vague(50) imsh.plot(label='Vrai contour') spl.plot_spline(label='Courbe initiale') st = timeit.default_timer() opti = optimize(spline=spl, method='slsqp', img=img, gamma=75., ba_ratio=100, jac=jaco) # ed = timeit.default_timer() # print ed - st lst = np.reshape(opti.x, (len(opti.x) / 2, 2)) spl.set_ctrl_pts(lst, only_free=True) spl.plot_spline(label='Courbe finale') [x, y] = lst.T plt.scatter(x, y) plt.title(u"Nombre de points de contrôle = 7" + r', $\gamma = 75$' + r', $\beta/\alpha = 100$') # plt.title(u'Rugosité = 60') plt.legend() plt.show()
def distance(ba, gamma, n_init, per=np.pi / 3): ''' Computing the distance between the final curve and the contour with respect to parameters like ba_ratio, gamma, number of initial points ''' ref_pts = get_pts_from_sgeom_circle(R=50) spl = spline_initialize(R=200, n_init=n_init) img, _ = create_circle(R=50) opti = optimize(spline=spl, method='slsqp', img=img, jac=None, ba_ratio=ba, gamma=gamma) lst = np.reshape(opti.x, (len(opti.x) / 2, 2)) spl.set_ctrl_pts(lst, only_free=True) pts = spl(np.linspace(0, 1, 3000)) dist = distance_between_curves(ref_pts, pts) print dist