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_vague_local(R, threshold=50, per=np.pi / 3): ''' Create a image in which the maximum pixels form a circular wave having a radius R Parameters ---------- R : float Radius of the circle threshold: float, optional Every pixel of which the value is less than this threshold is set to 0 per: float, optional Periodicity of the wave 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] r_nb = 200 rough_dict = {'lwr': 10} my_sgeom = rand_circle(R, 0, 0, r_nb, rough_dict, per) 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.arr[img.arr < threshold] = 0 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_fluctuation(): img_shape = (512, 512) frame_bounds = [-256, 256, -256, 256] R = 25 r_nb = 150 rough_dict = {'lwr': 10} r_per = np.pi / 3 my_sgeom = rand_circle(R, 0, 0, r_nb, rough_dict, r_per) 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_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_rect(): ''' Create a image in which the maximum pixels form a rectangular ''' img_shape = (512, 512) frame_bounds = [-256, 256, -256, 256] my_sgeom = SGeom(box(-100, -50, 100, 50)) 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 plot_coll(): img_shape = (512, 512) frame_bounds = [-256, 256, -256, 256] R = 25 c = np.array([0, 0]) phi = np.linspace(0, 2 * np.pi, 1000) x = c[0] + R * np.cos(phi) y = c[1] + R * np.sin(phi) dat = np.array([x, y]).T my_sgeom = SGeom(Polygon(dat)) 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_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