In modern photovoltaic power stations, the operational status of solar panels directly determines the overall power generation efficiency and long-term reliability. Among various failures, the hot spot effect is one of the most common and damaging defects. It occurs when certain cells within a solar panel operate at elevated temperatures due to mismatched current, shading, or material degradation. These hot spots not only reduce the output power but also accelerate the aging of the encapsulation materials and may even cause fire hazards. Therefore, accurate and efficient detection of hot spots in solar panels is of great practical significance. In this study, I propose an improved K-means clustering algorithm based on the HSV color space model for the automatic detection and segmentation of hot spot defects in infrared images of photovoltaic panels. The approach combines bilateral filtering, gray-level probability density estimation, and prior-knowledge-driven clustering initialization. The main contributions include a stable initial cluster center selection method derived from the grayscale distribution of the infrared image itself, which avoids the random initialization problems of the traditional K-means algorithm. Experimental results demonstrate that the proposed method achieves higher accuracy, precision, recall, and F-measure compared with conventional K-means and other typical hot spot detection methods. Moreover, the iterative process is more stable and computationally efficient, making the method suitable for large-scale aerial inspection of solar panel arrays.
Introduction
The increasing global demand for renewable energy has accelerated the deployment of photovoltaic systems. By 2022, solar power has become one of the most important clean energy sources around the world. However, solar panels operate under harsh outdoor conditions for decades, and their surfaces suffer from various defects such as cracks, snail trails, delamination, and hot spots. Among these defects, hot spots are particularly dangerous because they can cause permanent damage to the affected cells and even lead to complete module failure. Traditional detection techniques include electroluminescence imaging, laser-based scanning, and manual visual inspection. Electroluminescence imaging can reveal micro-cracks and electrical mismatches, but it requires the solar panel to be forward-biased in a dark environment, which is impractical for in-situ inspection of large photovoltaic plants. Manual visual inspection is labor-intensive, subjective, and cannot detect temperature anomalies hidden beneath the glass surface. In recent years, unmanned aerial vehicles equipped with thermal infrared cameras have become a popular platform for inspecting solar panels. The infrared camera measures the surface temperature distribution of the modules, and hot spots appear as bright regions with significantly higher gray values than the surrounding normal cells. Nevertheless, the raw infrared images often contain heavy noise, low contrast, non-uniform background, and discrete interference points, making defect extraction a challenging task.
Many image processing algorithms have been proposed for hot spot detection from infrared images. Threshold-based methods such as Otsu and improved Otsu are simple but sensitive to noise and uneven illumination. A B-spline least-squares fitting method can suppress noise to some extent, but the segmentation threshold is difficult to determine, especially when the image contains many discrete outliers. Deep learning approaches require a large number of labeled training samples, and they often only indicate whether a hot spot exists without providing a precise quantitative area. Superpixel-based saliency detection methods can achieve accurate segmentation, but several parameters must be tuned empirically, which limits their generalization capability. To address these limitations, I present a novel detection framework that leverages the inherent grayscale probability distribution of thermal infrared images. The proposed algorithm first converts the RGB image to the HSV color space and applies bilateral filtering to enhance the contrast while preserving edge details. Then, a Gaussian kernel-based non-parametric estimation is used to estimate the gray-level probability density function of the S component. The extreme points of this density function provide reliable prior knowledge for initializing the K-means clustering centers. Finally, the K-means algorithm is executed with these well-chosen initial centers, and morphological operations are applied to remove small false positives caused by non-generating components. The entire process is fully automatic and does not require a training dataset. Extensive experiments on real infrared images of solar panels show that the proposed method outperforms several existing algorithms in terms of accuracy, precision, recall, and computational stability.

