A mushroom maturity discrimination and prediction method based on image recognition
Patent Information
- Application Number
- CN202611484535.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-22
- Publication Date
- 2026-10-27
AI Technical Summary
[0004]本发明解决的技术问题是:现有技术难以在光照波动、表面湿润反光、姿态遮挡和伞缘褶皱细节变化等复杂成像条件下稳定提取能够表征蘑菇成熟度差异的有效特征并实现可靠分级,难以在目标区域定位与截取不稳定时保持成熟度判别的准确性,且难以同时利用空域特征与频域瞬时相位、瞬时频率信息进行联合建模以提升对成熟度细微差异的区分能力,并对低置信样本给出可控的待复检输出
[0015]本发明的有益效果:本发明通过骨干特征提取网络对蘑菇原始图像进行空域特征提取并结合边界框回归确定图像感兴趣区域,从而在背景干扰和姿态变化情况下稳定获得目标空域高阶特征矩阵;进一步对目标空域高阶特征矩阵进行快速傅里叶变换得到复数域特征矩阵,并通过希尔伯特变换构造解析信号特征矩阵以提取各频率位置的瞬时相位与瞬时频率,使蘑菇成熟度变化引起的纹理细节与结构变化能够在频率域被更敏感地表征;再对瞬时相位与瞬时频率进行交叉映射得到各个频率通道的复数权重系数,并对复数域特征矩阵进行矩阵相乘与逆快速傅里叶变换得到目标频域重构特征矩阵,使频率分量实现自适应重标定并增强与成熟度判别相关的频率响应;最后将目标空域高阶特征矩阵与目标频域重构特征矩阵展平后首尾串联拼接得到空频融合特征向量并进行决策分级映射计算,输出未成熟、成熟、过熟和待复检的蘑菇成熟度分级结果,从而相对于仅基于空域特征或简单阈值规则的方法提高成熟度判别的准确性与鲁棒性,并通过待复检机制降低边界样本误分级风险,提升实际分拣应用的可靠性与可控性。
Smart Images

