bpdl.utilities module¶
The basic module for generating synthetic images and also loading / exporting
Copyright (C) 2015-2020 Jiri Borovec <jiri.borovec@fel.cvut.cz>
-
bpdl.utilities.
convert_numerical
(s)[source]¶ try to convert a string tu numerical
- Parameters
s (str) – input string
- Returns
>>> convert_numerical('-1') -1 >>> convert_numerical('-2.0') -2.0 >>> convert_numerical('.1') 0.1 >>> convert_numerical('-0.') -0.0 >>> convert_numerical('abc58') 'abc58'
-
bpdl.utilities.
create_clean_folder
(path_dir)[source]¶ create empty folder and while the folder exist clean all files
- Parameters
path_dir (str) – path
- Return str
>>> path_dir = os.path.abspath('sample_dir') >>> path_dir = create_clean_folder(path_dir) >>> os.path.exists(path_dir) True >>> shutil.rmtree(path_dir, ignore_errors=True)
-
bpdl.utilities.
estimate_max_circle
(point, direction, points, max_diam=1000, step_tol=0.001)[source]¶ find maximal circe from a given pont in orthogonal direction which just touch the curve with points
- Parameters
- Returns
>>> y = [1] * 10 >>> pts = np.array(list(zip(range(len(y)), y))) >>> estimate_max_circle([5, 1], [0, 1], pts) 999.99... >>> y = [1] * 6 + [2] * 4 >>> pts = np.array(list(zip(range(len(y)), y))) >>> estimate_max_circle([4, 1], [0, 1], pts) 4.99...
-
bpdl.utilities.
estimate_point_max_circle
(idx, points, tangent_smooth=1, orient=1.0, max_diam=1000000.0, step_tol=0.001)[source]¶ estimate maximal circle from a particular point on curve
- Parameters
- Returns
>>> y = [1] * 25 + list(range(1, 50)) + [50] * 25 >>> pts = np.array(list(zip(range(len(y)), y))) >>> estimate_point_max_circle(0, pts) 60.38... >>> estimate_point_max_circle(30, pts) 17.14... >>> estimate_point_max_circle(90, pts) 999999.99...
-
bpdl.utilities.
estimate_rolling_ball
(points, tangent_smooth=1, max_diam=1000000.0, step_tol=0.001)[source]¶ roll a ball over curve and get for each particular position a maximal ball which does not intersect the rest of curve
- Parameters
points –
tangent_smooth –
max_diam –
step_tol –
- Returns
>>> y = [1] * 6 + [2] * 4 >>> pts = np.array(list(zip(range(len(y)), y))) >>> diams = estimate_rolling_ball(pts) >>> list(map(int, diams[0])) [24, 18, 12, 8, 4, 1, 9, 999999, 999999, 999999] >>> list(map(int, diams[1])) [999999, 999999, 999999, 999999, 999999, 10, 1, 4, 8, 12]
-
bpdl.utilities.
generate_gauss_2d
(mean, std, im_size=None, norm=None)[source]¶ Generating a Gaussian distribution in 2D image
- Parameters
- Return ndarray
>>> im = generate_gauss_2d([4, 5], [[1, 0], [0, 2]], (8, 10), norm=1.) >>> np.round(im, 1) array([[ 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ], [ 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ], [ 0. , 0. , 0. , 0.1, 0.1, 0.1, 0.1, 0.1, 0. , 0. ], [ 0. , 0.1, 0.2, 0.4, 0.5, 0.6, 0.5, 0.4, 0.2, 0.1], [ 0. , 0.1, 0.3, 0.6, 0.9, 1. , 0.9, 0.6, 0.3, 0.1], [ 0. , 0.1, 0.2, 0.4, 0.5, 0.6, 0.5, 0.4, 0.2, 0.1], [ 0. , 0. , 0. , 0.1, 0.1, 0.1, 0.1, 0.1, 0. , 0. ], [ 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ]]) >>> im = generate_gauss_2d([2, 3], [[1., 0], [0, 1.2]]) >>> np.round(im, 2) array([[ 0. , 0. , 0.01, 0.02, 0.01, 0. , 0. , 0. ], [ 0. , 0.02, 0.06, 0.08, 0.06, 0.02, 0. , 0. ], [ 0.01, 0.03, 0.09, 0.13, 0.09, 0.03, 0.01, 0. ], [ 0. , 0.02, 0.06, 0.08, 0.06, 0.02, 0. , 0. ], [ 0. , 0. , 0.01, 0.02, 0.01, 0. , 0. , 0. ]])