The remainder of this paper is organized as follows. Section 2 describes the data acquisition system and the preprocessing steps. Section 3 details the proposed improved K-means clustering algorithm, including the estimation of gray-level probability density, the determination of the number of clusters, the initialization of cluster centers, and the clustering procedure. Section 4 presents experimental results and comparisons with other methods. Section 5 concludes the paper with a summary of findings and future research directions.
Image Acquisition and Preprocessing
Infrared Image Acquisition
I used a DJI M300 unmanned aerial vehicle equipped with a Zenmuse H20T thermal camera to capture infrared images of solar panels at a photovoltaic power station. The flight altitude was set to 30 meters to ensure that each image clearly covers a complete solar panel while maintaining sufficient spatial resolution for defect detection. The H20T camera has a resolution of 640 by 512 pixels and operates in the long-wave infrared spectrum from 8 to 14 micrometers. The measurement range extends from -40°C to 150°C, with a fixed focal length of 13.5 millimeters. Table 1 summarizes the specifications of the thermal camera.
| Resolution | Wavelength range | Measuring range | Focal length |
|---|---|---|---|
| 640 × 512 | 8 – 14 μm | −40 °C to 150 °C | 13.5 mm |
Before applying the defect detection algorithm, I carefully planned the flight path to cover the entire photovoltaic array with sufficient overlap between adjacent images. The acquired images were stored in a lossless format to preserve the temperature information. Since the drone operates in an outdoor environment, the raw images may contain sun glint, dust particles, or motion blur. Therefore, a robust preprocessing chain is essential to improve the reliability of the subsequent clustering analysis.
HSV Space Conversion
Color space conversion is a common step in image processing because different color spaces highlight different properties of an image. The RGB color space describes colors as combinations of red, green, and blue intensities, which are highly correlated and sensitive to illumination changes. In contrast, the HSV (Hue, Saturation, Value) color space separates chromatic information from brightness information, making it more intuitive and robust against varying lighting conditions. For infrared thermal images, the temperature distribution is represented by the brightness of the image, but the saturation component is particularly useful for highlighting temperature anomalies in solar panels. The conversion from RGB to HSV is defined by the following equations:
$$ H = \begin{cases} 60^\circ \times \frac{G-B}{\Delta} + 0^\circ, & \text{if } Max = R \\ 60^\circ \times \frac{B-R}{\Delta} + 120^\circ, & \text{if } Max = G \\ 60^\circ \times \frac{R-G}{\Delta} + 240^\circ, & \text{if } Max = B \\ 0^\circ, & \text{if } \Delta = 0 \end{cases} $$
$$ S = \begin{cases} 0, & \text{if } Max = 0 \\ \frac{\Delta}{Max}, & \text{otherwise} \end{cases} $$
$$ V = \max(R, G, B) $$
where \(Max\) is the maximum component among R, G, B, and \(\Delta\) is the difference between the maximum and minimum components. After the conversion, I extract the S component (saturation) as the input for further processing. The S component is less affected by global brightness changes and can effectively represent the temperature contrast between normal cells and hot spot regions.
Bilateral Filtering
Infrared images are inherently noisy, with a low signal-to-noise ratio and reduced contrast. Directly applying a clustering algorithm to the raw S component may produce many false detections due to noise. I therefore apply a bilateral filter to the S component before the clustering stage. Bilateral filtering is a nonlinear, edge-preserving denoising technique that combines domain filtering with range filtering. The output pixel value is computed as a weighted average of neighboring pixels, where the weights depend both on the spatial distance and on the intensity difference. This dual weighting allows the filter to remove noise while preserving sharp edges, which is crucial for accurately retaining the boundaries of hot spots. The bilateral filter is defined by:
$$ I_{out}(\mathbf{p}) = \frac{1}{W_{\mathbf{p}}} \sum_{\mathbf{q} \in \Omega} I(\mathbf{q}) \cdot G_s(\|\mathbf{p}-\mathbf{q}\|) \cdot G_r(\|I(\mathbf{p})-I(\mathbf{q})\|) $$
where \(\mathbf{p}\) is the center pixel, \(\mathbf{q}\) is a neighboring pixel in the window \(\Omega\), \(G_s\) is the spatial Gaussian kernel with standard deviation \(\sigma_s\), \(G_r\) is the range Gaussian kernel with standard deviation \(\sigma_r\), and \(W_{\mathbf{p}}\) is the normalization factor:
$$ W_{\mathbf{p}} = \sum_{\mathbf{q} \in \Omega} G_s(\|\mathbf{p}-\mathbf{q}\|) \cdot G_r(\|I(\mathbf{p})-I(\mathbf{q})\|) $$
In my implementation, I used a filter window of 5 by 5 pixels with \(\sigma_s = 3\) and \(\sigma_r = 0.1\). The filtered S component exhibits a smoother background and a more distinct hot spot region, which facilitates the subsequent probability density estimation and clustering.
The effect of preprocessing can be observed by comparing the gray-level histogram before and after the bilateral filter. The original infrared image has a noisy histogram with many local fluctuations, while the processed image shows a smoother and more distinguishable distribution. This preprocessing step ensures that the grayscale probability density estimated later is stable and representative of the actual thermal distribution.
Proposed Improved K-Means Clustering Algorithm
Gray-Level Probability Density Extraction
In a thermal infrared image, each pixel value corresponds to a temperature level. Different materials on a solar panel surface have different thermal conductivities, leading to different gray-level ranges for the background, the normal cells, the metal frames, and the hot spot areas. The gray-level probability density function describes how these gray values are distributed over the entire image. If I can accurately estimate this distribution, I can identify the characteristic gray values that correspond to different components. Because the raw discrete histogram is not directly usable for analytical purposes, I apply a non-parametric Parzen window estimation using a Gaussian kernel to obtain a smooth probability density function.
Let the entire image contain \(N\) pixels with gray values \(\theta_1, \theta_2, \ldots, \theta_N\), each lying in the range [0, 255]. The probability that a randomly selected pixel has a gray value within a small region \(D\) of width \(h\) can be expressed as:
$$ P = \int_D f(x) dx \approx f(x) \cdot h $$
For the \(N\) available samples, if \(k\) samples fall into region \(D\), the probability can also be estimated as:
$$ P = \frac{k}{N} $$
The Gaussian kernel function is chosen to estimate the contribution of each sample to the density at a given gray value. The kernel is defined as:
$$ K\left(\frac{x – x_i}{h}\right) = \frac{1}{\sqrt{2\pi}} \exp\left(-\frac{(x – x_i)^2}{2h^2}\right) $$
By summing the contributions of all \(N\) samples, the estimated gray-level probability density function \(F(x)\) is:
$$ F(x) = \frac{1}{N h} \sum_{i=1}^{N} K\left(\frac{x – \theta_i}{h}\right) $$
where \(h\) is the bandwidth, which controls the smoothness of the estimated density. In my experiments, I set \(h = 2\). The resulting density curve is much smoother than the raw histogram and preserves the main peaks and valleys, which correspond to the prominent gray-level clusters in the image. The estimated density function is then used to derive prior knowledge for the clustering algorithm.
Determination of the Number of Clusters
The number of clusters \(K\) is a critical parameter in the K-means algorithm. If \(K\) is too small, different components may be merged; if \(K\) is too large, a single component may be split into multiple segments. I use the elbow method based on the sum of squared errors (SSE) to determine the optimal \(K\). The SSE is defined as:
$$ SSE = \sum_{i=1}^{K} \sum_{q \in C_i} \|q – m_i\|^2 $$
where \(C_i\) is the \(i\)-th cluster and \(m_i\) is its centroid. As \(K\) increases, the SSE generally decreases because the data points become closer to their cluster centers. However, after a certain point, the improvement becomes marginal, and the SSE curve forms an elbow. The \(K\) value at the elbow point is selected as the optimal number of clusters. In the case of photovoltaic panel infrared images, I typically obtain \(K = 3\) or \(K = 4\), depending on the complexity of the image. A typical scenario includes three main clusters: the dark background, the normal solar panel area, and the hot spot region. Occasionally, a fourth cluster may represent the metal frame or other bright structures.
Initial Cluster Center Selection Based on Prior Probability Density
One of the major drawbacks of the traditional K-means algorithm is the random selection of initial cluster centers. Different random initializations often lead to different clustering results, and the iterative process may converge to a local optimum rather than the global optimum. To solve this problem, I propose a deterministic initialization strategy based on the gray-level probability density function. The underlying assumption is that pixels belonging to the same physical component of the solar panel are distributed around one or more characteristic gray values, and the probability density function exhibits peaks at these characteristic values. Therefore, the extreme points (local maxima and minima) of the density function can provide meaningful initial centers.
Let \(\theta_{\min}\) and \(\theta_{\max}\) denote the minimum and maximum gray values corresponding to the peaks of the density curve. I divide the interval \([\theta_{\min}, \theta_{\max}]\) into \(K\) equal sub-intervals, each with width \(t\):
$$ t = \frac{\theta_{\max} – \theta_{\min}}{K} $$
For every pair of characteristic gray values \(\theta_i\) and \(\theta_j\), I check whether their difference is smaller than the threshold \(t\). If so, they are considered to belong to the same class:
$$ |\theta_i – \theta_j| < t, \quad \theta_i, \theta_j \in [\theta_{\min}, \theta_{\max}] $$
This grouping process produces \(K\) sets of feature points \(V_1, V_2, \ldots, V_K\). For each set, I select the gray value with the maximum probability density as the initial cluster center:
$$ \theta_{C_i} = \arg\max_{x \in V_i} F(x), \quad i = 1, 2, \ldots, K $$
This approach ensures that the initial cluster centers are located in the most densely populated areas of the gray-level distribution, which are the natural centroids of the underlying physical components. Because the selection is based on the image content rather than random numbers, the clustering result becomes reproducible and stable.
K-Means Clustering with Prior Knowledge
The traditional K-means algorithm iteratively assigns each pixel to the nearest cluster center based on the Euclidean distance, then recomputes the cluster centers as the mean of all pixels assigned to the respective cluster. The iteration continues until the cluster centers no longer change. The assignment step uses the minimum Euclidean distance criterion:
$$ C_i = \arg\min_{i \in \{1,\ldots,K\}} \| \theta – \theta_{C_i} \|^2 $$
After all pixels have been assigned to one of the \(K\) clusters, the new cluster centers are computed as the average of the pixels within each cluster:
$$ \theta’_{C_i} = \frac{1}{N_i} \sum_{x \in C_i} x $$
where \(N_i\) is the number of pixels in cluster \(C_i\). If the updated centers differ from the previous centers, the algorithm repeats the assignment and update steps. The process terminates when the centers remain unchanged, which is equivalent to minimizing the SSE within each cluster. The algorithmic steps of my improved K-means clustering method are outlined as follows:
1. Convert the original infrared image to the HSV space and extract the S component.
2. Apply bilateral filtering to the S component to remove noise while preserving edges.
3. Compute the gray-level histogram and estimate the smooth probability density function \(F(x)\) using Gaussian kernel density estimation.
4. Use the elbow method to determine the optimal number of clusters \(K\).
5. Extract the extreme points of \(F(x)\) to obtain the characteristic gray values, then group them based on the threshold \(t\) to form \(K\) feature point sets.
6. Select the gray value with maximal probability density within each feature point set as the initial cluster center \(\theta_{C_i}\).
7. Perform iterative K-means clustering: assign every pixel to the closest center using the Euclidean distance, update the centers, and repeat until convergence.
8. Apply morphological processing to remove small false-positive regions and obtain the final hot spot defect mask.
The convergence behavior of the improved algorithm is more predictable than that of the traditional algorithm. Since the initial centers are already close to the true centers, the number of iterations is significantly reduced. In my experiments, the improved algorithm always converges within a fixed number of iterations, whereas the traditional K-means may require a variable and sometimes much larger number of iterations due to random initialization.
Morphological Post-Processing
The infrared image of a solar panel contains not only the photovoltaic cells but also metallic frames, busbars, and other structural components. These non-generating parts typically have different thermal conductivities and may appear as bright or dark regions in the infrared image. To avoid false detections caused by these components, I apply morphological operations to the binary clustering result. First, I compute the connected components in the segmented image and obtain their areas. Then, I determine a threshold \(T\) based on the area of the non-generating regions of the known solar panel layout. Any region whose area is smaller than \(T\) is considered noise or a non-generating component and is removed from the defect mask. This step dramatically improves the precision of hot spot detection. Morphological opening and closing operations are also used to smooth the boundaries of the detected hot spots and to fill small holes. The final output is a binary image where the white regions indicate the hot spot defects.
Experimental Results and Analysis
Clustering Performance Evaluation
I evaluated the proposed improved K-means algorithm on a set of infrared images of solar panels captured at a photovoltaic power station. The images contain varying levels of noise and contrast. One representative sample was selected to visually compare the clustering results of the traditional K-means algorithm and the proposed improved algorithm. The clustering results are shown in Figure 1, where the original image contains a clear hot spot in the center of the panel. The traditional K-means algorithm, with random initialization, often fails to separate the hot spot from the normal cells due to interference from noise and outliers. The improved algorithm, by contrast, accurately segments the hot spot region while maintaining the correct boundaries. The quantitative comparison of the clustering performance is based on three common internal metrics: information entropy (IE), Davies-Bouldin index (DBI), and silhouette coefficient (SC). A lower IE indicates a more concentrated gray-level distribution, a lower DBI indicates better separation between clusters, and a higher SC indicates more compact and well-separated clusters. Table 2 reports the average values of these metrics for both algorithms.
| Algorithm | Information Entropy (IE) | Davies-Bouldin Index (DBI) | Silhouette Coefficient (SC) |
|---|---|---|---|
| Improved K-means | 3.4843 | 0.4709 | 0.8274 |
| Traditional K-means | 3.5804 | 0.4719 | 0.8248 |
The improved K-means algorithm achieves lower IE and DBI values, as well as a higher SC value, which indicates that the clusters obtained with the proposed method are more compact, more separated, and more concentrated around the true gray-level centers. This improvement is directly attributable to the deterministic initialization based on the gray-level probability density function.
Iteration Speed and Stability
Computational efficiency is an important factor for real-time inspection applications. I compared the convergence speed of the traditional and improved K-means algorithms by running each algorithm 100 times on the same preprocessed image. The number of iterations required for convergence was recorded for each run. The traditional K-means algorithm, due to random initialization, exhibits highly variable iteration counts, ranging from a minimum to a maximum with a difference of 26 iterations. In contrast, the improved algorithm always converges in exactly 18 iterations, because the initial centers are consistently selected near the final centers. This deterministic behavior greatly enhances the stability of the detection pipeline. Table 3 summarizes the iteration statistics for both algorithms.
| Algorithm | Minimum iterations | Maximum iterations | Mean iterations | Standard deviation |
|---|---|---|---|---|
| Improved K-means | 18 | 18 | 18.0 | 0.0 |
| Traditional K-means | 14 | 40 | 27.3 | 5.8 |
The improved algorithm not only reduces the average number of iterations but also eliminates the randomness in convergence speed. This makes the method more predictable and suitable for embedded or online inspection systems.
Defect Detection Accuracy Comparison
To further validate the effectiveness of the proposed defect detection method, I compared it against three other algorithms: the traditional K-means algorithm, an improved Otsu method based on top-hat transformation and contrast stretching, and a B-spline least-squares fitting method. The visual comparison on a representative infrared image is described as follows. The improved Otsu method is sensitive to noise and often misclassifies the module interconnect ribbons as hot spots because these regions have higher temperatures than the surrounding cells. The B-spline least-squares fitting method can suppress some noise and locate the hot spot more accurately, but the segmentation result is still influenced by discrete points, which introduces errors in the area statistics. The traditional K-means algorithm suffers from local optima, so the hot spot region is not consistently identified. The proposed improved K-means algorithm accurately isolates the hot spot from the background and normal cells, with smooth boundaries and no obvious false positives.
I also performed a quantitative evaluation on a larger test set consisting of 84 infrared images, each containing at least one real hot spot. The evaluation metrics are the accuracy \(A\), precision \(P\), recall \(R\), and F-measure \(F\), defined as:
$$ A = \frac{T_P + T_N}{T_P + T_N + F_P + F_N} $$
$$ P = \frac{T_P}{T_P + F_P} $$
$$ R = \frac{T_P}{T_P + F_N} $$
$$ F = \frac{2 P R}{P + R} $$
where \(T_P\) denotes the number of pixels correctly classified as hot spots, \(T_N\) denotes the number of pixels correctly classified as non-hot-spot areas, \(F_P\) denotes the number of non-hot-spot pixels incorrectly classified as hot spots, and \(F_N\) denotes the number of hot-spot pixels incorrectly classified as non-hot-spot. Table 4 presents the average metric values for the compared methods.
| Algorithm | Accuracy (%) | Precision (%) | Recall (%) | F-measure (%) |
|---|---|---|---|---|
| Improved K-means | 90.86 | 95.95 | 85.54 | 90.45 |
| Traditional K-means | 84.92 | 82.67 | 81.58 | 82.12 |
| B-spline fitting | 85.79 | 88.41 | 78.21 | 82.99 |
As shown in Table 4, the proposed improved K-means method achieves the highest accuracy, precision, and F-measure among all tested algorithms. The accuracy reaches 90.86% and the precision reaches 95.95%, indicating that almost all detected defects are true hot spots. The recall is 85.54%, which is also the highest among the comparison methods, demonstrating that the algorithm is capable of detecting most of the actual hot spot areas. The F-measure of 90.45% confirms the overall balance between precision and recall.
Discussion
The success of the proposed method stems from the combination of several key ideas. First, the HSV space conversion separates the saturation component, which effectively enhances the thermal contrast of solar panels. Second, bilateral filtering suppresses noise without blurring the thermal edges, which is crucial for preserving the exact shape of hot spots. Third, the Gaussian kernel density estimation provides a smooth probability density function from which the initial cluster centers can be derived in a deterministic manner. This prior knowledge not only speeds up the convergence of K-means but also prevents the algorithm from falling into local optima. Finally, morphological post-processing eliminates small false positives caused by solar panel frames and other metallic parts, improving the precision of the final defect mask.
One of the notable advantages of the improved algorithm is its robustness against different types of noise and image quality. The gray-level probability density function reflects the actual content of the image, so the initial cluster centers adapt to the specific brightness and contrast conditions of each image. This adaptive behavior makes the algorithm applicable to various photovoltaic installations without re-tuning the parameters. In contrast, methods that rely on fixed thresholds or pre-trained networks may fail when the image characteristics change due to different ambient temperatures, sun angles, or camera settings.
I also observed that the number of clusters K may occasionally need to be adjusted for images where the solar panel contains more complex structures, such as bypass diodes or multiple hot spots at different temperatures. In those cases, the elbow method still provides a reliable starting point, and the K value can be increased by one if the hot spot region appears to be split into multiple clusters. Overall, the algorithm has demonstrated a high degree of flexibility and stability in real-world tests.
Conclusion
In this paper, I have presented an improved K-means clustering method for the detection and quantification of hot spot defects in solar panels using infrared images. The proposed framework first converts the input image to the HSV color space and applies bilateral filtering to enhance the image contrast while suppressing noise. A Gaussian kernel density estimator is then used to obtain a smooth gray-level probability density function, from which the initial cluster centers are selected. This deterministic initialization strategy effectively eliminates the randomness of the traditional K-means algorithm and ensures reproducible segmentation results. The optimal number of clusters is determined by the elbow method, and the clustering iterations are carried out with the prior-knowledge-based centers. Finally, morphological operations remove small false-positive areas caused by non-generating components of the solar panel.
Experimental results on real infrared images demonstrate that the proposed method significantly outperforms the traditional K-means algorithm and other representative defect detection methods. The accuracy, precision, and F-measure all exceed 90%, and the recall reaches 85.54%, indicating a good trade-off between completeness and correctness. In addition, the improved initialization reduces the number of iterations to a fixed value of 18, whereas the traditional algorithm may require anywhere from 14 to 40 iterations. This deterministic convergence behavior makes the method highly suitable for large-scale solar panel inspection tasks that require both reliability and computational efficiency.
Future work will focus on extending the proposed method to the detection of other types of solar panel defects, such as cracks and delamination, using multi-modal imaging techniques. I also plan to investigate the integration of the clustering algorithm into a real-time drone-based inspection system, where the thermal images are processed immediately to provide immediate feedback to the ground station. Furthermore, the sensitivity of the bandwidth parameter \(h\) in the kernel density estimation will be studied in detail to make the algorithm even more robust under diverse environmental conditions.
