autoarray.inversion.mesh.image_mesh.KMeans#

class KMeans[source]#

Bases: AbstractImageMeshWeighted

Computes an image-mesh by running a weighted KMeans clustering algorithm.

This requires an adapt-image, which is the image that the KMeans algorithm adapts to in order to compute the image mesh. This could simply be the image itself, or a model fit to the image which removes certain features or noise.

For example, using the adapt image, the image mesh is computed as follows:

  1. Convert the adapt image to a weight map, which is a 2D array of weight values.

2) Run the KMeans algorithm on the weight map, such that the image mesh pixels cluster around the weight map values with higher values.

Parameters:
  • total_pixels – The total number of pixels in the image mesh and input into the KMeans algortihm.

  • weight_power

Methods

image_plane_mesh_grid_from

Returns an image mesh by running a KMeans clustering algorithm on the weight map.

mesh_pixels_per_image_pixels_from

Returns an array containing the number of mesh pixels in every pixel of the data's mask.

weight_map_from

Returns the weight-map used by the image-mesh to compute the mesh pixel centres.

Attributes

uses_adapt_images

image_plane_mesh_grid_from(mask, adapt_data)[source]#

Returns an image mesh by running a KMeans clustering algorithm on the weight map.

See the __init__ docstring for a full description of how this is performed.

Parameters:
  • grid – The grid of (y,x) coordinates of the image data the pixelization fits, which the KMeans algorithm adapts to.

  • adapt_data (Optional[ndarray]) – The weights defining the regions of the image the KMeans algorithm adapts to.