classifiers Package

classifiers Package

isodata Module

pyradar.classifiers.isodata.compute_avg_distance(img_flat, img_class_flat, centers, clusters_list)[source]

Computes all the average distances to the center in each cluster.

pyradar.classifiers.isodata.compute_overall_distance(img_class_flat, avg_dists_to_clusters, clusters_list)[source]

Computes the overall distance of the samples from their respective cluster centers.


Compute the pairwise distances ‘pair_dists’, between every two clusters centers and returns them sorted. Returns:

  • a list with tuples, where every tuple has in it’s first coord the distance between to clusters, and in the second coord has a tuple, with the numbers of the clusters measured. Output example:


    (d2,(cluster_3,cluster_4)), ... (dn, (cluster_n,cluster_n+1))]

pyradar.classifiers.isodata.discard_clusters(img_class_flat, centers, clusters_list)[source]

Discard clusters with fewer than THETA_M.

pyradar.classifiers.isodata.initial_clusters(img_flat, k, method='linspace')[source]

Define initial clusters centers as startup. By default, the method is “linspace”. Other method available is “random”.


Auxiliar function to set default values to all the parameters not given a value by the user.

pyradar.classifiers.isodata.isodata_classification(img, parameters=None)[source]

Classify a numpy ‘img’ using Isodata algorithm. Parameters: a dictionary with the following keys.

  • img: an input numpy array that contains the image to classify.

  • parameters: a dictionary with the initial values. If ‘parameters’ are not specified, the algorithm uses the default ones.

    • number of clusters desired. K = 15
    • max number of iterations. I = 100
    • max number of pairs of clusters which can be ,erged. P = 2
    • threshold value for min number in each cluster. THETA_M = 10
    • threshold value for standard deviation (for split). THETA_S = 0.1
    • threshold value for pairwise distances (for merge). THETA_C = 2
    • threshold change in the clusters between each iter. THETA_O = 0.01
Note: if some(or all) parameters are nos providen, default values
will be used.
  • img_class: a numpy array with the classification.
pyradar.classifiers.isodata.merge_clusters(img_class_flat, centers, clusters_list)[source]

Merge by pair of clusters in ‘below_threshold’ to form new clusters.

pyradar.classifiers.isodata.quit_low_change_in_clusters(centers, last_centers, iter)[source]

Stop algorithm by low change in the clusters values between each iteration.

Returns:True if should stop, otherwise False.
pyradar.classifiers.isodata.sort_arrays_by_first(centers, clusters_list)[source]

Sort the array ‘centers’ and the with indices of the sorted centers order the array ‘clusters_list’. Example: centers=[22, 33, 0, 11] and cluster_list=[7,6,5,4] returns (array([ 0, 11, 22, 33]), array([5, 4, 7, 6]))

pyradar.classifiers.isodata.split_clusters(img_flat, img_class_flat, centers, clusters_list)[source]

Split clusters to form new clusters.

pyradar.classifiers.isodata.update_clusters(img_flat, img_class_flat, centers, clusters_list)[source]

Update clusters.

kmeans Module

pyradar.classifiers.kmeans.converged_clusters(centers, last_centers, iter)[source]

Stop algorithm if there is no change in the clusters values between each iteration.

  • True if should stop, otherwise False.
pyradar.classifiers.kmeans.initial_clusters(img_flat, k, method='random')[source]

Define initial clusters centers as startup.

By default, the method is “linspace”. Other method available is “random”.

pyradar.classifiers.kmeans.kmeans_classification(img, k=5, iter_max=100)[source]

Classify a numpy ‘image’ according K-means algorithm.

  • img: an input numpy array that contains the image to classify.
  • k: number of classes (if not setted will use 5 as default)
  • iter_max: maximum number of iterations (if not setted will use 100 as default)
Return value:
  • img_class: an numpy array image with the classification.
pyradar.classifiers.kmeans.update_centers(img_flat, img_class, centers)[source]

Update the cluster center, computing the mean of all cluster members.

Read the Docs v: latest
On Read the Docs
Project Home

Free document hosting provided by Read the Docs.