# Rapid Detection of Key Phenotypic Parameters in Wheat Grains Using Linear Array Camera
## 2 Materials and Methods
### Research on Image Processing Methods
#### 2.3.1 Research on Preprocessing Methods  
The image preprocessing process is shown in Figure 10. The wheat images are processed using the Halcon machine vision software. First, the region of the color image is selected, and then, the color image is converted to grayscale. Subsequently, through image enhancement, feature extraction, and morphological processing, the influence of noise is reduced, and the original characteristic regions of the wheat grains are restored.  
The device employs a color linear array camera that captures images containing a substantial amount of information. However, during the image preprocessing stage, this information may become redundant. Therefore, according to the processing flow shown in the figure above, the color image is the first grayscale image to remove redundant information. Then, the image is smoothed to reduce the impact of noise on quality degradation during the image acquisition process. The image is separated into various color channels, facilitating the intuitive observation of grayscale distribution across different levels through a grayscale histogram. To enhance the visualization of channel segmentation effects, the same threshold segmentation method is applied to each of the different channels. The processing effect is shown in Figure 11. Finally, the method corresponding to the selected framed image is chosen for the preprocessing process.  
Figure 11: Comparison of image processing effects.  
Figure 10: Image preprocessing steps.  
When performing image enhancement, mean filtering, median filtering, Gaussian filtering, bilateral filtering, and guided filtering were adopted for effect comparison. When the operator parameters did not change significantly, guided filtering achieved relatively ideal noise removal. Moreover, after the image was converted into different channels, the gray histograms of each channel showed differences, as shown in Figure 11. The gray levels in the H channel were uniformly distributed, which was not conducive to feature extraction. The gray values of the background in the S channel were lower than those in other channels, making it convenient for segmenting the foreground and background. During the dynamic adjustment of the threshold segmentation values for different channels, when the low threshold was set to 23, the wheat area was well covered. Considering the integrity of the feature area and the impact of noise, the segmentation results for the S channel were superior. Consequently, this study conducted subsequent operations based on the S channel.  
After a series of image processing operations, including grayscale conversion and image enhancement in the early stage, the wheat area should be relatively completely extracted, and there will be no serious holes or protrusions that would have an impact. Only slight morphological processing of the image is required. By jointly using opening and closing operations to perform morphological processing on the wheat area, the protrusions on the edges of the wheat in the image can be removed, and the holes inside the area can be filled to show the original feature area of the wheat grains as much as possible. Simultaneously, to further eliminate noise and non-target objects, items smaller than specific preset criteria are excluded based on predefined parameters (such as area, major and minor axes, and other indicators). This process effectively screens out wheat grains that meet the established requirements.