Check out the Hyperspy Workshop May 13-17, 2024 Online

get_ellipse_model_ransac_single_frame#

pyxem.utils.ransac_ellipse_tools.get_ellipse_model_ransac_single_frame(data, xf=128, yf=128, rf_lim=30, semi_len_min=50, semi_len_max=90, semi_len_ratio_lim=1.2, min_samples=6, residual_threshold=10, max_trials=500)[source]#

Pick a random number of data points to fit an ellipse to.

The ellipse’s constraints can be specified.

See skimage.measure.ransac for more information.

Parameters:
  • data (numpy.ndarray) – In the form [[x0, y0], [x1, y1], …]

  • xf, yf (scalar, optional) – Default 128

  • rf_lim (scalar, optional) – How far the ellipse centre can be from (xf, yf)

  • semi_len_min, semi_len_max (scalar, optional) – Limits of the semi lengths

  • semi_len_ratio_lim (scalar, optional) – Limit of the ratio of the semi length, must be equal or larger than 1. This ratio is calculated by taking the largest semi length divided by the smallest semi length: max(semi0, semi1)/min(semi0, semi1). So for a perfect circle this ratio will be 1.

  • min_samples (scalar, optional) – Minimum number of data points to fit the ellipse model to.

  • residual_threshold (scalar, optional) – Maximum distance for a data point to be considered an inlier.

  • max_trials (scalar, optional) – Maximum number of tries for the ransac algorithm.

Returns:

Model data is accessed in model_ransac.params: [x, y, semi_len0, semi_len1, rotation]

Return type:

model_ransac, inliers

Examples

>>> import pyxem.utils.ransac_ellipse_tools as ret
>>> data = ret.EllipseModel().predict_xy(
...        np.arange(0, 2*np.pi, 0.5), params=(128, 130, 50, 60, 0.2))
>>> ellipse_model, inliers = ret.get_ellipse_model_ransac_single_frame(
...        data, xf=128, yf=128, rf_lim=5, semi_len_min=45,
...        semi_len_max=65, semi_len_ratio_lim=1.4, max_trials=1000)