MahalanobisDistance

Qualified name: CDC.color_models.MahalanobisDistance

class MahalanobisDistance(*, reference_pixels, bands_to_use=None, transform=None)[source]

Bases: BaseDistance

A multivariate normal distribution used to describe the color of a set of pixels.

Methods

calculate_distance

Calculate the color distance using mahalanobis for each pixel in the image to the reference.

calculate_statistics

Calculate covariance and average.

from_image_annotation

Create a class instance from a reference image and an annotated mask.

from_pixel_values

Create a class instance from a list of pixel values before bands_to_use and transforms are applied.

get_bands_to_use

Get correct bands to use from supplied alpha channel number and the number of bands in input.

save_pixel_values

Save raw, transformed and selected bands reference pixels to csv files.

save_pixel_values_to_file

Save pixel values to csv file with tab delimiter.

show_statistics

Print the statistics to screen.

Attributes

color_values

Reference pixel values

color_values_raw

Raw pixel values as reference

color_values_transformed

Transformed reference pixel values

covariance

Covariance of the reference pixels.

average

Average of the reference pixels.

Parameters:
classmethod from_image_annotation(*, reference, annotated, bands_to_use=None, alpha_channel=-1, transform=None, **kwargs)

Create a class instance from a reference image and an annotated mask.

Parameters:
Return type:

BaseDistance

classmethod from_pixel_values(*, pixel_values, bands_to_use=None, alpha_channel=-1, transform=None, **kwargs)

Create a class instance from a list of pixel values before bands_to_use and transforms are applied.

Parameters:
Return type:

BaseDistance

calculate_distance(image)[source]

Calculate the color distance using mahalanobis for each pixel in the image to the reference.

Parameters:

image (ndarray)

Return type:

ndarray

calculate_statistics()[source]

Calculate covariance and average.

Return type:

None

get_bands_to_use(alpha_channel, number_of_bands)

Get correct bands to use from supplied alpha channel number and the number of bands in input.

Parameters:
  • alpha_channel (int | None)

  • number_of_bands (int)

Return type:

None

save_pixel_values(output_location, channel_names_in=None, channel_names_out=None)

Save raw, transformed and selected bands reference pixels to csv files.

Parameters:
  • output_location (Path)

  • channel_names_in (str | None)

  • channel_names_out (str | None)

Return type:

None

save_pixel_values_to_file(filename, values, header=None, raw=True)

Save pixel values to csv file with tab delimiter.

Parameters:
Return type:

None

show_statistics()[source]

Print the statistics to screen.

Return type:

None

average: float | None

Average of the reference pixels.

color_values: ndarray

Reference pixel values

color_values_raw: ndarray | None

Raw pixel values as reference

color_values_transformed: ndarray | None

Transformed reference pixel values

covariance: ndarray | None

Covariance of the reference pixels.