## 3 Methodology
### Improved Scheme Based on OTSU Dynamic Threshold Calculation: Strategy 1  
The core of the Magefreehome algorithm lies in segmenting the image by comparing the grayscale values of the pixels in the rows and columns where the image center point is located against a set threshold. This threshold directly determines segmentation accuracy. When the image background varies, the grayscale values of the pixels can differ, making a fixed threshold insufficient for precise segmentation. If the threshold is set too low, background pixels may be included, causing the segmented image to retain irrelevant parts (Figure 2b). Conversely, if the threshold is set too high, many pixels from the target area may be excluded, resulting in the foreground being mistakenly cut off and the loss of valid information (Figure 2c). This paper proposes an improved scheme based on OTSU dynamic threshold calculation. The OTSU algorithm, which operates on the principle of maximizing inter-class variance, segments the image into foreground and background according to the grayscale distribution characteristics. The objective is to minimize the global brightness difference and the squared difference between the two segments. During the algorithm's execution, the histogram of the grayscale image is analyzed to automatically calculate the inter-class variance for each potential threshold. The threshold with the maximum inter-class variance is selected as the optimal threshold, enabling the grayscale image to be segmented into foreground and background, accordingly, thereby achieving a dynamically adaptive threshold that adjusts to the image background. However, the OTSU algorithm for image segmentation is often affected by shadows [49; 50; 51]. Specifically, when the row or column containing the image center point falls within a deep shadow area (Figure 3a), the grayscale values in these regions may drop to 0 during binarization, causing these points to be ignored in the detection process. This can result in incorrect segmentation of the shadow area, leading to over-segmentation (Figure 3b). To address this issue, a shadow detection mechanism is introduced. Before segmentation, the algorithm first detects the presence of shadows in the image. If shadows are present and the row of the image center point intersects the shadow area, the grayscale values of these points will change relatively gradually, meaning they change slowly with a certain slope (Figure 4a). Conversely, if the column does not intersect the shadow area, the grayscale values of the points will change more significantly. If no shadows are present (Figure 5a), the grayscale values of the points in the row or column containing the center point will exhibit significant jumps (Figure 5b,c), making it easier to distinguish the background from the foreground. The shadow detection mechanism proposed in this paper operates as follows. Let \(G_{n}\) represent the grayscale value of the \(n\)-th predicted target segmentation point, \(G_{n-i}\) represent the grayscale value of the point located \(i\) positions before the \(n\)-th predicted target segmentation point, and \(G_{n+i}\) represent the grayscale value of the point located  
Figure 3: (**a**) The original image, (**b**) The original image after segmentation. Figure 2: (**a**) Original image, (**b**) the threshold is 40, (**c**) the threshold is 200.  
positions after the \(n\)-th predicted target segmentation point. \(G_{a}\) and \(G_{b}\) denote the average grayscale values, respectively, and are defined as follows:  
\[G_{a}=\frac{\frac{\sum\limits_{1}^{i}G_{n-i}}{i}}{i} \tag{1}\]  
\[G_{b}=\frac{\sum\limits_{1}^{i}G_{n+i}}{i} \tag{2}\]  
Here, \(dist.\) refers to the distance between the \(n\)-th predicted target segmentation point and the image boundary. To accurately determine the presence of shadows within an image, this paper proposes Algorithm 1: Shadow Detection and Segmentation.