Module API

ASTROALIGN aligns stellar images using no WCS information.

It does so by finding similar 3-point asterisms (triangles) in both images and deducing the affine transformation between them.

General registration routines try to match feature points, using corner detection routines to make the point correspondence. These generally fail for stellar astronomical images, since stars have very little stable structure and so, in general, indistinguishable from each other.

Asterism matching is more robust, and closer to the human way of matching stellar images.

Astroalign can match images of very different field of view, point-spread functions, seeing and atmospheric conditions.

  1. Martin Beroiz

astroalign.MIN_MATCHES_FRACTION = 0.8

The minimum fraction of triangle matches to accept a transformation.

If the minimum fraction yields more than 10 triangles, 10 is used instead.

Default: 0.8

exception astroalign.MaxIterError

Raise if maximum iterations reached.

astroalign.NUM_NEAREST_NEIGHBORS = 5

The number of nearest neighbors of a given star (including itself) to construct the triangle invariants.

Default: 5

astroalign.PIXEL_TOL = 2

The pixel distance tolerance to assume two invariant points are the same.

Default: 2

astroalign.apply_transform(transform, source, target, fill_value=None, propagate_mask=False)

Apply the transformation transform to source.

The output image will have the same shape as target.

Parameters:
  • transform – A scikit-image SimilarityTransform object.

  • source – A 2D NumPy, CCData or NDData array of the source image to be transformed.

  • target – A 2D NumPy, CCData or NDData array of the target image. Only used to set the output image shape.

  • fill_value (float) – A value to fill in the areas of aligned_image where footprint == True.

  • propagate_mask (bool) – Wether to propagate the mask in source.mask onto footprint.

Returns:

aligned_image is a numpy 2D array of the transformed source. footprint is a mask 2D array with True on the regions with no pixel information.

Return type:

aligned_image, footprint

astroalign.estimate_transform(*args, **kwargs)

Lazy-loader function for skimage.transform.estimate_transform.

Full documentation: https://scikit-image.org/docs/stable/api/skimage.transform.html#skimage.transform.estimate_transform

astroalign.find_transform(source, target, max_control_points=50, detection_sigma=5, min_area=5)

Estimate the transform between source and target.

Return a SimilarityTransform object T that maps pixel x, y indices from the source image s = (x, y) into the target (destination) image t = (x, y). T contains parameters of the tranformation: T.rotation, T.translation, T.scale, T.params.

Parameters:
  • source – A 2D NumPy, CCData or NDData array of the source image to be transformed or an interable of (x, y) coordinates of the source control points.

  • target – A 2D NumPy, CCData or NDData array of the target (destination) image or an interable of (x, y) coordinates of the target control points.

  • max_control_points – The maximum number of control point-sources to find the transformation.

  • detection_sigma (int) – Factor of background std-dev above which is considered a detection. This value is ignored if input are not images.

  • min_area (int) – Minimum number of connected pixels to be considered a source. This value is ignored if input are not images.

Returns:

The transformation object and a tuple of corresponding star positions in source and target.

Return type:

T, (source_pos_array, target_pos_array)

Raises:
  • TypeError – If input type of source or target is not supported.

  • ValueError – If it cannot find more than 3 stars on any input.

  • MaxIterError – If no transformation is found.

astroalign.matrix_transform(*args, **kwargs)

Lazy-loader function for skimage.transform.matrix_transform.

Full documentation: https://scikit-image.org/docs/stable/api/skimage.transform.html#skimage.transform.matrix_transform

astroalign.register(source, target, fill_value=None, propagate_mask=False, max_control_points=50, detection_sigma=5, min_area=5)

Transform source to coincide pixel to pixel with target.

Parameters:
  • source – A 2D NumPy, CCData or NDData array of the source image to be transformed.

  • target – A 2D NumPy, CCData or NDData array of the target image. Used to set the output image shape as well.

  • fill_value – A value to fill in the areas of aligned_image where footprint == True.

  • propagate_mask (bool) – Wether to propagate the mask in source.mask onto footprint.

  • max_control_points – The maximum number of control point-sources to find the transformation.

  • detection_sigma (int) – Factor of background std-dev above which is considered a detection.

  • min_area (int) – Minimum number of connected pixels to be considered a source.

Returns:

aligned_image is a numpy 2D array of the transformed source. footprint is a mask 2D array with True on the regions with no pixel information.

Return type:

aligned_image, footprint

Raises:
  • TypeError – If input type of source or target is not supported.

  • ValueError – If it cannot find more than 3 stars on any input.

  • MaxIterError – If no transformation is found.