def initialize(): # initialize the spline c = np.array([0, 0]) R = 100.0 nbr_init = 30 phi = np.linspace(0, 2.0 * np.pi, nbr_init) x_init = c[0] + R * np.cos(phi) y_init = c[1] + R * np.sin(phi) x_init[nbr_init - 1] = x_init[0] y_init[nbr_init - 1] = y_init[0] tck, _ = splprep([x_init, y_init], s=0, per=1) spl = BSpline_periodic(tck[0], np.transpose(tck[1]), tck[2], is_periodic=True) # create an image img_shape = (512, 512) frame_bounds = [-256, 256, -256, 256] my_sgeom = circle(100, 0, 0) strat = lscad.MountainStrategy() param_dict = {'hmax': 100., 'sigma': (0, 0)} tmp = fk_img.img_from_sgeom(img_shape, frame_bounds, my_sgeom, z_map_strategy=strat, param_dict=param_dict) x, y = tmp.arrf.sampling_vectors() img = RectBivariateSpline(x, y, np.flipud(tmp.arr)) return spl, img
def create_image(R): ''' Create a image in which the maximum pixels form a circle having a radius R Parameters ---------- R : float Radius of the circle Returns ------- img_xy : RectBivariate object A narray whose values at non-integer coordinates are available thanks to interpolation imsh : ImShape object A object which helps to display the contour and the image ''' img_shape = (512, 512) frame_bounds = [-256, 256, -256, 256] my_sgeom = circle(R, 0, 0) strat = lscad.MountainStrategy() param_dict = {'hmax': 100., 'sigma': (0, 0)} img = fk_img.img_from_sgeom(img_shape, frame_bounds, my_sgeom, z_map_strategy=strat, param_dict=param_dict) x, y = img.arrf.sampling_vectors() img_xy = interpolate.RectBivariateSpline(x, y, np.flipud(img.arr)) gcoll = GeomCollection() gcoll.set_geom(0, my_sgeom) imsh = ImShape(image=img, geom_coll=gcoll) return img_xy, imsh
def create_circle_1(): img_shape = (512, 512) frame_bounds = [-256, 256, -256, 256] R = 25 my_sgeom = circle(R, 0, 0) strat = lscad.MountainStrategy() param_dict = {'hmax': 100., 'sigma': (0, 0)} img = fk_img.img_from_sgeom(img_shape, frame_bounds, my_sgeom, z_map_strategy=strat, param_dict=param_dict) img.plot() plt.show()
def get_pts_from_sgeom_circle(R): ''' Get a referenced points from Sgeom object in order to compute the distance between the target and the final curve. In this case, it is from image of circle ''' sgeom = circle(R, 0, 0) xy_arr = sgeom.get_xy()[0] x_arr = xy_arr[:, 0] y_arr = xy_arr[:, 1] tck, _ = spline.build_spline(x_arr, y_arr, per=True, k=3) knots = tck[0] ctrl_pts = np.transpose(tck[1]) deg = tck[2] spl = BSpline_periodic(knots, ctrl_pts, deg, is_periodic=True) return spl(np.linspace(0, 1, 10000))
def create_2ob(): img_shape = (512, 512) frame_bounds = [-256, 256, -256, 256] R = 25 my_sgeom_1 = circle(R, -100, 0) my_sgeom_2 = SGeom(box(0, 0, 100, 50)) my_geom = MultiPolygon([my_sgeom_1.geom, my_sgeom_2.geom]) my_sgeom = SGeom(my_geom, label='circle_square') strat = lscad.MountainStrategy() param_dict = {'hmax': 100., 'sigma': (0, 0)} img = fk_img.img_from_sgeom(img_shape, frame_bounds, my_sgeom, z_map_strategy=strat, param_dict=param_dict) gcoll = GeomCollection() gcoll.set_geom(0, my_sgeom) imsh = ImShape(image=img, geom_coll=gcoll) imsh.plot() plt.show()
def create_noisy_circle(R): img_shape = (512, 512) frame_bounds = [-256, 256, -256, 256] my_sgeom = circle(R, 0, 0) strat = lscad.MountainStrategy() param_dict = {'hmax': 100., 'sigma': (0, 0)} img = fk_img.img_from_sgeom(img_shape, frame_bounds, my_sgeom, z_map_strategy=strat, param_dict=param_dict) mu, sigma = 0, 10 noise = np.random.normal(mu, sigma, img.arr.shape).astype(float) noisy_img = img.arr + noise x, y = img.arrf.sampling_vectors() img_xy = interpolate.RectBivariateSpline(x, y, np.flipud(noisy_img)) gcoll = GeomCollection() gcoll.set_geom(0, my_sgeom) imsh = ImShape(image=img, geom_coll=gcoll) imsh.plot() plt.show()
def create_2ob(): ''' Create a image in which the maximum pixels form 2 objects ''' img_shape = (512, 512) frame_bounds = [-256, 256, -256, 256] R = 25 my_sgeom_1 = circle(R, -100, 0) my_sgeom_2 = SGeom(box(0, 0, 100, 50)) my_geom = MultiPolygon([my_sgeom_1.geom, my_sgeom_2.geom]) my_sgeom = SGeom(my_geom, label='circle_square') strat = lscad.MountainStrategy() param_dict = {'hmax': 100., 'sigma': (0, 0)} img = fk_img.img_from_sgeom(img_shape, frame_bounds, my_sgeom, z_map_strategy=strat, param_dict=param_dict) x, y = img.arrf.sampling_vectors() img_xy = interpolate.RectBivariateSpline(x, y, np.flipud(img.arr)) gcoll = GeomCollection() gcoll.set_geom(0, my_sgeom) imsh = ImShape(image=img, geom_coll=gcoll) return img_xy, imsh