autoarray.inversion.pixelization.image_mesh.HilbertBalanced#

class HilbertBalanced[source]#

Bases: AbstractImageMeshWeighted

Computes a balanced image-mesh by computing the Hilbert curve of the adapt data and drawing points from it.

The standard Hilbert image-mesh suffers a systematic where the vast majority of points are drawn from the high weighted reigons. This often leaves few points to reconstruct the lower weight regions, leading to discontinuities in the reconstruction.

This image-mesh addresses this by drawing half the points from the weight map and the other half from (1 - weight map). This ensures both high and low weighted regions are sampled equally, but still has sufficient flexibility to dedicate many points to the highest weighted regions.

This requires an adapt-image, which is the image that the Hilbert curve 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 Hilbert algorithm on the weight map, such that the image mesh pixels cluster around the weight map values with higher values.

Parameters:
  • pixels – The total number of pixels in the image mesh and drawn from the Hilbert curve.

  • weight_floor – The minimum weight value in the weight map, which allows more pixels to be drawn from the lower weight regions of the adapt image.

  • weight_power – The power the weight values are raised too, which allows more pixels to be drawn from the higher weight regions of the adapt image.

  • ratio – The ratio between the number of pixdels in the image mesh drawn from the weight map and (1 - weight map). For example, if there are 1000 pixels and a ratio of 0.8, 800 pixels are drawn from the weight map and therefore make up the high weighted region of the image mesh.

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 the balanced Hilbert curve 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 the balanced Hilbert curve 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 Hilbert curve adapts to.

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

Return type:

Grid2DIrregular