autoarray.inversion.pixelization.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

check_adapt_background_pixels

Checks the number of mesh pixels in the background of the image-mesh and raises an InversionException if there are fewer mesh pixels in the background than the input settings.

check_mesh_pixels_per_image_pixels

Checks the number of mesh pixels in every image pixel and raises an InversionException if there are fewer mesh pixels inside a certain number of image-pixels than the input settings.

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

rtype:

bool

image_plane_mesh_grid_from(grid, adapt_data, settings=None)[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 (Grid2D) – 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.

Return type:

Grid2DIrregular