Figure CN122990236A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image recognition technology, and in particular to a method for predicting and determining the maturity of mushrooms based on image recognition. Background Technology
[0002] In recent years, the demand for large-scale cultivation and automated sorting of edible fungi has been continuously increasing. The maturity of mushrooms directly affects the harvesting time, commercial grade, and storage and transportation quality. Therefore, it is necessary to quickly and stably determine and predict the maturity of the collected raw mushroom images. Existing methods mostly use threshold rules based on color and morphology or classification models based solely on spatial convolution features for discrimination. Under conditions such as light fluctuations, surface moisture reflection, changes in details of cap edge wrinkles, and pose occlusion, feature instability can easily lead to misjudgments and insufficient confidence, making it difficult to meet the stability and controllability requirements of sorting production lines.
[0003] Currently, Chinese invention patent application CN122156965A discloses a remote sensing identification method for grassland mushroom rings based on multispectral threshold screening and geometric constraints. This method includes multispectral remote sensing image acquisition and preprocessing, vegetation index construction and ring feature enhancement, adaptive threshold screening to generate candidate binary maps, morphological arc repair and connected component candidate region extraction, geometric constraint fitting and parameter extraction, false target suppression and consistency verification, and identification result output. This method can automatically identify mushroom ring targets in remote sensing images and extract structured parameters composed of center coordinates, radius, and ring width. It effectively enhances the ring features of mushroom rings and suppresses false detections caused by complex background interference, improving identification accuracy and reliability. The results can be used for fungal resource surveys and grassland ecological monitoring. However, the related technologies do not address the spatial feature extraction and target region interception process for judging the maturity of mushrooms at close range. They do not provide a processing mechanism for extracting instantaneous frequency and instantaneous phase by performing fast Fourier transform on the high-order feature matrix of the target spatial domain and combining it with Hilbert transform. They do not provide a processing mechanism for cross-mapping instantaneous phase and instantaneous frequency to generate complex weight coefficients and for adaptive recalibrating and reconstructing the complex domain feature matrix by inverse fast Fourier transform. They also do not provide an implementation method for calculating the decision-level mapping based on spatial-frequency fusion feature vectors and outputting maturity level results of immature, mature, overripe, and pending re-examination. Summary of the Invention
[0004] The technical problem solved by this invention is that existing technologies are difficult to reliably extract effective features that characterize the differences in mushroom maturity under complex imaging conditions such as light fluctuations, surface wet reflection, posture occlusion, and changes in the details of umbrella edge wrinkles. They are also difficult to maintain the accuracy of maturity discrimination when the target area is unstable in terms of localization and interception. Furthermore, they are difficult to simultaneously utilize spatial features and instantaneous phase and frequency information in the frequency domain for joint modeling to improve the ability to distinguish subtle differences in maturity and to provide controllable output for re-examination of low-confidence samples.
[0005] To solve the above-mentioned technical problems, the present invention provides the following technical solution: a mushroom maturity discrimination and prediction method based on image recognition, comprising the following steps: Step S1: Acquire the original image of the mushroom and input the original image of the mushroom into the backbone feature extraction network for spatial feature extraction and target region cropping to obtain the target spatial high-order feature matrix; Step S2: Perform a fast Fourier transform on the high-order feature matrix of the target spatial domain to obtain the feature matrix of the complex domain, and then perform a Hilbert transform to extract the instantaneous frequency and instantaneous phase at each frequency position. Step S3: Cross-mapping is performed on the instantaneous phase and instantaneous frequency to obtain the complex weight coefficients of each frequency channel, and matrix multiplication and inverse fast Fourier transform are performed on the complex domain feature matrix to obtain the target frequency domain reconstructed feature matrix. Step S4: Flatten the target spatial domain high-order feature matrix and the target frequency domain reconstructed feature matrix respectively and concatenate them end to end to obtain the spatial-frequency fusion feature vector, and perform decision-level mapping calculation to obtain the corresponding mushroom maturity level result.
[0006] Preferably, step S1 specifically includes: Step S11: Acquire the original image of the mushroom and input the original image of the mushroom into the backbone feature extraction network to extract the basic spatial feature matrix; The backbone feature extraction network includes an initial convolutional layer, a hybrid attention layer, and a deformable convolutional layer; Step S12 involves performing position prediction and feature extraction processing on the basic spatial feature matrix to obtain the target spatial high-order feature matrix. The processing logic is as follows: Boundary box regression is performed on the basic spatial feature matrix to obtain the target bounding box, and the region of interest in the image is determined based on the mapping correspondence between the target bounding box and the original mushroom image. Based on the spatial coordinates of the region of interest in the image, the corresponding region is extracted from the basic spatial feature matrix to obtain the target spatial high-order feature matrix.
[0007] Preferably, the processing logic for extracting the basic spatial feature matrix is as follows: In the initial convolutional layer, the original mushroom image is subjected to initial convolutional mapping operation to obtain a high-dimensional spatial mapping matrix; In the hybrid attention layer, the high-dimensional spatial mapping matrix is processed by global average pooling and linear mapping matrix multiplication through a hybrid spatial channel attention mechanism to obtain channel attention weights. At the same time, max pooling and average pooling are concatenated along the spatial dimension corresponding to the high-dimensional spatial mapping matrix to obtain spatial attention weights. The channel attention weights and spatial attention weights are calibrated by multiplying element-wise with the corresponding spatial dimension high-dimensional spatial mapping matrix to obtain the weighted calibrated high-dimensional spatial mapping matrix. In the deformable convolutional layer, a preset sampling convolutional kernel is introduced. The weighted and calibrated high-dimensional spatial mapping matrix is subjected to deformable convolutional sampling operation. The two-dimensional spatial offset of the preset sampling convolutional kernel in the horizontal and vertical directions is calculated based on the spatial position corresponding to the weighted and calibrated high-dimensional spatial mapping matrix. Based on the two-dimensional spatial offset, bilinear interpolation sampling is performed on the irregular grid sampling points to obtain the basic spatial feature matrix.
[0008] Preferably, the processing logic for the target bounding box is as follows: The initial prediction box is obtained by mapping the basic spatial feature matrix using preset regression parameters; The spatial intersection-union ratio error between the initial predicted bounding box and the ground truth bounding box is used as the regression constraint for the target bounding box. The regression mapping of the basic spatial feature matrix is calculated using preset regression parameters to obtain the corresponding target bounding box.
[0009] Preferably, step S2 specifically includes: Step S21: Take the target spatial domain high-order feature matrix as input and perform a fast Fourier transform on it to transform the target spatial domain high-order feature matrix from spatial domain independent variables to frequency domain independent variables, generate a complex form matrix, and convert it to obtain a complex domain feature matrix. Step S22: Perform Hilbert transform on the complex domain feature matrix, calculate the complex orthogonal conjugate terms of the complex domain feature matrix, and linearly combine the complex domain feature matrix with the complex orthogonal conjugate terms to obtain the analytic signal feature matrix. Extract the instantaneous frequency and instantaneous phase of each frequency position in the analytic signal feature matrix.
[0010] Preferably, the processing logic of step S22 is as follows: The real components of a one-dimensional frequency domain sequence are extracted along the horizontal row vector direction or the vertical column vector direction of the complex domain feature matrix. The real components of the one-dimensional frequency domain sequence are then transformed using a preset Hilbert transform operator to obtain the complex orthogonal conjugate terms of the corresponding complex domain feature matrix. By linearly combining and complexly recombining the complex domain feature matrix with complex orthogonal conjugate terms, the analytic signal feature matrix is obtained. Calculate the arctangent ratio of the imaginary part to the real part of each complex element in the feature matrix of the analytical signal to obtain the instantaneous phase matrix corresponding to each frequency position; The instantaneous phase matrix is calculated by first-order difference along the arrangement direction of the one-dimensional frequency domain sequence to obtain the instantaneous frequency matrix corresponding to each frequency position.
[0011] Preferably, step S3 specifically includes: Step S31: Cross-mapping the instantaneous phase matrix and the instantaneous frequency matrix through matrix multiplication to calculate the complex weighting coefficients of each frequency channel; Step S32: Multiply the complex weight coefficients of each frequency channel with the corresponding frequency channel in the complex domain feature matrix to obtain the frequency domain adaptive recalibration feature matrix. Step S33: Perform an inverse fast Fourier transform on the frequency domain adaptive recalibration feature matrix to obtain a complex matrix after the inverse transform, and extract the real part of the complex matrix after the inverse transform to obtain the target frequency domain reconstructed feature matrix.
[0012] Preferably, the processing logic for cross mapping is as follows: The instantaneous phase matrix and instantaneous frequency matrix are used as inputs; The first preset weight matrix is used to perform a first matrix multiplication operation with the instantaneous phase matrix and the instantaneous frequency matrix respectively to obtain the first phase intermediate matrix and the first frequency intermediate matrix; The second preset weight matrix is used to perform a second matrix multiplication operation with the instantaneous phase matrix and the instantaneous frequency matrix respectively to obtain the second phase intermediate matrix and the second frequency intermediate matrix; Subtract the first phase intermediate matrix and the second frequency intermediate matrix to obtain the calibration real part matrix, and add the first frequency intermediate matrix and the second phase intermediate matrix to obtain the calibration imaginary part matrix. By combining the real part of the calibration matrix as the real part term and the imaginary part of the calibration matrix as the imaginary part term into complex vectors, the complex weighting coefficients of each frequency channel are obtained.
[0013] Preferably, step S4 specifically includes: Step S41: Flatten the target spatial domain high-order feature matrix and the target frequency domain reconstructed feature matrix respectively to obtain a one-dimensional spatial domain feature vector and a one-dimensional frequency domain feature vector. Step S42: The one-dimensional spatial domain feature vector and the one-dimensional frequency domain feature vector are concatenated and spliced together to obtain the spatial-frequency fused feature vector. Step S43: Perform decision-level mapping calculation on the space-frequency fusion feature vector to obtain the corresponding mushroom maturity level result; The mushroom maturity grading results include immature, mature, overripe, and pending re-inspection.
[0014] Preferably, the processing logic for the decision hierarchy mapping calculation is as follows: The spatial-frequency fusion feature vector is multiplied by the preset classification weight matrix, and then weighted and superimposed with the preset bias vector to obtain a linear feature vector. The probability distribution vector is obtained by performing a probability transformation on the linear eigenvector using a normalized exponential function. The probability distribution vector includes immature probability values, mature probability values, and overripe probability values; The maximum value is searched for the immature probability value, mature probability value and overmature probability value. The probability value with the largest value is determined as the target maximum value, and the preset maturity category corresponding to the target maximum value is determined as the candidate maturity category. The preset maturity categories include immature, mature, and overripe; The confidence level determination process for the target maximum value includes: When the target maximum value is greater than or equal to the preset confidence threshold, and the candidate maturity category is immature, the maturity classification result of immature mushrooms is obtained. When the target maximum value is greater than or equal to the preset confidence threshold, and the candidate maturity category is mature, the maturity classification result of mature mushrooms is obtained. When the target maximum value is greater than or equal to the preset confidence threshold, and the candidate maturity category is overripe, the maturity classification result of overripe mushrooms is obtained. When the maximum target value is less than the preset confidence threshold, the confidence of the current growth state is determined to be insufficient, and the mushroom maturity grading result to be re-examined is obtained.
[0015] The beneficial effects of this invention are as follows: This invention extracts spatial features from the original mushroom image using a backbone feature extraction network and combines this with bounding box regression to determine the region of interest, thereby stably obtaining the target spatial high-order feature matrix under background interference and pose changes. Furthermore, a Fast Fourier Transform is performed on the target spatial high-order feature matrix to obtain a complex domain feature matrix, and an analytical signal feature matrix is constructed using a Hilbert Transform to extract the instantaneous phase and instantaneous frequency at each frequency position, enabling more sensitive characterization of texture details and structural changes caused by mushroom maturity variations in the frequency domain. Finally, a cross-mapping is performed on the instantaneous phase and instantaneous frequency to obtain the complex weight coefficients for each frequency channel. The complex domain feature matrix is multiplied and subjected to inverse fast Fourier transform to obtain the target frequency domain reconstructed feature matrix, enabling adaptive recalibration of frequency components and enhancing the frequency response related to maturity discrimination. Finally, the target spatial domain high-order feature matrix and the target frequency domain reconstructed feature matrix are flattened and concatenated to obtain a spatial-frequency fusion feature vector, which is then used for decision-level mapping calculation. The resulting mushroom maturity classifications (immature, mature, overripe, and requiring re-inspection) are output. This improves the accuracy and robustness of maturity discrimination compared to methods based solely on spatial features or simple threshold rules. Furthermore, the re-inspection mechanism reduces the risk of misclassification of boundary samples, enhancing the reliability and controllability of practical sorting applications. Attached Figure Description
[0016] Figure 1 A flowchart illustrating the steps of a mushroom maturity prediction method based on image recognition, as provided in one embodiment of the present invention; Figure 2 The flowchart shows the frequency domain transformation and Hilbert instantaneous parameter extraction. Figure 3 A flowchart for generating complex weights for phase-frequency cross-mapping; Figure 4 A flowchart for flattening and cascading fusion of spatial frequency characteristics; Figure 5 This is a flowchart for decision-making classification and confidence level determination. Detailed Implementation
[0017] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.
[0018] Example, refer to Figure 1-5 This paper presents a method for predicting mushroom maturity based on image recognition, comprising the following steps: Step S1: Acquire the original image of the mushroom and input the original image of the mushroom into the backbone feature extraction network for spatial feature extraction and target region cropping to obtain the target spatial high-order feature matrix; Step S2: Perform a fast Fourier transform on the high-order feature matrix of the target spatial domain to obtain the feature matrix of the complex domain, and then perform a Hilbert transform to extract the instantaneous frequency and instantaneous phase at each frequency position. Step S3: Cross-mapping is performed on the instantaneous phase and instantaneous frequency to obtain the complex weight coefficients of each frequency channel, and matrix multiplication and inverse fast Fourier transform are performed on the complex domain feature matrix to obtain the target frequency domain reconstructed feature matrix. Step S4: Flatten the target spatial domain high-order feature matrix and the target frequency domain reconstructed feature matrix respectively and concatenate them end to end to obtain the spatial-frequency fusion feature vector, and perform decision-level mapping calculation to obtain the corresponding mushroom maturity level result.
[0019] In specific implementation, step S1 includes: Step S11: Acquire the original image of the mushroom and input the original image of the mushroom into the backbone feature extraction network to extract the basic spatial feature matrix; The backbone feature extraction network consists of an initial convolutional layer, a hybrid attention layer, and a deformable convolutional layer; In step S11, the original images of the mushrooms are acquired by continuously imaging and sampling the mushrooms on the conveyor belt using an industrial camera fixed above the harvesting and sorting station. The optical axis of the industrial camera is perpendicular to the plane of the conveyor belt to reduce the influence of perspective distortion on the bounding box regression. The resolution of the industrial camera is set to 1920 x 1080 pixels, the frame rate is set to 30 frames per second, and the exposure time is set to 1 x 10. -3 The gain was set to a fixed value to suppress brightness drift. To ensure the color and texture of the mushroom surface remained stable across different batches, this embodiment used a ring-shaped supplementary light source with a constant color temperature and placed a polarizer in front of the camera lens to reduce the wet reflection from the mushroom surface. A dark matte material was used for the acquisition background to enhance the contrast between the mushroom and the background. The acquired original mushroom image was a three-channel color image. In this embodiment, the original mushroom image was normalized and scaled to 640×640 pixels before being input into the backbone feature extraction network. The scaling ratio and edge fill offset were recorded for subsequent mapping between the target bounding box and the original mushroom image.
[0020] The backbone feature extraction network includes an initial convolutional layer, a hybrid attention layer, and a deformable convolutional layer. The initial convolutional layer is used to map the original mushroom image to a high-dimensional spatial representation. In this embodiment, the initial convolutional layer adopts a 3-layer convolutional structure. The first convolutional layer has a kernel size of 3×3, 32 output channels, and a stride of 2. The second convolutional layer has a kernel size of 3×3, 64 output channels, and a stride of 2. The third convolutional layer has a kernel size of 3×3, 128 output channels, and a stride of 2. Each convolutional layer is followed by batch normalization and ReLU activation, thereby obtaining a high-dimensional spatial mapping matrix with a spatial resolution of 80×80 and 128 channels. The hybrid attention layer is used to jointly calibrate the high-dimensional spatial mapping matrix using channel attention and spatial attention. In this embodiment, channel attention is achieved by global average pooling followed by two linear mapping layers. The hidden dimension of the linear mapping is set to 64, and the output dimension is restored to 128. Spatial attention is achieved by concatenating max pooling and average pooling along the channel dimension, followed by a 7×7 convolution to obtain spatial attention weights. The channel attention weights and spatial attention weights are then multiplied element-wise with the high-dimensional spatial mapping matrix to obtain the weighted and calibrated high-dimensional spatial mapping matrix. The deformable convolutional layer is used to enhance the alignment sampling capability at target edges and deformable regions. In this embodiment, the deformable convolutional layer uses a two-layer deformable convolutional structure, with each convolutional kernel size of 3×3, 256 output channels, and a stride of 1. It generates a two-dimensional spatial offset for each sampling position through offset prediction convolution. Subsequently, bilinear interpolation sampling is performed on irregular sampling points, outputting a basic spatial feature matrix with a spatial resolution of 80×80 and 256 channels. The backbone feature extraction network was trained using supervised learning. The training data consisted of the original mushroom images collected in step S11, with each image labeled with a mushroom bounding box. During training, the input resolution was fixed at 640×640 pixels, the AdamW optimizer was used, and the learning rate was set to 1×10⁻⁶. -4 The weight decay is set to 1×10. -2 The batch size is set to 16, the number of training epochs is set to 120, and the learning rate is set to 1×10⁻⁶. -4 To maintain convergence stability and avoid bounding box regression oscillations under limited sample conditions, a batch size of 16 was set to balance memory usage and gradient estimation stability. The number of training epochs was set to 120 to allow the hybrid attention layer and deformable convolutional layer to fully learn the feature representation capabilities under mushroom edge deformation and occlusion conditions. During training, random brightness perturbations and slight blur enhancements were used to improve robustness under conditions of lighting fluctuations and slight defocus. After training, network parameters were fixed during the inference phase to extract the basic spatial feature matrix.
[0021] The processing logic for extracting the basic spatial feature matrix is as follows: In the initial convolutional layer, the original mushroom image is subjected to initial convolutional mapping operation to obtain a high-dimensional spatial mapping matrix; The initial convolutional layer is used to perform initial convolutional mapping operations on the original mushroom image and obtain a high-dimensional spatial mapping matrix. The initial convolutional layer adopts a 3-layer convolutional structure, with a kernel size of 3×3, and output channels of 32, 64, and 128 respectively, and strides of 2, 2, and 2 respectively. After each convolutional layer, batch normalization and ReLU activation are performed to reduce the spatial resolution from 640×640 to 80×80 and form a high-dimensional spatial mapping matrix with 128 channels, thereby preserving the high-response features of the mushroom cap outline and texture at a lower spatial resolution.
[0022] In the hybrid attention layer, the high-dimensional spatial mapping matrix is processed by global average pooling and linear mapping matrix multiplication through a hybrid spatial channel attention mechanism to obtain channel attention weights. At the same time, max pooling and average pooling are concatenated along the spatial dimension corresponding to the high-dimensional spatial mapping matrix to obtain spatial attention weights. The hybrid spatial channel attention mechanism comprises a channel attention branch and a spatial attention branch. The channel attention branch performs global average pooling along the spatial dimension of the high-dimensional spatial mapping matrix to obtain channel description vectors. Then, it obtains channel attention weights through two layers of linear mapping. The hidden dimension of the linear mapping is set to 64, and the output dimension is restored to 128, achieving a balance between parameter size and expressive power. The spatial attention branch performs max pooling and average pooling along the channel dimension of the high-dimensional spatial mapping matrix and performs concatenated mapping. Then, it obtains spatial attention weights through 7×7 convolution, expanding the receptive field and improving the focusing ability on the mushroom target region. Subsequently, the channel attention weights are element-wise multiplied with the high-dimensional spatial mapping matrix to obtain the channel calibration result. Then, the spatial attention weights are element-wise multiplied with the channel calibration result to obtain a weighted calibrated high-dimensional spatial mapping matrix, thereby suppressing background texture response and enhancing the response of the mushroom target region.
[0023] The channel attention weights and spatial attention weights are calibrated by multiplying element-wise with the corresponding spatial dimension high-dimensional spatial mapping matrix to obtain the weighted calibrated high-dimensional spatial mapping matrix. In the deformable convolutional layer, a preset sampling convolutional kernel is introduced. The weighted and calibrated high-dimensional spatial mapping matrix is subjected to deformable convolutional sampling operation. The two-dimensional spatial offset of the preset sampling convolutional kernel in the horizontal and vertical directions is calculated based on the spatial position corresponding to the weighted and calibrated high-dimensional spatial mapping matrix. Based on the two-dimensional spatial offset, bilinear interpolation sampling is performed on the irregular grid sampling points to obtain the basic spatial feature matrix.
[0024] Deformable convolutional layers are used to perform deformable convolutional sampling operations on the weighted and calibrated high-dimensional spatial mapping matrix and output the basic spatial feature matrix. The preset sampling convolutional kernel is a 3x3 kernel corresponding to 9 regular sampling positions. The deformable convolutional layer first uses offset prediction convolution to regress the two-dimensional spatial offset. The offset prediction convolution uses a 3x3 kernel and outputs 18 channels, which represent the horizontal and vertical offsets at the 9 sampling positions. Subsequently, based on the two-dimensional spatial offsets, bilinear interpolation sampling is performed on the weighted and calibrated high-dimensional spatial mapping matrix at irregular grid sampling points, and the result is weighted and summed with the preset sampling convolutional kernel weights. The computational form of deformable convolution is spatially... The location is represented as: ; in, For deformable convolutional layers in spatial position The eigenvalues of the underlying spatial feature matrix output at that location. For output channel index, The sampling point index is the preset sampling convolution kernel. In this embodiment, the preset sampling convolution kernel is 3 by 3, so the number of sampling points is 9. Iterate through the 9 sampling positions from 1 to 9. For the preset sampling convolution kernel in the output channel With the Convolution weights at each sampling point For the first The fixed offset vector of the regular sampling position relative to the center position corresponding to each sampling point. For the first The two-dimensional spatial offset corresponding to each sampling point This is the weighted, calibrated high-dimensional spatial mapping matrix. The feature values are obtained by bilinear interpolation from the weighted and calibrated high-dimensional spatial mapping matrix at irregular sampling locations. The deformable convolutional layer adopts a two-layer deformable convolutional structure, with a kernel size of 3x3, 256 output channels, and a stride of 1. The output of the two layers serves as the basic spatial feature matrix, which maintains good feature alignment and target focusing ability under mushroom edge deformation and local occlusion conditions.
[0025] Step S12 involves performing position prediction and feature extraction processing on the basic spatial feature matrix to obtain the target spatial high-order feature matrix. The processing logic is as follows: Boundary box regression is performed on the basic spatial feature matrix to obtain the target bounding box, and the region of interest in the image is determined based on the mapping correspondence between the target bounding box and the original mushroom image. The processing logic for the target bounding box is as follows: The initial prediction box is obtained by mapping the basic spatial feature matrix using preset regression parameters; The preset regression parameters are a set of regression parameters used to map the basic spatial feature matrix to bounding box regression quantities. The preset regression parameters consist of the convolutional kernel weights and biases of the location prediction layer, and together with the geometric prior of the reference box, determine the center coordinates and width and height of the initial prediction box. The location prediction layer is consistent with step S12, using a two-layer convolutional structure to complete the regression mapping. The first convolutional kernel size is 3×3 and the number of output channels is 256. The second convolutional kernel size is 1×1 and the number of output channels is 4. The four regression quantities output by the second convolutional layer correspond to the horizontal offset of the center point, the vertical offset of the center point, the width scale, and the height scale, respectively. The weights and biases of the two convolutional layers are fixed after training and are not updated, and are used as preset regression parameters in the inference stage.
[0026] The initial prediction box is obtained by mapping the basic spatial feature matrix using preset regression parameters. This involves inputting the basic spatial feature matrix into the location prediction layer and performing convolutional regression mapping to obtain four regression values for each spatial location. The second convolutional layer of the location prediction layer is then used to map the spatial location... Taking the output at point as an example, its convolution mapping calculation can be expressed as: ; in, For location prediction layer in spatial location The output of the first One regression quantity, For the first The input channel and the first The contribution coefficient of each sampling point location to the output regression quantity The basic spatial characteristic matrix in the th On each input channel, located in spatial position eigenvalues at that location For the preset regression parameters and the first The bias term corresponding to each regressor; The spatial intersection-union ratio error between the initial predicted bounding box and the ground truth bounding box is used as the regression constraint for the target bounding box. The regression mapping of the basic spatial feature matrix is calculated using preset regression parameters to obtain the corresponding target bounding box.
[0027] The spatial intersection-union ratio (CIU) error is calculated by first calculating the area of the intersection region between the initial predicted bounding box and the ground truth bounding box, and then calculating the area of the union region between the initial predicted bounding box and the ground truth bounding box. The spatial CIU is the ratio of the intersection region area to the union region area, and the spatial CIU error is the complement of the spatial CIU. The formulas for calculating the spatial CIU and spatial CIU error are as follows: ; ; in, For spatial intersection and union ratio, This represents the area of the intersection region between the initial predicted bounding box and the ground truth bounding box. Let be the area of the union region of the initial predicted bounding box and the ground truth bounding box. The spatial intersection-union ratio (IURR) is the error. The smaller the IURR, the higher the degree of overlap between the initial predicted bounding box and the ground truth bounding box.
[0028] The approach of using the spatial intersection-union error (CIU) as a regression constraint for the target bounding box and calculating the regression mapping of the basic spatial feature matrix using preset regression parameters involves constructing a regression loss using the CIU during the training phase and updating the preset regression parameters through backpropagation. This ensures that the regression output from the location prediction layer continuously reduces the CIU between the initial predicted box and the ground truth box. In this embodiment, the regression loss is expressed as a mean value of the CIU, and the calculation formula is as follows: ; in, To regress the loss, The number of samples participating in the regression constraints. For the first Spatial crossover and reunification error of each sample. By analyzing the... Optimization is performed, and the preset regression parameters are gradually converged to a parameter state that can stably output the target bounding box.
[0029] After training converges, the updated preset regression parameters are fixed and saved. During the inference phase, the preset regression parameters are still used to perform regression mapping calculation on the basic spatial feature matrix to obtain the initial prediction box. The initial prediction box is then output as the target bounding box, thereby completing the calculation and localization of the target bounding box. The target bounding box is used to subsequently determine the region of interest in the image and to extract the corresponding region from the basic spatial feature matrix to obtain the target spatial high-order feature matrix.
[0030] Based on the spatial coordinates of the region of interest in the image, the corresponding region is extracted from the basic spatial feature matrix to obtain the target spatial high-order feature matrix.
[0031] Specifically, position prediction and feature extraction are performed on the basic spatial feature matrix to obtain the target spatial high-order feature matrix. Position prediction is achieved by bounding box regression calculation to obtain the target bounding box. In this embodiment, a position prediction layer is added after the basic spatial feature matrix. The position prediction layer uses a two-layer convolutional structure: the first layer has a 3×3 kernel size, 256 output channels, and a stride of 1; the second layer has a 1×1 kernel size, 4 output channels, and a stride of 1. It outputs four regression quantities, corresponding to the horizontal offset of the target bounding box center point, the vertical offset of the target bounding box center point, the width scale of the target bounding box, and the height scale of the target bounding box. The bounding box regression calculation is performed using a reference box parameterization method. The center coordinates of the reference box are determined by the feature map grid position. The width and height of the reference box are preset constants and proportional to the input size. In this embodiment, the reference box width is set to 160 pixels to cover the common scale range of a single mushroom under the input size. The four regression quantities output by the position prediction layer are denoted as... , , , Mark the center coordinates of the reference frame as , Let the width and height of the reference box be denoted as , The formulas for calculating the center coordinates and width and height of the target bounding box are as follows: ; ; ; ; in, The horizontal coordinates of the center point of the target bounding box. The vertical coordinates of the center point of the target bounding box. The width of the target bounding box. The height of the target bounding box. For natural numbers, The horizontal coordinates of the center point of the reference frame. The vertical coordinate of the center point of the reference frame. The width of the reference box. The height of the reference box. This is the lateral offset regression value of the center point output by the location prediction layer. This is the longitudinal offset regression value of the center point output by the location prediction layer. This is the width-scale regression output of the location prediction layer. This is the height-scale regression output of the location prediction layer. The reference box is used to provide an initial location and scale baseline for the bounding box regression.
[0032] The mapping relationship between the target bounding box and the original mushroom image is used to restore the target bounding box coordinates at the input scale to the original mushroom image coordinate system. In this embodiment, the original mushroom image is scaled to 640×640 pixels in step S11, and the scaling ratio and edge fill offset are recorded. Therefore, the mapping relationship is completed through inverse scaling and inverse offset. That is, the edge fill offset is subtracted from the four boundary coordinates of the target bounding box, and then divided by the scaling ratio to obtain its corresponding position in the original mushroom image coordinate system. The region of interest can be determined using this mapping relationship. The region of interest is the area covered by the target bounding box on the original mushroom image. When determining the region of interest, the target bounding box is appropriately expanded around it. The expansion ratio is set to 0.10 to retain the mushroom edge and local background texture information. The expansion ratio of 0.10 is used to avoid excessive truncation in the case of occlusion or blurred edges, which would cause the target spatial domain high-order feature matrix to lack effective edge features. At the same time, the expansion range is controlled to avoid introducing too much background interference.
[0033] The corresponding region is extracted on the basic spatial feature matrix to obtain the target spatial high-order feature matrix. First, the boundary coordinates of the region of interest in the image under the input image coordinate system are mapped to the spatial coordinate system of the basic spatial feature matrix according to the feature downsampling step size. The downsampling step size of the basic spatial feature matrix relative to the input image is 8. Then, the corresponding feature sub-region is extracted from the basic spatial feature matrix according to the mapped spatial coordinate position as the target spatial high-order feature matrix. In order to ensure that the target spatial high-order feature matrix of mushroom targets of different scales has a uniform size for subsequent processing, this embodiment resamples the extracted feature sub-regions to a fixed spatial size of 32×32 and maintains the number of channels at 256 through bilinear interpolation to obtain the target spatial high-order feature matrix. Through the above position prediction processing and feature extraction processing, the mushroom target can be located from the original mushroom image and the high-order semantic feature region corresponding to the mushroom target can be extracted from the basic spatial feature matrix.
[0034] In specific implementation, step S2 includes: Step S21: Take the target spatial domain high-order feature matrix as input and perform a fast Fourier transform on it to transform the target spatial domain high-order feature matrix from spatial domain independent variables to frequency domain independent variables, generate a complex form matrix, and convert it to obtain a complex domain feature matrix. Specifically, the method for generating complex form matrices involves processing the high-order characteristic matrix of the target spatial domain in the th order. The spatial data on each output channel is denoted as ,in, For horizontal spatial indexing, For vertical spatial indexing, The value is a real number. As the real part of the complex input matrix, a zero matrix of the same size is used as the imaginary part of the complex input matrix, thus forming the complex input matrix to be transformed. This makes the output of the Fast Fourier Transform in complex form and retains the phase information, providing a complex input basis for the Hilbert Transform in step S22.
[0035] The process of performing a Fast Fourier Transform (FFT) on the high-order feature matrix of the target spatial domain involves performing a two-dimensional FFT on the 32×32 complex input matrix of each channel. The two-dimensional FFT employs a row-first, column-later decomposition process. First, a one-dimensional FFT is performed on each row along the vertical index direction to obtain an intermediate complex matrix. Then, a one-dimensional FFT is performed on each column of the intermediate complex matrix along the horizontal index direction to obtain the final frequency domain complex matrix. The one-dimensional FFT uses a divide-and-conquer butterfly recursive calculation process. Since the length of 32 satisfies the integer power of 2 condition, this embodiment does not pad the spatial dimensions and directly performs 5 levels of butterfly operations on the 32-length sequence, thereby reducing numerical disturbances introduced by invalid frequency components.
[0036] The first The two-dimensional fast Fourier transform results of each output channel are denoted as... ,in, For horizontal frequency indexing, For vertical frequency indexing, For complex values, the transformation relationship from the spatial domain to the frequency domain can be expressed as: ; in, The imaginary unit; right After repeating the above two-dimensional fast Fourier transform process for all channels from 1 to 256, all channels... The complex domain feature matrix is obtained by stacking the features according to the channel dimension. In the implementation, the complex domain feature matrix is stored in the form of real part matrix and imaginary part matrix. The real part matrix and imaginary part matrix correspond one-to-one with the target spatial domain high-order feature matrix in the channel dimension and frequency dimension, thus completing the process of transforming the target spatial domain high-order feature matrix from spatial domain independent variables to frequency domain independent variables and generating the complex domain feature matrix.
[0037] Step S22: Perform a Hilbert transform on the complex domain feature matrix, calculate the complex orthogonal conjugate terms of the complex domain feature matrix, and linearly combine the complex domain feature matrix with the complex orthogonal conjugate terms to obtain the analytic signal feature matrix. Extract the instantaneous frequency and instantaneous phase at each frequency position in the analytic signal feature matrix. The processing logic is as follows: The real components of a one-dimensional frequency domain sequence are extracted along the horizontal row vector direction or the vertical column vector direction of the complex domain feature matrix. The real components of the one-dimensional frequency domain sequence are then transformed using a preset Hilbert transform operator to obtain the complex orthogonal conjugate terms of the corresponding complex domain feature matrix. The preset Hilbert transform operator is a one-dimensional finite-length discrete Hilbert transform convolution kernel, used to transform the real components of a one-dimensional frequency domain sequence into conjugate components orthogonal to it. In this embodiment, the length of the preset Hilbert transform operator is set to 31 to balance the approximation accuracy of the conjugate components and the computational complexity. The center coefficient of the convolution kernel is set to 0, and the remaining coefficients of the convolution kernel are set according to the truncation form of the discrete Hilbert transform kernel to satisfy the odd symmetry property and suppress the even-numbered response. Its coefficients are defined as follows: ; ; ; in, For convolution kernel index, For the discrete convolution kernel of the preset Hilbert transform operator at index 1 Convolution coefficients at; The process of extracting the real component of a one-dimensional frequency domain sequence along the horizontal row vector direction of the complex domain feature matrix and transforming it using a preset Hilbert transform operator is as follows: While keeping each channel index and each vertical frequency index unchanged, the real component along the horizontal frequency index direction is taken as the input of the one-dimensional frequency domain sequence. A one-dimensional convolution operation is then performed on this one-dimensional frequency domain sequence, and the output is used as the complex orthogonal conjugate term. The formula for calculating the complex orthogonal conjugate term is: ; in, For complex orthogonal conjugate terms, The characteristic matrix of the complex field at the channel index is The horizontal frequency index on the channel is Vertical frequency index is The value of the real component at the location; When the horizontal frequency index goes out of bounds, this embodiment uses boundary copying to fill in the out-of-bounds position to ensure that the complex orthogonal conjugate terms and the complex domain feature matrix have the same size in the channel dimension and frequency dimension.
[0038] By linearly combining and complexly recombining the complex domain feature matrix with complex orthogonal conjugate terms, the analytic signal feature matrix is obtained. Specifically, the real components of the complex domain characteristic matrix are used as the real components of the analytic signal characteristic matrix, and the imaginary components of the complex domain characteristic matrix are added to the complex orthogonal conjugate terms to obtain the imaginary components of the analytic signal characteristic matrix, thus obtaining the complex elements of the analytic signal characteristic matrix. The expression for the complex recombination relation of the analytic signal characteristic matrix is: ; ; in, To analyze the signal feature matrix at the channel index Horizontal frequency index With vertical frequency index The actual item at the location, For the characteristic matrix of the complex field in the channel index Horizontal frequency index With vertical frequency index The real part of the quantity. To analyze the signal feature matrix at the channel index Horizontal frequency index With vertical frequency index The virtual part of the term, For the characteristic matrix of the complex field in the channel index Horizontal frequency index With vertical frequency index The imaginary component at the location; The expression for the complex elements of the analytic signal feature matrix is: ; in, To analyze the signal feature matrix at the channel index Horizontal frequency index With vertical frequency index Complex elements at a location.
[0039] The instantaneous phase matrix corresponding to each frequency position is obtained by calculating the arctangent ratio of the imaginary part to the real part of each complex element in the characteristic matrix of the analytical signal. The calculation formula is as follows: ; in, For the instantaneous phase matrix in the channel index Horizontal frequency index With vertical frequency index The phase value at that point, It should be a very small constant to avoid the denominator being zero; The instantaneous phase matrix is calculated by first-order difference along the arrangement direction of the one-dimensional frequency domain sequence to obtain the instantaneous frequency matrix corresponding to each frequency position.
[0040] The instantaneous frequency matrix is obtained by performing a first-order difference calculation on the instantaneous phase matrix along the arrangement direction of the one-dimensional frequency domain sequence. In this embodiment, the difference is performed along the horizontal frequency index direction. The formula for calculating the instantaneous frequency matrix is as follows: ; in, For the instantaneous frequency matrix in the channel index Horizontal frequency index With vertical frequency index The frequency value at that location, For channel index Horizontal frequency index With vertical frequency index Phase value at that point, lateral frequency index The value ranges from 0 to 30, and the horizontal frequency index is... When the value is 31, it is not included in the difference and the instantaneous frequency matrix value at that position is set to 0, thereby obtaining the instantaneous frequency matrix corresponding to each frequency position and using it as the input for the cross mapping in step S3.
[0041] Compared to traditional methods that only utilize convolutional features or texture statistics in the spatial domain to determine mushroom maturity, this application introduces a Fast Fourier Transform (FFT) after obtaining the target spatial domain high-order feature matrix. This transforms the target spatial domain high-order feature matrix from spatial domain independent variables to frequency domain independent variables, forming a complex domain feature matrix. This allows subtle texture variations, edge detail variations, and periodic structural variations related to maturity to be explicitly expressed in the form of frequency components, rather than relying solely on local convolutional responses in the spatial domain, which are susceptible to illumination, pose, and background perturbations. Furthermore, this application performs a Hilbert transform on the complex domain feature matrix to obtain complex orthogonal conjugate terms, and then performs linear combination and complex recombination with the complex domain feature matrix to construct an analytical signal feature matrix. The instantaneous phase and instantaneous frequency at each frequency position are extracted, so that the frequency structure drift and phase structure difference caused by maturity changes can be stably characterized in the form of instantaneous phase matrix and instantaneous frequency matrix. This makes up for the insufficient discrimination ability caused by traditional frequency domain methods that only use amplitude information or power spectrum information and ignore phase information. At the same time, the instantaneous phase and instantaneous frequency are derived from the consistent modeling of the same complex domain feature matrix, which can form a more sensitive and distinguishable description of the texture refinement, wrinkle changes and edge transition changes caused by maturity. This makes the subsequent cross mapping and frequency domain reconstruction in step S3 have a stronger feature selection basis, and ultimately improves the stability and generalization ability of mushroom maturity grading results under complex lighting, surface wet reflection and slight posture changes.
[0042] In specific implementation, step S3 includes: Step S31 involves cross-mapping the instantaneous phase matrix and instantaneous frequency matrix using matrix multiplication to calculate the complex weighting coefficients for each frequency channel. The processing logic is as follows: The instantaneous phase matrix and instantaneous frequency matrix are used as inputs; The first preset weight matrix is used to perform a first matrix multiplication operation with the instantaneous phase matrix and the instantaneous frequency matrix respectively to obtain the first phase intermediate matrix and the first frequency intermediate matrix; The second preset weight matrix is used to perform a second matrix multiplication operation with the instantaneous phase matrix and the instantaneous frequency matrix respectively to obtain the second phase intermediate matrix and the second frequency intermediate matrix; It should be noted that the first preset weight matrix is used to perform a first linear mapping between the instantaneous phase matrix and the instantaneous frequency matrix, and the second preset weight matrix is used to perform a second linear mapping between the instantaneous phase matrix and the instantaneous frequency matrix. Together, they constitute the set of linear transformation parameters for the cross-mapping. The first and second preset weight matrices are used as learnable parameters during the training phase and remain fixed during the inference phase, hence the term "preset". In this embodiment, the dimensions of both the first and second preset weight matrices are set to 1024 rows and 1024 columns to accommodate the flattened 1024x1 vector input and ensure that the output remains a 1024x1 vector, thus facilitating subsequent rearrangement to restore a 32x32 matrix. Preferably, in this embodiment, the first and second preset weight matrices are constructed as diagonal matrices to reduce the parameter size and improve training stability. The specific form of the first preset weight matrix is as follows: ; The specific form of the second preset weight matrix is as follows: ; in, This is the first preset weight matrix. This is the second preset weight matrix. to The diagonal elements of the preset first weight matrix, to These are the diagonal elements of the pre-defined second weight matrix; The first and second preset weight matrices adopt a diagonal structure. Each dimension of the flattened vector of the instantaneous phase and frequency matrices corresponds to a specific frequency position. The diagonal structure allows for independent scaling and calibration of phase and frequency information at different frequency positions, thereby reducing coupling between irrelevant frequency positions and improving the interpretability and stability of complex weight coefficients. The preferred initialization range for the diagonal elements is -0.05 to +0.05. This avoids excessive amplification during the early stages of training due to cross-mapping, which could lead to divergence in the frequency domain adaptive recalibration feature matrix. Simultaneously, it preserves sufficient gradient magnitude to facilitate subsequent learning of maturity-related frequency position weight distributions.
[0043] When the instantaneous phase matrix and instantaneous frequency matrix are used as input, the instantaneous phase matrix at index f of each frequency channel is flattened to obtain the phase vector, and the instantaneous frequency matrix at index f of each frequency channel is flattened to obtain the frequency vector. Both are 1024 rows and 1 column. The processing procedure for the first matrix multiplication operation is to calculate the product of the preset first weight matrix and the phase vector to obtain the first intermediate phase matrix, and then calculate the product of the preset first weight matrix and the frequency vector to obtain the first intermediate frequency matrix. The processing procedure for the second matrix multiplication operation is to calculate the product of the preset second weight matrix and the phase vector to obtain the second intermediate phase matrix, and then calculate the product of the preset second weight matrix and the frequency vector to obtain the second intermediate frequency matrix. The calculation formula is as follows: ; ; ; ; in, This is the flattened vector form of the intermediate matrix of the first phase. For phase vector, This is the flattened vector form of the intermediate matrix of the first frequency. It is a frequency vector. This is the flattened vector form of the intermediate matrix of the second phase. This is the flattened vector form of the intermediate matrix of the second frequency. Frequency channel index; Subtract the first phase intermediate matrix and the second frequency intermediate matrix to obtain the calibration real part matrix, and add the first frequency intermediate matrix and the second phase intermediate matrix to obtain the calibration imaginary part matrix. Among them, for and The calibration real part vector is obtained by subtracting element-wise; the calibration imaginary part matrix is obtained by adding the first frequency intermediate matrix and the second phase intermediate matrix. and The calibration imaginary part vector is obtained by subtracting elements one by one, and its calculation formula is as follows: ; ; in, To calibrate the flattened vector form of the real part matrix, This is used to define the flattened vector form of the imaginary part matrix.
[0044] Will and Rearrange them into 32×32 matrices according to their original order before flattening to obtain the calibration real part matrix and the calibration imaginary part matrix.
[0045] By combining the real part of the calibration matrix as the real part term and the imaginary part of the calibration matrix as the imaginary part term into complex vectors, the complex weighting coefficients of each frequency channel are obtained.
[0046] The process of combining the calibration real part matrix as the real part term and the calibration imaginary part matrix as the imaginary part term to obtain the complex weighting coefficients involves constructing complex elements at each frequency channel and each frequency position. The complex weighting coefficients are located at the frequency channel index... Horizontal frequency index is Vertical frequency index is The complex element at the position is denoted as Its complex combined form is: ; in, To calibrate the real part matrix at the frequency channel index is And the frequency position is The element value at that location, To calibrate the imaginary part matrix at the frequency channel index is And the frequency position is The element value at that location.
[0047] Step S32: Multiply the complex weight coefficients of each frequency channel with the corresponding frequency channel in the complex domain feature matrix to obtain the frequency domain adaptive recalibration feature matrix. In step S32, matrix multiplication is implemented by performing element-wise complex multiplication on the two-dimensional frequency plane within each frequency channel, so that the complex weighting coefficients simultaneously modulate the amplitude and phase of the complex domain feature matrix. The frequency domain adaptive recalibration feature matrix is located at the frequency channel index... Horizontal frequency index is Vertical frequency index is The complex element at the position is denoted as The calculation relationship is as follows: ; in, For complex elements of the complex weighting coefficients, Let be the complex elements of the characteristic matrix of the complex field.
[0048] Same frequency channel The 32×32 complex frequency plane is flattened into a 1024-row, 1-column complex vector in a fixed order. The flattened vector of the complex domain characteristic matrix is denoted as... The flattened vector of the complex weight coefficients is denoted as ,in: ; ; based on Construct a complex diagonal matrix with 1024 rows and 1024 columns. Its matrix form is: ; in, to for Complex elements in; The frequency domain adaptive recalibration vector is obtained by multiplying the flattened vector of the complex domain characteristic matrix with a complex diagonal matrix. The calculation formula is as follows: ; in, It is a frequency domain adaptive recalibration vector; The frequency channels are obtained by rearranging the frequency domain adaptive recalibration vectors into a 32×32 complex matrix in their original order. The frequency domain adaptive recalibration results. For Repeat the above process for all frequency channels from 1 to 256 and stack them according to the frequency channel dimension to obtain the frequency domain adaptive recalibration feature matrix.
[0049] Step S33: Perform an inverse fast Fourier transform on the frequency domain adaptive recalibration feature matrix to obtain a complex matrix after the inverse transform, and extract the real part of the complex matrix after the inverse transform to obtain the target frequency domain reconstructed feature matrix.
[0050] In step S33, the inverse fast Fourier transform is performed independently for each frequency channel. A two-dimensional inverse fast Fourier transform is performed on the 32×32 complex frequency plane to obtain the complex matrix after the inverse transform, indexed in space. The formula for calculating the complex elements of a number is: ; in, The complex matrix obtained by the inverse fast Fourier transform has the following frequency channel index: And the spatial index is and Complex elements at the location, For frequency channel index and Take numbers from 1 to 256. For horizontal spatial index and Take values from 0 to 31. For vertical spatial index and Take values from 0 to 31. The frequency-domain adaptive recalibration feature matrix is indexed at the frequency channel. And the horizontal frequency index is With the vertical frequency index as Complex elements at the location, For horizontal frequency index and Take values from 0 to 31. Vertical frequency index and Take values from 0 to 31. Natural exponent calculation, 32 is the side length of the two-dimensional frequency plane; After performing a two-dimensional inverse fast Fourier transform on all frequency channels, the complex matrix after the inverse transform is obtained.
[0051] The real part extraction process involves extracting the real part element by element from the complex matrix after the inverse transformation. The real part of the target frequency domain reconstruction feature matrix is used as the value at the same frequency channel and spatial index. The target frequency domain reconstruction feature matrix is at the frequency channel index. And the spatial index is The element at the location is denoted as The calculation formula is as follows: ; in, This is a real part extraction operation; The target frequency domain reconstructed feature matrix is composed of All indexed by frequency channel Spatial Index The arrangement is configured with a spatial size of 32×32 and a frequency channel number of 256, and serves as the input for flattening and concatenating the target spatial domain high-order feature matrix in step S4.
[0052] In specific implementation, step S4 includes: Step S41: Flatten the target spatial domain high-order feature matrix and the target frequency domain reconstructed feature matrix respectively to obtain a one-dimensional spatial domain feature vector and a one-dimensional frequency domain feature vector. In step S41, the processing logic for flattening the target spatial domain high-order feature matrix and the target frequency domain reconstructed feature matrix is to read the three-dimensional matrix element by element and write it into a one-dimensional array according to a fixed traversal order, thereby obtaining a one-dimensional spatial domain feature vector and a one-dimensional frequency domain feature vector. In this embodiment, the target spatial domain high-order feature matrix has 256 channels and a spatial size of 32×32, and the target frequency domain reconstructed feature matrix has 256 frequency channels and a spatial size of 32×32. Therefore, the length of the one-dimensional spatial domain feature vector is 256×32×32, and the length of the one-dimensional frequency domain feature vector is 256×32×32. To ensure that the spatial-frequency fusion feature vector has a consistent dimensional meaning among different samples, this embodiment adopts a channel-first and spatial row-first flattening order. First, the channels are traversed from smallest to largest according to the channel index. Then, within each channel, the rows are traversed from smallest to largest according to the horizontal spatial index. Then, the columns are traversed from smallest to largest according to the vertical spatial index. The read elements are then written into the one-dimensional spatial domain feature vector or the one-dimensional frequency domain feature vector in sequence. The target spatial domain high-order feature matrix at the channel index is Horizontal spatial index is Vertical spatial index is The element at the location is denoted as The first one-dimensional spatial eigenvector The elements are denoted as The flattening mapping relationship is as follows: ; ; in, Take numbers from 1 to 256. Take values from 0 to 31. Take values from 0 to 31.
[0053] The target frequency domain reconstructed feature matrix is indexed in the frequency channel. Horizontal spatial index is Vertical spatial index is The element at the location is denoted as The first one-dimensional frequency domain eigenvector The elements are denoted as The flattening mapping relationship is as follows: ; ; in, Take numbers from 1 to 256. Take values from 0 to 31. The values range from 0 to 31. By using the above fixed flattening order, each dimension of the one-dimensional spatial feature vector and the one-dimensional frequency feature vector can be stably mapped to a unique channel and spatial location, which facilitates the subsequent decision-making hierarchical mapping calculation and learning of stable feature weights.
[0054] Step S42: The one-dimensional spatial domain feature vector and the one-dimensional frequency domain feature vector are concatenated and spliced together to obtain the spatial-frequency fused feature vector. In step S42, the entire one-dimensional spatial feature vector is placed in the front section, and the entire one-dimensional frequency domain feature vector is placed in the back section. These elements are then written sequentially according to their original element order to form a new, longer one-dimensional vector. Let the length of the one-dimensional spatial feature vector be... The length of the one-dimensional frequency domain eigenvector is The length of the space-frequency fusion feature vector is The first feature vector of space-frequency fusion The elements are denoted as The writing relationship of concatenating the beginning and end is as follows: ; ; in, The first eigenvector in the one-dimensional frequency domain The corresponding element value after subtracting the length of the one-dimensional spatial feature vector. The first eigenvector in a one-dimensional spatial domain The numerical value of each element; By concatenating the beginning and end, the first half of the spatial-frequency fusion feature vector retains the spatial representation information of the target spatial high-order feature matrix, and the second half retains the frequency domain reconstruction information of the target frequency domain reconstruction feature matrix, so that the decision-level mapping calculation in step S43 can simultaneously use spatial and frequency domain features to complete the discrimination of mushroom maturity level results.
[0055] Step S43 involves performing decision-level mapping calculations on the space-frequency fusion feature vector to obtain the corresponding mushroom maturity level grading results. The processing logic is as follows: The spatial-frequency fusion feature vector is multiplied by the preset classification weight matrix, and then weighted and superimposed with the preset bias vector to obtain a linear feature vector. The preset classification weight matrix is used to map the space-frequency fusion feature vector to the linear feature vector space corresponding to the mushroom maturity grading result. The preset classification weight matrix is the linear mapping parameter in the decision grading mapping calculation, and it, together with the preset bias vector, constitutes the linear classifier parameters. The space-frequency fusion feature vector is obtained by concatenating a one-dimensional spatial feature vector and a one-dimensional frequency feature vector. In this embodiment, the length of the one-dimensional spatial feature vector is 256×32×32, and the length of the one-dimensional frequency feature vector is also 256×32×32, therefore the length of the space-frequency fusion feature vector is 524288. The preset classification weight matrix has the same number of rows as the number of categories in the probability distribution vector, which is 3 rows, and the same number of columns as the length of the space-frequency fusion feature vector, which is 524288 columns. The specific form is as follows: ; The first row corresponds to the linear mapping weights of the immature probability value, the second row corresponds to the linear mapping weights of the mature probability value, and the third row corresponds to the linear mapping weights of the overmature probability value. Preset bias vector. It is a 3x1 vector, and its specific form is: ; in, This is a bias term for the immature probability value. This is a bias term for the maturity probability value. This is a bias term for the overripe probability value; The process of multiplying the space-frequency fusion feature vector with the preset classification weight matrix and then weighting and superimposing it with the preset bias vector to obtain a linear feature vector is as follows: First, the space-frequency fusion feature vector is written as a 524288-row, 1-column vector, denoted as... Then perform matrix multiplication to obtain a 3x1 linear eigenvector, denoted as . The calculation relationship is as follows: ; The linear eigenvector contains three components, corresponding to the linear components of the immature probability value, the mature probability value, and the overripe probability value, respectively. The linear eigenvector is used as the input to the normalized exponential function.
[0056] The probability distribution vector is obtained by performing a probability transformation on the linear eigenvector using a normalized exponential function. The probability distribution vector includes immature probability values, mature probability values, and overripe probability values; The normalization exponential function is used to transform a linear eigenvector into a probability distribution vector, ensuring that the immature, mature, and overripe probabilities all fall within the range of 0 to 1, and their sum is 1. In this embodiment, the normalization exponential function performs an exponential operation on each component of the linear eigenvector to obtain a non-negative component, and then normalizes each component using the sum of these non-negative components to obtain the probability distribution vector. The three components of the linear eigenvector are denoted as... Let the three components of the probability distribution vector be denoted as The calculation relationship is as follows: ; in, This represents the probability value of immaturity. This represents the maturity probability value. This represents the probability of over-ripeness.
[0057] The maximum value is searched for the immature probability value, mature probability value and overmature probability value. The probability value with the largest value is determined as the target maximum value, and the preset maturity category corresponding to the target maximum value is determined as the candidate maturity category. The preset maturity categories include immature, mature, and overripe; The confidence level determination process for the target maximum value includes: When the target maximum value is greater than or equal to the preset confidence threshold, and the candidate maturity category is immature, the maturity classification result of immature mushrooms is obtained. When the target maximum value is greater than or equal to the preset confidence threshold, and the candidate maturity category is mature, the maturity classification result of mature mushrooms is obtained. When the target maximum value is greater than or equal to the preset confidence threshold, and the candidate maturity category is overripe, the maturity classification result of overripe mushrooms is obtained. When the maximum target value is less than the preset confidence threshold, the confidence of the current growth state is determined to be insufficient, and the mushroom maturity grading result to be re-examined is obtained.
[0058] The results of mushroom maturity grading include immature, mature, overripe, and pending re-inspection.
[0059] Specifically, the process of performing maximum value retrieval on the immature probability value, mature probability value, and overripe probability value is a comparison. The maximum value among the three factors (maturity, maturity, and overripeness) is determined as the target maximum, and the category corresponding to the target maximum is determined as the candidate maturity category. Then, a confidence level determination is performed on the target maximum to determine whether to output immature, mature, overripe, or pending review. In this embodiment, a preset confidence threshold is set to 0.75. A preset confidence threshold that is too low will make boundary samples more likely to be forcibly assigned to immature, mature, or overripe, increasing the risk of misjudgment; a preset confidence threshold that is too high will cause a large number of samples to be judged as pending review, reducing automation efficiency. Immature, mature, or overripe is only output when the maximum probability in the probability distribution vector has a high advantage. Therefore, in cases where the maturity grading boundary is blurred, illumination fluctuations, or surface reflections cause feature instability, uncertain samples are classified as pending review, reducing the impact of incorrect grading on subsequent sorting decisions and improving the reliability of mushroom maturity grading results.
[0060] Finally, it should be noted that the ordinal numbers such as "first" and "second" used in this specification are only used to distinguish and explain similar technical features to facilitate description and understanding, and are not intended to limit these technical features to have a specific order, subordinate relationship or necessary correspondence.
[0061] The terms "including," "comprising," and their variations, as used in this specification, have a non-exclusive meaning. That is, unless otherwise specified, a process, method, or system that includes several elements may include not only the elements explicitly listed, but also other elements not explicitly listed, or elements inherent to implementing the process, method, or system. Similarly, a technical feature defined by including one element does not exclude the presence of other identical elements.
[0062] The embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments, while identical or similar content is not repeated. Those skilled in the art can make equivalent substitutions or appropriate adjustments to the intra-layer parameter configuration of the backbone feature extraction network, the implementation method of target bounding box regression, the length of the preset Hilbert transform operator, the construction method of the preset first weight matrix and the preset second weight matrix, and the value range of the preset confidence threshold, without departing from the technical scope defined by the claims of this invention, and can still achieve the technical effect of outputting mushroom maturity grading results through spatial-frequency fusion feature vectors. The description of the above embodiments enables those skilled in the art to implement or use this invention, and the scope of protection of this invention is based on the above content, and should cover equivalent modifications consistent with the principles and novel features disclosed in this invention.
Claims
1. A method for predicting and determining the maturity of mushrooms based on image recognition, characterized in that, Includes the following steps: Step S1: Acquire the original image of the mushroom and input the original image of the mushroom into the backbone feature extraction network for spatial feature extraction and target region cropping to obtain the target spatial high-order feature matrix; Step S2: Perform a fast Fourier transform on the high-order feature matrix of the target spatial domain to obtain the feature matrix of the complex domain, and then perform a Hilbert transform to extract the instantaneous frequency and instantaneous phase at each frequency position. Step S3: Cross-mapping is performed on the instantaneous phase and instantaneous frequency to obtain the complex weight coefficients of each frequency channel, and matrix multiplication and inverse fast Fourier transform are performed on the complex domain feature matrix to obtain the target frequency domain reconstructed feature matrix. Step S4: Flatten the target spatial domain high-order feature matrix and the target frequency domain reconstructed feature matrix respectively and concatenate them end to end to obtain the spatial-frequency fusion feature vector, and perform decision-level mapping calculation to obtain the corresponding mushroom maturity level result.
2. The mushroom maturity prediction method based on image recognition as described in claim 1, characterized in that, Step S1 specifically includes: Step S11: Acquire the original image of the mushroom and input the original image of the mushroom into the backbone feature extraction network to extract the basic spatial feature matrix; The backbone feature extraction network includes an initial convolutional layer, a hybrid attention layer, and a deformable convolutional layer; Step S12 involves performing position prediction and feature extraction processing on the basic spatial feature matrix to obtain the target spatial high-order feature matrix. The processing logic is as follows: Boundary box regression is performed on the basic spatial feature matrix to obtain the target bounding box, and the region of interest in the image is determined based on the mapping correspondence between the target bounding box and the original mushroom image. Based on the spatial coordinates of the region of interest in the image, the corresponding region is extracted from the basic spatial feature matrix to obtain the target spatial high-order feature matrix.
3. The mushroom maturity prediction method based on image recognition as described in claim 2, characterized in that, The processing logic for extracting the basic spatial feature matrix is as follows: In the initial convolutional layer, the original mushroom image is subjected to initial convolutional mapping operation to obtain a high-dimensional spatial mapping matrix; In the hybrid attention layer, the high-dimensional spatial mapping matrix is processed by global average pooling and linear mapping matrix multiplication through a hybrid spatial channel attention mechanism to obtain channel attention weights. At the same time, max pooling and average pooling are concatenated along the spatial dimension corresponding to the high-dimensional spatial mapping matrix to obtain spatial attention weights. The channel attention weights and spatial attention weights are calibrated by multiplying element-wise with the corresponding spatial dimension high-dimensional spatial mapping matrix to obtain the weighted calibrated high-dimensional spatial mapping matrix. In the deformable convolutional layer, a preset sampling convolutional kernel is introduced. The weighted and calibrated high-dimensional spatial mapping matrix is subjected to deformable convolutional sampling operation. The two-dimensional spatial offset of the preset sampling convolutional kernel in the horizontal and vertical directions is calculated based on the spatial position corresponding to the weighted and calibrated high-dimensional spatial mapping matrix. Based on the two-dimensional spatial offset, bilinear interpolation sampling is performed on the irregular grid sampling points to obtain the basic spatial feature matrix.
4. The mushroom maturity prediction method based on image recognition as described in claim 3, characterized in that, The processing logic for the target bounding box is as follows: The initial prediction box is obtained by mapping the basic spatial feature matrix using preset regression parameters; The spatial intersection-union ratio error between the initial predicted bounding box and the ground truth bounding box is used as the regression constraint for the target bounding box. The regression mapping of the basic spatial feature matrix is calculated using preset regression parameters to obtain the corresponding target bounding box.
5. The mushroom maturity prediction method based on image recognition as described in claim 4, characterized in that, Step S2 specifically includes: Step S21: Take the target spatial domain high-order feature matrix as input and perform a fast Fourier transform on it to transform the target spatial domain high-order feature matrix from spatial domain independent variables to frequency domain independent variables, generate a complex form matrix, and convert it to obtain a complex domain feature matrix. Step S22: Perform Hilbert transform on the complex domain feature matrix, calculate the complex orthogonal conjugate terms of the complex domain feature matrix, and linearly combine the complex domain feature matrix with the complex orthogonal conjugate terms to obtain the analytic signal feature matrix. Extract the instantaneous frequency and instantaneous phase of each frequency position in the analytic signal feature matrix.
6. The mushroom maturity prediction method based on image recognition as described in claim 5, characterized in that, The processing logic for step S22 is as follows: The real components of a one-dimensional frequency domain sequence are extracted along the horizontal row vector direction or the vertical column vector direction of the complex domain feature matrix. The real components of the one-dimensional frequency domain sequence are then transformed using a preset Hilbert transform operator to obtain the complex orthogonal conjugate terms of the corresponding complex domain feature matrix. By linearly combining and complexly recombining the complex domain feature matrix with complex orthogonal conjugate terms, the analytic signal feature matrix is obtained. Calculate the arctangent ratio of the imaginary part to the real part of each complex element in the feature matrix of the analytical signal to obtain the instantaneous phase matrix corresponding to each frequency position; The instantaneous phase matrix is calculated by first-order difference along the arrangement direction of the one-dimensional frequency domain sequence to obtain the instantaneous frequency matrix corresponding to each frequency position.
7. The mushroom maturity prediction method based on image recognition as described in claim 6, characterized in that, Step S3 specifically includes: Step S31: Cross-mapping the instantaneous phase matrix and the instantaneous frequency matrix through matrix multiplication to calculate the complex weighting coefficients of each frequency channel; Step S32: Multiply the complex weight coefficients of each frequency channel with the corresponding frequency channel in the complex domain feature matrix to obtain the frequency domain adaptive recalibration feature matrix. Step S33: Perform an inverse fast Fourier transform on the frequency domain adaptive recalibration feature matrix to obtain a complex matrix after the inverse transform, and extract the real part of the complex matrix after the inverse transform to obtain the target frequency domain reconstructed feature matrix.
8. The mushroom maturity prediction method based on image recognition as described in claim 7, characterized in that, The processing logic for cross mapping is as follows: The instantaneous phase matrix and instantaneous frequency matrix are used as inputs; The first preset weight matrix is used to perform a first matrix multiplication operation with the instantaneous phase matrix and the instantaneous frequency matrix respectively to obtain the first phase intermediate matrix and the first frequency intermediate matrix; The second preset weight matrix is used to perform a second matrix multiplication operation with the instantaneous phase matrix and the instantaneous frequency matrix respectively to obtain the second phase intermediate matrix and the second frequency intermediate matrix; Subtract the first phase intermediate matrix and the second frequency intermediate matrix to obtain the calibration real part matrix, and add the first frequency intermediate matrix and the second phase intermediate matrix to obtain the calibration imaginary part matrix. By combining the real part of the calibration matrix as the real part term and the imaginary part of the calibration matrix as the imaginary part term into complex vectors, the complex weighting coefficients of each frequency channel are obtained.
9. The mushroom maturity prediction method based on image recognition as described in claim 8, characterized in that, Step S4 specifically includes: Step S41: Flatten the target spatial domain high-order feature matrix and the target frequency domain reconstructed feature matrix respectively to obtain a one-dimensional spatial domain feature vector and a one-dimensional frequency domain feature vector. Step S42: The one-dimensional spatial domain feature vector and the one-dimensional frequency domain feature vector are concatenated and spliced together to obtain the spatial-frequency fused feature vector. Step S43: Perform decision-level mapping calculation on the space-frequency fusion feature vector to obtain the corresponding mushroom maturity level result; The mushroom maturity grading results include immature, mature, overripe, and pending re-inspection.
10. The mushroom maturity prediction method based on image recognition as described in claim 9, characterized in that, The processing logic for decision hierarchy mapping calculation is as follows: The spatial-frequency fusion feature vector is multiplied by the preset classification weight matrix, and then weighted and superimposed with the preset bias vector to obtain a linear feature vector. The probability distribution vector is obtained by performing a probability transformation on the linear eigenvector using a normalized exponential function. The probability distribution vector includes immature probability values, mature probability values, and overripe probability values; The maximum value is searched for the immature probability value, mature probability value and overmature probability value. The probability value with the largest value is determined as the target maximum value, and the preset maturity category corresponding to the target maximum value is determined as the candidate maturity category. The preset maturity categories include immature, mature, and overripe; The confidence level determination process for the target maximum value includes: When the target maximum value is greater than or equal to the preset confidence threshold, and the candidate maturity category is immature, the maturity classification result of immature mushrooms is obtained. When the target maximum value is greater than or equal to the preset confidence threshold, and the candidate maturity category is mature, the maturity classification result of mature mushrooms is obtained. When the target maximum value is greater than or equal to the preset confidence threshold, and the candidate maturity category is overripe, the maturity classification result of overripe mushrooms is obtained. When the maximum target value is less than the preset confidence threshold, the confidence of the current growth state is determined to be insufficient, and the mushroom maturity grading result to be re-examined is obtained.
Citation Information
Patent Citations
Grassland mushroom circle remote sensing identification method based on multispectral threshold screening and geometric constraint
CN122156965A