BaseDistance¶
Qualified name: CDC.color_models.BaseDistance
- class BaseDistance(*, reference_pixels, bands_to_use=None, transform=None)[source]¶
Bases:
ABC
Base class for all color distance models. Can be used to create new methods for calculating the color distance. Sub classes must implement
calculate_distance()
,calculate_statistics()
andshow_statistics()
.- Parameters:
reference_pixels (np.ndarray) – Pixels to use as a reference
bands_to_use (tuple[int, ...] | list[int] | None) – A list of indexes to choose which “colors” are used in distance calculations
transform (BaseTransform | None) – A transform to apply to the images before the distance is calculated.
Methods
Calculate the color distance for each pixel in the image to the reference.
Calculate the necessary statistics for performing the distance calculation, i.e. the covariance and average or similar.
Create a class instance from a reference image and an annotated mask.
Create a class instance from a list of pixel values before bands_to_use and transforms are applied.
Get correct bands to use from supplied alpha channel number and the number of bands in input.
Save raw, transformed and selected bands reference pixels to csv files.
Save pixel values to csv file with tab delimiter.
Print the statistics to screen.
Attributes
Reference pixel values
Raw pixel values as reference
Transformed reference pixel values
Covariance of the reference pixels.
Average of the reference pixels.
- classmethod from_image_annotation(*, reference, annotated, bands_to_use=None, alpha_channel=-1, transform=None, **kwargs)[source]¶
Create a class instance from a reference image and an annotated mask.
- Parameters:
- Return type:
- classmethod from_pixel_values(*, pixel_values, bands_to_use=None, alpha_channel=-1, transform=None, **kwargs)[source]¶
Create a class instance from a list of pixel values before bands_to_use and transforms are applied.
- Parameters:
- Return type:
- abstractmethod calculate_distance(image)[source]¶
Calculate the color distance for each pixel in the image to the reference. Subclasses must implement this and call super() as the first thing to apply band selection and transforms.
- abstractmethod calculate_statistics()[source]¶
Calculate the necessary statistics for performing the distance calculation, i.e. the covariance and average or similar. Must be implemented by subclasses.
- Return type:
None
- get_bands_to_use(alpha_channel, number_of_bands)[source]¶
Get correct bands to use from supplied alpha channel number and the number of bands in input.
- save_pixel_values(output_location, channel_names_in=None, channel_names_out=None)[source]¶
Save raw, transformed and selected bands reference pixels to csv files.
- save_pixel_values_to_file(filename, values, header=None, raw=True)[source]¶
Save pixel values to csv file with tab delimiter.