# Quantitative Evaluation Method for the Severity of Surface Fuzz Defects in Carbon Fiber Prepreg
## 2 Materials and Methods
### Selection of Defective Pixels
Within the 1366 pixel range, the horizontal variation in the image is relatively small. Therefore, the average grayscale of \((2\times\mathrm{p}+1)\times\mathrm{n}\) pixels centered on the pixel is taken as the grayscale threshold. This is shown as follows:  
\[\mathrm{meangray1}(\mathrm{x})=\frac{1}{(2*\mathrm{p}+1)*\mathrm{n}}\sum_{ \mathrm{i=1}}^{\mathrm{n}}\int_{\mathrm{i=x-p}}^{\mathrm{x+p}}\mathrm{img}( \mathrm{x},\mathrm{y}) \tag{4}\]  
\[\mathrm{mask1}(\mathrm{x},\mathrm{y})= \begin{cases}1,\mathrm{img}_{\mathrm{ mean}}(\mathrm{x},\mathrm{y})>\mathrm{meangray1}(\mathrm{x})*1.1\\ 0,\mathrm{img}_{\mathrm{mean}}(\mathrm{x},\mathrm{y})<\mathrm{meangray1}( \mathrm{x})*1.1\end{cases}  \tag{5}\]  
In the computation of the first defect mask, the grayscale threshold is derived by incorporating both the fuzz defect regions and the background. However, since this initial threshold may be biased due to the inclusion of fuzz pixels, a second threshold step is introduced to refine the segmentation. In this step, the background is first cleaned by excluding the previously identified fuzz pixels using the first mask, and a new column-wisegrayscale threshold is computed based on the purified background. Specifically, the second column-wise average grayscale value, meangray2, is calculated as follows:  
\[\text{meangray2(y)}=\frac{1}{(2*\text{p}+1)*\text{m}}\sum_{i=1}^{\text{m}}\int_{ j=\text{y-p}}^{\text{y+p}}\text{img(x,y)}*(1-\text{mask1}) \tag{6}\]  
Here, mask1 is the binary mask obtained from the first threshold step, where a value of 1 indicates a fuzz defect pixel and 0 indicates a background pixel. Equation (6) computes the average grayscale of the background region after removing the fuzz defect areas, thereby providing a more accurate column-wise threshold for the second segmentation stage. Then, a second defect mask2 is generated by comparing the local average grayscale imgmean with the threshold defined by Equation (6):  
\[\text{mask2(x,y)}= \begin{cases}1,\text{img}_{\text{mean}}(\text{x},\text{y}) >\text{meangray2(y)}*1.1\\ 0,\text{img}_{\text{mean}}(\text{x},\text{y})<\text{meangray2(y)}*1.1\end{cases}  \tag{7}\]  
The calculation for images with a ratio of m to n greater than 3 is as follows:  
\[\text{meangray2(x)}=\frac{1}{(2*\text{p}+1)*\text{n}}\sum_{i=1}^{\text{n}}\int_ {i=\text{x-p}}^{\text{x+p}}\text{img(x,y)} \tag{8}\]  
\[\text{mask2(x,y)}= \begin{cases}1,\text{img}_{\text{mean}}(\text{x},\text{y}) >\text{meangray2(x)}*1.1\\ 0,\text{img}_{\text{mean}}(\text{x},\text{y})<\text{meangray2(x)}*1.1\end{cases}  \tag{9}\]  
To enhance the robustness of the final defect mask and minimize the risk of pixel omission due to improper threshold selection, the mask with the higher number of identified defect pixels among mask1 and mask2 is selected as the final result. This selection is formalized as follows:  
\[\text{mask}=\text{max}(\text{mask1},\text{mask2}) \tag{10}\]  
In the resulting mask, the value 1 denotes a fuzz defect pixel, while 0 indicates a background pixel. This approach ensures that the threshold process is adaptive to the spatial characteristics of the image, thereby improving the accuracy and reliability of fuzz defect detection in carbon fiber prepreg surfaces.