Aircraft Detection 1.0
Loading...
Searching...
No Matches
kmeans.h File Reference
#include <filesystem>
#include <opencv2/core/mat.hpp>

Go to the source code of this file.

Functions

cv::Mat kmeansBySize (const std::vector< cv::Mat > &extracted_templates, int K)
 Performs K-Means clustering on a set of templates based on their dimensions.
 
cv::Mat kmeansByIntensity (const std::vector< cv::Mat > &extracted_templates, int K_clusters)
 Performs K-Means clustering on a set of templates based on their mean intensity.
 
void saveClusteredImages (const std::vector< cv::Mat > &images, const std::vector< std::string > &image_paths, const cv::Mat &labels, const std::vector< std::filesystem::path > &cluster_paths)
 Saves images into directories based on their cluster labels.
 

Function Documentation

◆ kmeansByIntensity()

cv::Mat kmeansByIntensity ( const std::vector< cv::Mat > & clustered_templates_by_size,
int K_clusters )

Performs K-Means clustering on a set of templates based on their mean intensity.

This function takes a vector of templates that have been clustered by size and performs K-Means clustering based on their mean intensity. The result is a matrix of labels indicating the cluster assignment for each template.

Parameters
[in]clustered_templates_by_sizeA vector of cv::Mat objects representing the templates that have been previously clustered by size.
[in]K_clustersThe number of intensity-based clusters to form.
Returns
A cv::Mat containing the cluster labels for each template based on intensity.
Note
The function calculates the mean intensity of each template and uses this information as input for the K-Means clustering algorithm.
See also
cv::mean
cv::kmeans

◆ kmeansBySize()

cv::Mat kmeansBySize ( const std::vector< cv::Mat > & extracted_templates,
int K )

Performs K-Means clustering on a set of templates based on their dimensions.

This function takes a vector of extracted templates and performs K-Means clustering based on their width and height. The result is a matrix of labels indicating the cluster assignment for each template.

Parameters
[in]extracted_templatesA vector of cv::Mat objects representing the extracted templates.
[in]KThe number of clusters to form.
Returns
A cv::Mat containing the cluster labels for each template.
Note
The function creates a matrix with the dimensions of each template and uses this matrix as input for the K-Means clustering algorithm.
See also
cv::kmeans

◆ saveClusteredImages()

void saveClusteredImages ( const std::vector< cv::Mat > & images,
const std::vector< std::string > & image_paths,
const cv::Mat & labels,
const std::vector< std::filesystem::path > & cluster_paths )

Saves images into directories based on their cluster labels.

This function takes a vector of images, their corresponding file paths, cluster labels, and destination directories for each cluster. It saves each image into the appropriate directory based on its cluster label.

Parameters
[in]imagesA vector of cv::Mat objects representing the images to be saved.
[in]image_pathsA vector of strings containing the original file paths of the images.
[in]labelsA cv::Mat containing the cluster labels for each image.
[in]cluster_pathsA vector of std::filesystem::path objects representing the destination directories for each cluster.
Note
The function assumes that the number of images, file paths, and labels are the same. Each image is saved with its original filename into the directory corresponding to its cluster label.
See also
cv::imwrite
std::filesystem::path