# Grayscale Iterative Star Spot Extraction Algorithm Based on Image Entropy
## 5 Inner-Outer Template Star Spot Extraction Algorithm Based on Image Entropy
### Star Spot Extraction Based on Image Entropy  
Information entropy can reflect the amount of information contained in a source and is commonly used to represent the global characteristics of information sources [35]. It is widely applied in areas such as target detection, image restoration, and matching. For images, image entropy reflects the degree of dispersion of grayscale distribution, and it is directly proportional to the uniformity of the grayscale distribution. The image entropy is the expected value of the information content contained in all states and is a global concept. Its definition is as follows [36]:  
\[H=-\sum_{i=1}^{q}P_{i}\text{log }P_{i} \tag{12}\]  
where \(H\) is the image entropy, and \(q\) is the number of grayscale levels for all pixels in the local range, and in this paper, the pixel bit depth is 8, so \(q\) is 255; \(P_{i}\) is the probability density function of grayscale level \(i\). The logarithm involved in this equation is the base-2 logarithm. Local entropy reflects the degree of grayscale confusion in a local area of the image. A more complex distribution of grayscale values in the image results in a higher entropy value, while a smoother image background leads to a lower entropy value [37]. When bright star spots appear on a smooth background, they can cause significant changes in the local grayscale distribution. Therefore, the local entropy operator can be used to reflect local grayscale variations in the image and can be used for star spot detection. In a star image, the entire image is scanned using a sliding window composed of an inner template and an outer template for star spot detection. By calculating the image entropy-related value at the current position, whether there are star spots present in the inner template at that position can be determined. In order to create a significant difference in entropy values between regions with star spots and regions without star spots, a low-threshold binary image processing can be applied to the image beforehand. The star spot extraction process based on image entropy is as follows:  
1. A star spot extraction sliding window composed of an inner template and an outer template is established to scan the entire image, with the centers of the inner and outer templates aligned, as shown in Figure 2.
2. If the mean and maximum grayscale values of the pixels in the inner template region reach the set threshold, it is considered that a star exists in that region; otherwise, the star spot extraction sliding window scans the next position. 3. If the assumed star spots are present in the scanning window, the following values are calculated separately:  
(1) The image entropy of the region \(W_{2}\) covered by the outer template: \(ImgEntropy(W_{2})=H(W_{2})\);  
(2) The region \(W_{3}\) is covered by the outer template but not by the inner template, \(W_{3}=W_{2}-W_{1}\), and the image entropy of this part is \(ImgEntropy(W_{3})=H(W_{3})\). Figure 2: Composition of the sliding window for star spot extraction. 4. The difference in image entropy between region \(W_{2}\) and region \(W_{3}\) is calculated as follows: \[H(W_{3})-H(W_{2})=ImgEntrogy(W_{3})-ImgEntrogy(W_{2})\] (13)  
If there are complete star spots in the inner template region, the difference in image entropy between region \(W_{2}\) and region \(W_{3}\) will be significant. If the difference in image entropy reaches a threshold value, it is considered that there are star spots in that region. Figure 3 shows the difference in image entropy as the star spot extraction sliding window scans different positions in the star image. From Figure 3, it can be observed that when the scanning window contains a background region, the difference in image entropy is smaller than when the scanning window is over a region with complete star spots. Therefore, the position of the star spot targets can be determined by selecting the regions where the difference in image entropy exceeds a threshold value.