region_grow.classifiers module

Classes with the definition of the different classifiers for build the connected components for the Region Grow algorithm

class region_grow.classifiers.BandThreshold(pixels_df, band_threshold=0.1)

Bases: region_grow.classifiers.Classifier

Allows to classify all pixels similar to a given one The threshold of the bands will be +- a percentage defined by the user The pixel will be classified if and only if its reflectance for each spectral band is in the margin calculated from the threshold.

WARNING: This classification method is designed to perform the process of Region Grow with only one pixel, in case more than one pixel is provided The user will be notified that the process will only use the first one found.

Parameters
  • pixels_df (pandas.DataFrame) – Dataframe with each of the spectral reflectances or indexes to be used for the pixels associated with the points of entry

  • band_threshold (float) – Similarity threshold to be calculated for each band band_threshold in [0, 1)

fit()

Allows training in the method of classification and calculation the acceptance threshold for each of the bands

predict(pixel)

Determines if the pixel should be added to the polygon making the prediction according to the threshold values for each of the bands

Parameters

pixel (numpy.ndarray) – Spectral reflectance of the pixel to be analyzed

Returns

True/False – If the pixel meets the conditions proposals to add it or not to the component connected.

Return type

bool

class region_grow.classifiers.Classifier(pixels_df: pandas.core.frame.DataFrame)

Bases: abc.ABC

Define the class that will provide the method of classification for the new pixels given the seed

Parameters

pixels_df (pandas.DataFrame) – Dataframe with each of the spectral reflectances to be used for the pixels associated with the input points

abstract fit()

It defines the way in which the classification model will be trained.

abstract predict(pixel: numpy.ndarray)

Predicts whether a given pixel can be added or not to the connected component under construction

Parameters

pixel (numpy.ndarray) – Vector with each of the reflectance values spectral or indexes that make up the pixel

Returns

True/False – If the pixel meets the conditions proposals to add it or not to the component connected.

Return type

bool

class region_grow.classifiers.ConfidenceInterval(pixels_df, confidence_lvl=0.99)

Bases: region_grow.classifiers.Classifier

Allows to make a classification of the pixels by using a confidence interval for each of the spectral bands or indices

Parameters
  • pixels_df (pandas.DataFrame) – Dataframe with each of the spectral reflectances or indexes to be used for the pixels associated with the seed points

  • confidence_lvl (float) – Confidence level at which the interval is built confidence_lvl in [0, 1)

fit()

Build a confidence interval for each of the bands or indexes to use them as a classification threshold

predict(pixel)

It makes the prediction according to the values of confidence interval

Parameters

pixel (numpy.ndarray) – Vector with each of the reflectance values spectral or indexes that make up the pixel

Returns

True/False – If the pixel meets the conditions proposals to add it or not to the component connected.

Return type

bool

class region_grow.classifiers.EuclideanDistance(pixels_df)

Bases: region_grow.classifiers.Classifier

Allows to make a classification of the pixels calculating the sum of the euclidean distance differences between the i-band of the pixel against the the i-band of seed pixels

Parameters

pixels_df (pandas.DataFrame) – Dataframe with each of the spectral reflectances or indexes to be used for the pixels associated with the points of entry

fit()

Calculate the average of each of the bands present in the seed pixel array (DataFrame)

Returns

bands_mean – Average of each of the bands of the dataframe being the first position the average of band 1

Return type

numpy.ndarray

predict(pixel)

Predicts whether a given pixel can be added or not to the connected component under construction

Parameters

pixel (numpy.ndarray) – Vector with each of the reflectance values spectral or indexes that make up the pixel

Returns

True/False – If the pixel meets the conditions proposals to add it or not to the component connected.

Return type

bool

threshold()

Calculate the average of each of the bands present in the seed pixel array (DataFrame)

Returns

threshold – Acceptable difference threshold to consider a pixel as member of the connected component. It is calculated from the seed points.

Return type

float

class region_grow.classifiers.EuclideanDistanceReFit(pixels_df: pandas.core.frame.DataFrame, refit_threshold: int = 3)

Bases: region_grow.classifiers.Classifier

Allows to make a classification of the pixels calculating the sum of the distance differences euclidean between the i-band of the pixel against the the i-band of the seed pixels

The difference with the standard implementation is that, as that finds new pixels, retrains and adjusts the content of the bands with the values of these new pixels

Parameters
  • pixels_df (pandas.DataFrame) – Dataframe with each of the spectral reflectances or indexes to be used for the pixels associated with the points of entry

  • refit_threshold (int) – Number of extra pixels to be added before retraining the classifier

compute_threshold()

Calculates the threshold to determine if a pixel should be grouped or not within the polygon to be generated

Returns

threshold – Acceptable difference threshold to consider a pixel as member of the connected component. It is calculated from the seed points.

Return type

float

fit()

Calculate the average of each of the bands present in the seed pixel array (DataFrame)

Returns

bands_mean – Average of each of the bands of the dataframe being the first position the average of band 1

Return type

numpy.ndarray

predict(pixel)

Determines if the pixel should be added to the polygon making the prediction according to the difference of the band with the average of the seed pixels for that band.

Parameters

pixel (numpy.ndarray) – Spectral reflectance of the pixel to be analyzed

Returns

True/False – If the pixel meets the conditions proposals to add it or not to the component connected.

Return type

bool

refit(pixel)

Allows to retrain the algorithm with the classified points in order to improve accuracy in finding similar pixels and bias it to achieve this goal

pixel: numpy.ndarray

Vector with each of the reflectance values spectra or indexes that make up the new pixel to be added to the connected.

region_grow.classifiers.select_balanced_classifier(classifier_tag: str)region_grow.classifiers.Classifier

Allows you to select a given sorter its abbreviation, to create the connected component

Parameters

classifier_tag (str) –

Tag that defines each of the registered classifiers

EDR: Euclidean distance that recomputes the average of the bands

after X-pixels new added to the connected component EuclideanDistanceReFit.

BD: Threshold for a single seed pixel band - BandThreshold

A +- threshold is defined to define the accepted range per band

Returns

rg_classifier – Reference to the class of the sorter to be instantiated

Return type

Classifier

region_grow.classifiers.select_classifier(classifier_tag: str)region_grow.classifiers.Classifier

Allows you to select a given sorter its abbreviation, to create the connected component

Parameters

classifier_tag (str) –

Tag that defines each of the registered classifiers

ED: Euclidean Distance - EuclideanDistance

Calculates the euclidean distance between the band of the pixel to be analyzed and the average of the accepted threshold

CI: Confidence Interval over the average - ConfidenceInterval

It performs a confidence interval as a way to determine the acceptance threshold

EDR: Euclidean distance that recomputes the average of the bands

after X-pixels new added to the connected component EuclideanDistanceReFit.

BD: Threshold for a single seed pixel band - BandThreshold

A +- threshold is defined to define the accepted range per band

Returns

rg_classifier – Reference to the class of the sorter to be instantiated

Return type

Classifier