A method and system for detecting the porosity of food cut surfaces
By using deep convolutional neural network models and morphological processing techniques, the problems of strong subjectivity and serious misjudgment in the detection of pore structure in baked goods have been solved. This has enabled the quantification of multidimensional pore structure of food cross-sections and the automated determination of quality grades, thereby improving detection accuracy and stability.
Patent Information
- Application Number
- CN202611280307.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-22
- Publication Date
- 2026-11-17
AI Technical Summary
Existing technologies for detecting the pore structure of baked goods suffer from problems such as strong subjectivity, lack of unified quantitative standards, single detection dimensions, serious misjudgments, and lack of multi-dimensional quantitative capabilities. They are particularly difficult to achieve refined and standardized evaluation in complex food categories.
A deep convolutional neural network model is used for feature extraction and segmentation. By combining connected component attributes and morphological opening operations, and through binarization and threshold screening, the total porosity, average equivalent diameter and pore distribution uniformity of the food cross-section are obtained. Multidimensional index weighting is then performed to determine the food quality grade.
It achieves high-precision, multi-dimensional pore structure quantification of food cross-sections, improving detection accuracy and stability, ensuring that the results closely match the actual microstructure of food, and solving the shortcomings of single evaluation dimensions and incomplete quality characterization.
Smart Images

Figure CN123118501A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to a method and system for detecting the porosity of food cross-sections. Background Technology
[0002] For baked and fermented foods, such as bread, steamed buns, whole wheat products, and fruit-based fermented pastries, the internal pore structure is a core microscopic indicator that determines the product's texture, fluffiness, softness, flavor retention, and overall quality stability. Precise quantitative detection of pore structure has significant engineering application value for achieving standardized industrial production, quality control, and defect traceability in baked goods. Currently, the industry mainly uses three methods for detecting the pore structure of baked goods: human sensory evaluation, physical destructive testing, and traditional machine vision inspection. Human sensory evaluation relies on inspectors' visual observation of the cross-section's porosity and subjective scoring based on touch, which suffers from strong subjectivity, lack of unified quantitative standards, poor repeatability, and inability to achieve refined data recording, making it difficult to meet the precise quality inspection needs of modern industrial production. Physical destructive testing often uses methods such as water displacement and volume compression to determine overall porosity. These methods damage the sample structure, constituting destructive testing, and only obtain overall macroscopic pore parameters, failing to analyze microscopic characteristics such as pore size and distribution uniformity. This results in a single detection dimension and extremely low data information.
[0003] With the popularization of machine vision technology, image-based non-destructive pore detection has gradually become the mainstream alternative. However, in complex categories such as whole-wheat baked goods and compound fermented foods containing fruits, nuts, and grains, the food cross-section contains a large number of complex interfering textures such as grain particles, fruit fragments, bran textures, and fiber patterns. Their grayscale characteristics are highly similar to the dark areas of pores, leading to serious confusion and misjudgment problems in traditional threshold segmentation techniques, making it impossible to effectively distinguish between real pores and matrix impurities. At the same time, existing visual inspection technologies can only perform single porosity calculations, lacking multi-dimensional quantification capabilities for pore size distribution and spatial uniformity, and lacking standardized correction and intelligent grading systems, making it difficult to achieve refined and standardized evaluation of the internal structure of fermented baked goods. Summary of the Invention
[0004] In view of this, the present invention proposes a method and system for detecting the porosity of food cut surfaces.
[0005] The technical solution of the present invention is implemented as follows: The first aspect of the present invention provides a method for detecting the porosity of food cut surfaces, comprising: The initial cross-sectional image of the food to be tested is acquired and preprocessed to obtain the intermediate cross-sectional image; The intermediate cross-sectional image is subjected to feature extraction and feature segmentation using a pre-trained deep convolutional neural network model to obtain a probability distribution map that includes food matrix and pore classification. The probability distribution map is binarized and thresholded to obtain an initial segmentation mask map. The initial segmentation mask map is then corrected based on connected component properties and morphological opening operations to obtain the target segmentation mask map. Based on the ratio of the total number of pore pixels in the target segmentation mask to the total number of effective pixels corresponding to the food cross-section, the total porosity of the food cross-section is determined. For each independent pore connected region in the target segmentation mask, the actual physical area is converted by the pixel area to determine the average equivalent diameter of the pores in the food cross-section. The intermediate cross-section image is uniformly divided into multiple sub-grids, and the pore distribution uniformity is determined based on the porosity of each sub-grid. The total porosity, the average equivalent diameter, and the pore distribution uniformity are used as basic indicators for weighted processing to obtain a weighted score. The quality grade of the food to be tested is determined based on the weighted score.
[0006] Based on the above technical solutions, preferably, the step of acquiring the initial cross-sectional image of the food to be tested and performing preprocessing to obtain the intermediate cross-sectional image includes: The initial cross-sectional image is cropped using a polygonal bounding box selection algorithm to obtain a Region of Interest (ROI) image; The ROI image is scaled to a preset size to obtain a normalized image. The normalized image is divided into multiple local grids, and histogram equalization is performed independently on each local grid to obtain the intermediate cross-sectional image.
[0007] Based on the above technical solutions, preferably, the deep convolutional neural network model includes an encoder, a decoder, and skip connections; the step of using a pre-trained deep convolutional neural network model to extract and segment features from the intermediate cross-sectional image to obtain a probability distribution map containing food matrix and pore classification includes: The encoder is used to perform multi-layer convolution and pooling operations on the intermediate cross-section image, extracting shallow edge features and deep semantic features of the image step by step and compressing the image dimension to obtain encoder features; The decoder is used to perform deconvolution upsampling on the intermediate slice image to restore the image size and obtain the decoder features; The encoder features and the decoder features are fused by skip connections to obtain a dual-channel probability distribution map; the probability distribution map includes the probability value of each pixel being classified as food matrix and pores.
[0008] Based on the above technical solutions, preferably, the step of binarizing and thresholding the probability distribution map to obtain the initial segmentation mask map includes: If the probability value of a target pixel being classified as a food matrix is greater than the first threshold, the target pixel is classified as a food matrix pixel. If the probability value of a target pixel being classified as a food matrix is not greater than a first threshold, the target pixel is classified as a pore pixel; the target pixel is any pixel in the image pixels.
[0009] Based on the above technical solutions, preferably, the step of modifying the initial segmentation mask image based on connected component attributes and morphological opening operations to obtain the target segmentation mask image includes: Connectivity detection is performed on the initial segmentation mask to obtain the attribute information of each independent pore connected region. The independent pore connected regions are then filtered based on prior knowledge to determine the true pore region. A morphological opening operation is performed on the actual pore region to reduce pixel-level noise and obtain a target segmentation mask.
[0010] Based on the above technical solutions, preferably, the weighted processing of the total porosity, the average equivalent diameter, and the pore distribution uniformity as basic indicators to obtain a weighted score includes: The average equivalent diameter of the standard qualified sample is fitted using a Gaussian mixture model to obtain an equivalent diameter histogram. A standard probability density function is generated based on the equivalent diameter histogram, and an actual probability density function is generated based on the average equivalent diameter of the food to be tested. The probability distribution residual is determined based on the Wasserstein distance between the standard probability density function and the actual probability density function; The total porosity, the probability distribution residual, and the pore distribution uniformity are used as basic indicators for weighted processing to obtain a weighted score.
[0011] Based on the above technical solutions, preferably, before fitting the average equivalent diameter of the standard qualified sample using a Gaussian mixture model to obtain the equivalent diameter histogram, the method further includes: The original model is trained by forward and backward propagation using binary cross-entropy loss and Dice loss, resulting in a gradient-converged Gaussian mixture model.
[0012] More preferably, a second aspect of the present invention provides a food cut surface porosity detection system, comprising: a preprocessing module, an extraction and segmentation module, a sieving and correction module, an index determination module, and a weighted processing module; wherein, The preprocessing module is configured to acquire an initial cross-sectional image of the food to be tested and perform preprocessing to obtain an intermediate cross-sectional image; The extraction and segmentation module is configured to use a pre-trained deep convolutional neural network model to perform feature extraction and feature segmentation on the intermediate cross-section image to obtain a probability distribution map that includes food matrix and pore classification. The screening and correction module is configured to perform binarization and threshold screening on the probability distribution map to obtain an initial segmentation mask map, and to correct the initial segmentation mask map based on connected component attributes and morphological opening operations to obtain a target segmentation mask map. The index determination module is configured to determine the total porosity of the food cross-section based on the ratio of the total number of pore pixels in the target segmentation mask to the total number of effective pixels corresponding to the food cross-section; for each independent pore connected region in the target segmentation mask, the average equivalent diameter of the food cross-section pores is determined by converting the pixel area into the actual physical area; and the intermediate cross-section image is uniformly divided into multiple sub-grids, and the pore distribution uniformity is determined based on the porosity of each sub-grid. The weighted processing module is configured to perform weighted processing on the total porosity, the average equivalent diameter, and the pore distribution uniformity as basic indicators to obtain a weighted score, and determine the quality grade of the food to be tested based on the weighted score.
[0013] More preferably, a third aspect of the present invention provides an electronic device, including a processor and a memory; the memory has a computer program stored thereon, wherein the computer program, when executed by the processor, implements the food cut surface porosity detection method described in the first aspect.
[0014] More preferably, a fourth aspect of the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the food cut surface porosity detection method described in the first aspect.
[0015] The method and system for detecting the porosity of food cut surfaces according to the present invention have the following advantages over the prior art: 1. Standardized intermediate cross-sectional images are obtained by preprocessing the initial cross-sectional images of the food to be tested. Then, deep convolutional neural networks are used to extract deep features and perform semantic segmentation of the images, outputting a probability distribution map of the food matrix and pores. After binarization and thresholding, an initial segmentation mask map is obtained. Then, noise removal, edge smoothing, and pore correction are completed by combining connected component attribute filtering and morphological opening operations to obtain a high-precision target segmentation mask map. On this basis, three core microscopic physical indicators of the food cross-section, namely total porosity, average equivalent diameter of pores, and uniformity of pore distribution, are quantitatively calculated. Finally, a comprehensive score is generated by multi-indicator weighted fusion and the food quality grade is automatically determined. This significantly improves the accuracy of pore detection, avoids the defects of single indicators and one-sided quality evaluation, and realizes multi-dimensional and refined quantification of the pore structure of food.
[0016] 2. After the model outputs the probability distribution map, effective pore regions are initially screened through binarization and thresholding. Then, combined with the connected component attribute filtering mechanism, meaningless small noise connected components are removed based on the physical characteristics of the real pores. Combined with morphological opening operation, the pore edges are smoothed without changing the overall size and structural characteristics of the pores, resulting in a high-precision, low-noise target segmentation mask map. This suppresses image noise and model prediction errors, ensuring that the pore segmentation results closely match the real microstructure of food, and significantly improving the stability and reliability of the detection results.
[0017] 3. The total porosity of the cross-section is accurately calculated by the proportion of pore pixels, characterizing the overall looseness of the food; the average equivalent diameter of the pores is obtained by physical conversion of the pixel area of connected regions, quantifying the overall size of the pores; and the local porosity of each region is statistically analyzed by dividing the image into sub-grids to calculate the uniformity of pore distribution, characterizing the consistency of the pore spatial arrangement. These multi-dimensional indicators complement and corroborate each other, comprehensively restoring the microstructure of the pores inside the food, solving the shortcomings of single evaluation dimensions and incomplete quality characterization, and improving the reliability of the evaluation results. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a schematic flowchart of a method for detecting the porosity of a food section provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of the mask image correction process provided in an embodiment of the present invention; Figure 3This is a schematic diagram illustrating the principle of pore distribution uniformity calculation provided in an embodiment of the present invention; Figure 4 A hierarchical logic diagram based on residual analysis of standard distribution curves provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of a food section porosity detection system provided in an embodiment of the present invention; Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0020] The technical solutions of the present invention will be clearly and completely described below with reference to the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0021] In some embodiments, such as Figure 1 As shown, Figure 1 This is a flowchart illustrating a method for detecting the porosity of a food section according to an embodiment of the present invention; the method for detecting the porosity of a food section according to the present invention includes: S110: Acquire the initial cross-sectional image of the food to be tested and perform preprocessing to obtain the intermediate cross-sectional image.
[0022] S120 uses a pre-trained deep convolutional neural network model to extract and segment features from the intermediate cross-section image, obtaining a probability distribution map that includes food matrix and pore classification.
[0023] S130, the probability distribution map is binarized and thresholded to obtain the initial segmentation mask map, and the initial segmentation mask map is corrected based on the connected component properties and morphological opening operation to obtain the target segmentation mask map.
[0024] S140, based on the ratio of the total number of pore pixels in the target segmentation mask to the total number of effective pixels corresponding to the food cross-section, determine the total porosity of the food cross-section. For each independent pore connected region in the target segmentation mask, convert the actual physical area by the pixel area to determine the average equivalent diameter of the pores in the food cross-section. Then, uniformly divide the intermediate cross-section image into multiple sub-grids and determine the pore distribution uniformity based on the porosity of each sub-grid.
[0025] S150 uses total porosity, average equivalent diameter, and pore distribution uniformity as basic indicators for weighted processing to obtain a weighted score, and determines the quality grade of the food to be tested based on the weighted score.
[0026] In this embodiment, considering that the initial cross-sectional image of the food to be tested is easily affected by factors such as uneven ambient lighting, background interference, inconsistent image resolution, and low local contrast, resulting in blurred pore edges and masking of micropore features, while bran, fruit pieces, and texture noise also cause significant interference, image acquisition and standardization preprocessing are used to remove invalid background areas, unify image scale, enhance the feature differences between pores and matrix, suppress noise in the original image, and eliminate systematic errors caused by differences in acquisition conditions. This provides a standardized input image with high feature recognition for subsequent deep learning models. Based on a deep convolutional neural network encoder-decoder + skip connection architecture, the network automatically learns the shallow edge texture features and deep semantic features of the image, achieving pixel-level semantic discrimination of food matrix and pores. The network completes multi-scale feature extraction and semantic abstraction through the encoder, feature recovery and spatial localization through the decoder, and compensates for the loss of downsampling details through skip connections. Finally, it outputs the predicted probability of each pixel belonging to matrix and pores, forming a probability distribution map, achieving accurate feature segmentation under complex texture interference.
[0027] Furthermore, initial segmentation masks commonly suffer from defects such as isolated noise, pseudo-pores, edge burrs, and minor adhesions resulting from model predictions. By filtering through connected component properties, meaningless minor noise regions can be eliminated based on the physical size characteristics of the actual pores. Moreover, by employing morphological opening operations followed by erosion and then dilation, edges can be smoothed, minor burrs removed, and slightly adhered pores separated without altering the overall area and morphology of the pores. This allows for precise mask correction, resulting in a target segmentation mask that closely matches the actual tissue structure.
[0028] Building upon this foundation, a comprehensive quantitative assessment of pore structure is achieved using a precisely segmented target mask, encompassing overall proportion, individual particle size, and spatial distribution. The overall porosity is characterized by the pore pixel ratio (total porosity); the average equivalent diameter (equivalent to the area of connected components) represents the average pore size; and the dispersion of local porosity (uniformity of pore distribution) is statistically analyzed through grid partitioning, quantifying the spatial uniformity of pore distribution. This enables a quantifiable evaluation of the microstructure of food. Total porosity, average equivalent diameter, and pore distribution uniformity reflect food quality in terms of porosity, pore size, and distribution consistency, respectively. By assigning appropriate weights to these three fundamental indicators and integrating them, a comprehensive quantitative scoring system is constructed. This eliminates the problem of misjudgment based on a single indicator, transforming multidimensional pore structure characteristics into unified quantitative scores. Based on these score ranges, automated, standardized, and subjectively unbiased food quality grading is achieved.
[0029] In some embodiments, acquiring an initial cross-sectional image of the food to be tested and performing preprocessing to obtain an intermediate cross-sectional image includes: The initial cross-sectional image is cropped using a polygonal bounding box selection algorithm to obtain the ROI image; The ROI image is scaled to a preset size to obtain a normalized image. The normalized image is divided into multiple local grids, and histogram equalization is performed independently on each local grid to obtain the intermediate cross-sectional image.
[0030] In this embodiment, the effective region of the ROI is extracted from the initial cross-sectional image, and invalid regions such as the background and borders are cropped and removed. Then, the ROI image is normalized and scaled to be uniform to the fixed input size of the model. Then, local contrast enhancement is completed by limiting contrast adaptive histogram equalization, weakening the interference caused by uneven lighting, and enhancing the details of the pore edge. Finally, a middle cross-sectional image with clear texture, uniform scale, and significant features is obtained.
[0031] In some embodiments, the deep convolutional neural network model includes an encoder, a decoder, and skip connections; using a pre-trained deep convolutional neural network model to extract and segment features from the intermediate cross-sectional image, a probability distribution map containing food matrix and pore classification is obtained, including: The encoder performs multi-layer convolution and pooling operations on the intermediate cross-section image, extracts shallow edge features and deep semantic features of the image step by step, and compresses the image dimension to obtain encoder features; The decoder is used to perform deconvolution upsampling on the intermediate slice image to restore the image size and obtain the decoder features; By fusing encoder and decoder features through skip connections, a dual-channel probability distribution map is obtained; the probability distribution map includes the probability value of each pixel being classified as food matrix and pores.
[0032] In this embodiment, the preprocessed intermediate cross-sectional image is input into the trained deep convolutional neural network model, which automatically completes multi-layer convolutional feature extraction, multi-scale semantic fusion and pixel-level classification prediction, and outputs a dual-channel probability distribution map, which corresponds to the confidence probability of each pixel being food matrix and pores, respectively.
[0033] For example, the encoder module uses ResNet-34 as the backbone network, removes fully connected layers, and includes five feature extraction stages to extract multi-scale semantic features of the image. A Convolutional Attention Module (CBAM) is introduced at the skip connection between the encoder and decoder. The CBAM includes cascaded channel attention and spatial attention sub-modules to suppress background texture noise weights and enhance the weights of aperture edge features. The decoder module includes four upsampling stages, each using transposed convolution to enlarge the feature map size by a factor of two, and then concatenating it with the attention-weighted encoder feature map.
[0034] In some embodiments, the probability distribution map is binarized and thresholded to obtain an initial segmentation mask map, including: If the probability value of the target pixel being classified as a food matrix is greater than the first threshold, the target pixel is classified as a food matrix pixel. If the probability value of the target pixel being classified as a food matrix is not greater than the first threshold, the target pixel is classified as a pore pixel; the target pixel is any pixel in the image.
[0035] In this embodiment, a first threshold is set to binarize all pixels in the probability distribution map. Pixels with a probability greater than the first threshold are classified as food matrix, and pixels with a probability less than the first threshold are classified as pores, generating a black-and-white binary initial segmentation mask map. Here, the first threshold can be determined empirically.
[0036] In some embodiments, the initial segmentation mask image is modified based on connected component properties and morphological opening operations to obtain the target segmentation mask image, including: Connectivity detection is performed on the initial segmentation mask to obtain the attribute information of each independent pore connected region. Combined with prior knowledge, the independent pore connected regions are filtered to determine the real pore region. Morphological opening operations are performed on the real pore regions to reduce pixel-level noise and obtain the target segmentation mask.
[0037] In this embodiment, please refer to Figure 2 , Figure 2 This is a schematic diagram of the mask image correction process provided in an embodiment of the present invention. The initial segmented mask image is subjected to connected component detection, the area parameters of each pore connected component are statistically analyzed, a minimum area threshold is set to filter out connected components with excessively small noise, and then a morphological opening operation is performed on the remaining connected components using a 3×3 elliptical structuring element, i.e., erosion followed by dilation, to separate the adhered pores and smooth the edge burrs and pore contours, finally obtaining a target segmentation mask image with no false pores, low noise, and high precision.
[0038] In some embodiments, total porosity, average equivalent diameter, and pore distribution uniformity are used as basic indicators for weighted processing to obtain a weighted score, including: The average equivalent diameter of the standard qualified sample is fitted using a Gaussian mixture model to obtain an equivalent diameter histogram. A standard probability density function is generated based on the equivalent diameter histogram, and an actual probability density function is generated based on the average equivalent diameter of the food to be tested. Determine the probability distribution residuals based on the Wasserstein distance between the standard probability density function and the actual probability density function; The total porosity, probability distribution residual, and pore distribution uniformity were used as basic indicators for weighted processing to obtain a weighted score.
[0039] In an alternative embodiment, please refer to Figure 3 , Figure 3This is a schematic diagram illustrating the principle of pore distribution uniformity calculation provided in an embodiment of the present invention. The left image shows a diagram of dividing the cross-section into an 8×8 grid, and the right image shows the corresponding local porosity heatmap. The darker the color, the denser the pores in that area. The uniformity index is calculated based on the variance of this heatmap data. The total number of pore pixels in the target segmentation mask image is compared with the total number of pixels in the effective area of the cross-section, and the total porosity of the food cross-section is calculated by the ratio of the two. All independent pore connected domains are traversed, and according to the pixel physical size ratio calibrated by the camera, the area of each pore pixel is converted into the actual physical area. The equivalent circular diameter of a single pore is calculated and the average value is obtained to obtain the average equivalent diameter. The intermediate cross-section image is uniformly divided into several rows and columns of sub-grids, and the local porosity of each sub-grid is calculated. By statistically analyzing the standard deviation or coefficient of variation of the porosity of all sub-grids, the pore distribution uniformity index is obtained. The smaller the value, the more uniform the distribution.
[0040] Here, the uniformity of pore distribution can be expressed as: ; in, Let the standard deviation of the local porosity of all N×M subgrids be . U represents the average local porosity of all subgrids; the closer the U value is to 1, the more uniform the pore distribution.
[0041] In another alternative embodiment, please refer to Figure 4 , Figure 4 This invention provides a hierarchical logic diagram based on residual analysis of standard distribution curves. A mathematical model of pore diameter distribution based on standard qualified samples is constructed. The pore distribution data of the sample to be tested is compared with the model's residual to calculate the distribution distance loss. A Gaussian mixture model is used to fit the average equivalent diameter of the standard qualified samples to obtain an equivalent diameter histogram, which in turn generates a standard probability density function. The equivalent diameters of all pores in the corrected mask image of the sample to be tested are statistically analyzed to generate the actual probability density function. The Wasserstein distance between the two distributions, also known as the bulldozer distance EMD, is calculated as the distribution residual R.
[0042] ; Where CDF is the cumulative distribution function, std corresponds to the standard qualified sample, and act characterizes the sample to be tested.
[0043] The residual R, total porosity P, and pore distribution uniformity U are used as basic indicators for weighted processing to obtain a weighted score. A pre-established standard interval for the corresponding score and quality grade is used. Based on whether the final weighted score of the sample falls within the interval, the system automatically determines whether the food is excellent, qualified, or unqualified, thus completing an intelligent quantitative assessment of food quality.
[0044] In some embodiments, before fitting the average equivalent diameter of the standard qualified sample using a Gaussian mixture model to obtain an equivalent diameter histogram, the method further includes: The original model is trained by forward and backward propagation using binary cross-entropy loss and Dice loss, resulting in a gradient-converged Gaussian mixture model.
[0045] In this embodiment, the training loss function of the Gaussian mixture model Weighted binary cross-entropy loss and Dice loss composition: ; in, This is a balance coefficient with a value range of [0.3, 0.7], used to address the sample imbalance problem where the number of aperture pixels accounts for a small proportion of the image.
[0046] Binary cross-entropy (BCE) is responsible for supervising classification confidence pixel by pixel, constraining the predicted probability of each pixel belonging to either the food matrix or pores to approximate the true label. Dice loss addresses the imbalance in the proportion of pore regions in segmentation tasks by directly optimizing the intersection and overlap between the predicted mask and the ground truth mask, mitigating the imbalance of positive and negative samples caused by the small proportion of pore pixels in food slices being easily ignored by the model. The two loss mechanisms together constitute a composite loss, balancing pixel-level classification accuracy with region segmentation completeness. The labeled food slice samples are input into a deep segmentation network for forward propagation, calculating the combined loss of the predicted probability distribution map and the ground truth mask. The network weights are iteratively updated through backpropagation gradient backpropagation, continuously training until the gradient stabilizes and converges, resulting in a gradient-converged Gaussian mixture model.
[0047] In some embodiments, please refer to Figure 5 , Figure 5 This is a schematic diagram of a food section porosity detection system provided in an embodiment of the present invention. The present invention provides a food section porosity detection system 500, comprising: a preprocessing module 510, an extraction and segmentation module 520, a sieving correction module 530, an index determination module 540, and a weighted processing module 550; wherein,
[0048] The preprocessing module 510 is configured to acquire an initial cross-sectional image of the food to be tested and perform preprocessing to obtain an intermediate cross-sectional image; The extraction and segmentation module 520 is configured to use a pre-trained deep convolutional neural network model to extract and segment features from the intermediate cross-section image, and obtain a probability distribution map containing food matrix and pore classification. The screening and correction module 530 is configured to perform binarization and threshold screening on the probability distribution map to obtain an initial segmentation mask map, and to correct the initial segmentation mask map based on the connected component attributes and morphological opening operation to obtain the target segmentation mask map. The index determination module 540 is configured to determine the total porosity of the food cross-section based on the ratio of the total number of pore pixels in the target segmentation mask to the total number of effective pixels corresponding to the food cross-section. For each independent pore connected region in the target segmentation mask, the actual physical area is converted by the pixel area to determine the average equivalent diameter of the pores in the food cross-section. The intermediate cross-section image is uniformly divided into multiple sub-grids, and the pore distribution uniformity is determined based on the porosity of each sub-grid. The weighted processing module 550 is configured to perform weighted processing based on total porosity, average equivalent diameter and pore distribution uniformity to obtain a weighted score, and determine the quality grade of the food to be tested based on the weighted score.
[0049] In some embodiments, the preprocessing module 510 is specifically configured as follows: The initial cross-sectional image is cropped using a polygonal bounding box selection algorithm to obtain the ROI image; The ROI image is scaled to a preset size to obtain a normalized image. The normalized image is divided into multiple local grids, and histogram equalization is performed independently on each local grid to obtain the intermediate cross-sectional image.
[0050] In some embodiments, the deep convolutional neural network model includes an encoder, a decoder, and skip connections; the extraction and segmentation module 520 is specifically configured as follows: The encoder performs multi-layer convolution and pooling operations on the intermediate cross-section image, extracts shallow edge features and deep semantic features of the image step by step, and compresses the image dimension to obtain encoder features; The decoder is used to perform deconvolution upsampling on the intermediate slice image to restore the image size and obtain the decoder features; By fusing encoder and decoder features through skip connections, a dual-channel probability distribution map is obtained; the probability distribution map includes the probability value of each pixel being classified as food matrix and pores.
[0051] In some embodiments, the screening correction module 530 is specifically configured as follows: If the probability value of the target pixel being classified as a food matrix is greater than the first threshold, the target pixel is classified as a food matrix pixel. If the probability value of the target pixel being classified as a food matrix is not greater than the first threshold, the target pixel is classified as a pore pixel; the target pixel is any pixel in the image.
[0052] In some embodiments, the screening correction module 530 is specifically configured as follows: Connectivity detection is performed on the initial segmentation mask to obtain the attribute information of each independent pore connected region. Combined with prior knowledge, the independent pore connected regions are filtered to determine the real pore region. Morphological opening operations are performed on the real pore regions to reduce pixel-level noise and obtain the target segmentation mask.
[0053] In some embodiments, the weighting processing module 550 is specifically configured as follows: The average equivalent diameter of the standard qualified sample is fitted using a Gaussian mixture model to obtain an equivalent diameter histogram. A standard probability density function is generated based on the equivalent diameter histogram, and an actual probability density function is generated based on the average equivalent diameter of the food to be tested. Determine the probability distribution residuals based on the Wasserstein distance between the standard probability density function and the actual probability density function; The total porosity, probability distribution residual, and pore distribution uniformity were used as basic indicators for weighted processing to obtain a weighted score.
[0054] In some embodiments, the food cut surface porosity detection system further includes a training module; the training module is specifically configured as follows: The original model is trained by forward and backward propagation using binary cross-entropy loss and Dice loss, resulting in a gradient-converged Gaussian mixture model.
[0055] It should be noted that the food cut surface porosity detection system provided in this application embodiment and the food cut surface porosity detection method provided in this application embodiment are based on the same application concept. Therefore, the specific implementation of this embodiment can refer to the implementation of the aforementioned food cut surface porosity detection method, and the repeated parts will not be described again.
[0056] In some embodiments, please refer to Figure 6 , Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device 600 provided in this application includes a processor 610 and a memory 620; the memory 620 stores a computer program, wherein the computer program, when executed by the processor, implements the aforementioned method for detecting the porosity of food cut surfaces.
[0057] Specifically, processor 610 may include, for example, a general-purpose microprocessor, an instruction set processor and / or an associated chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. Processor 610 may also include onboard memory for caching purposes. Processor 610 may be a single processing unit or multiple processing units for performing different actions of the method flow according to embodiments of this application.
[0058] Memory 620 may be any medium capable of containing, storing, transmitting, propagating, or transmitting instructions. For example, memory 620 may include, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, instruments, or propagation media. Specific examples of memory 620 include: magnetic storage devices such as magnetic tape or hard disk drives (HDDs); optical storage devices such as optical discs (CD-ROMs); and may also be random access memory (RAM) or flash memory; and / or wired / wireless communication links.
[0059] This application also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the above-described method for detecting the porosity of food cut surfaces. This computer-readable medium may be included in the device / apparatus / system described in the above embodiments; or it may exist independently and not assembled into that device / apparatus / system. The aforementioned computer-readable medium carries one or more programs, which, when executed, implement the method according to the embodiments of this application.
[0060] According to embodiments of this application, a computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wired, optical fiber, radio frequency signals, etc., or any suitable combination thereof.
[0061] Those skilled in the art will understand that the features described in the various embodiments and / or claims of this application can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in this application. All such combinations and / or combinations fall within the scope of this application. Therefore, the scope of this application should not be limited to the above embodiments, but should be defined not only by the appended claims, but also by the equivalents of the appended claims. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this invention should be included within the protection scope of this invention.
Claims
1. A method for detecting the porosity of food cross-sections, characterized in that, include: The initial cross-sectional image of the food to be tested is acquired and preprocessed to obtain the intermediate cross-sectional image; The intermediate cross-sectional image is subjected to feature extraction and feature segmentation using a pre-trained deep convolutional neural network model to obtain a probability distribution map that includes food matrix and pore classification. The probability distribution map is binarized and thresholded to obtain an initial segmentation mask map. The initial segmentation mask map is then corrected based on connected component properties and morphological opening operations to obtain the target segmentation mask map. Based on the ratio of the total number of pore pixels in the target segmentation mask to the total number of effective pixels corresponding to the food cross-section, the total porosity of the food cross-section is determined. For each independent pore connected region in the target segmentation mask, the actual physical area is converted by the pixel area to determine the average equivalent diameter of the pores in the food cross-section. The intermediate cross-section image is uniformly divided into multiple sub-grids, and the pore distribution uniformity is determined based on the porosity of each sub-grid. The total porosity, the average equivalent diameter, and the pore distribution uniformity are used as basic indicators for weighted processing to obtain a weighted score. The quality grade of the food to be tested is determined based on the weighted score.
2. The method for detecting the porosity of food cut surfaces as described in claim 1, characterized in that, The process of acquiring an initial cross-sectional image of the food to be tested and performing preprocessing to obtain an intermediate cross-sectional image includes: The initial cross-sectional image is cropped using a polygonal bounding box selection algorithm to obtain a Region of Interest (ROI) image; The ROI image is scaled to a preset size to obtain a normalized image. The normalized image is divided into multiple local grids, and histogram equalization is performed independently on each local grid to obtain the intermediate cross-sectional image.
3. The method for detecting the porosity of food cut surfaces as described in claim 1, characterized in that, The deep convolutional neural network model includes an encoder, a decoder, and skip connections; the step of using the pre-trained deep convolutional neural network model to extract and segment features from the intermediate cross-sectional image to obtain a probability distribution map containing food matrix and pore classification includes: The encoder is used to perform multi-layer convolution and pooling operations on the intermediate cross-section image, extracting shallow edge features and deep semantic features of the image step by step and compressing the image dimension to obtain encoder features; The decoder is used to perform deconvolution upsampling on the intermediate slice image to restore the image size and obtain the decoder features; The encoder features and the decoder features are fused by skip connections to obtain a dual-channel probability distribution map; the probability distribution map includes the probability value of each pixel being classified as food matrix and pores.
4. The method for detecting the porosity of food cut surfaces as described in claim 3, characterized in that, The binarization and thresholding of the probability distribution map to obtain the initial segmentation mask map includes: If the probability value of a target pixel being classified as a food matrix is greater than the first threshold, the target pixel is classified as a food matrix pixel. If the probability value of a target pixel being classified as a food matrix is not greater than a first threshold, the target pixel is classified as a pore pixel; the target pixel is any pixel in the image pixels.
5. The method for detecting the porosity of food cut surfaces as described in claim 1, characterized in that, The step of modifying the initial segmentation mask image based on connected component properties and morphological opening operations to obtain the target segmentation mask image includes: Connectivity detection is performed on the initial segmentation mask to obtain the attribute information of each independent pore connected region. The independent pore connected regions are then filtered based on prior knowledge to determine the true pore region. A morphological opening operation is performed on the actual pore region to reduce pixel-level noise and obtain a target segmentation mask.
6. The method for detecting the porosity of food cut surfaces as described in claim 1, characterized in that, The weighted score is obtained by weighting the total porosity, the average equivalent diameter, and the pore distribution uniformity as basic indicators, including: The average equivalent diameter of the standard qualified sample is fitted using a Gaussian mixture model to obtain an equivalent diameter histogram. A standard probability density function is generated based on the equivalent diameter histogram, and an actual probability density function is generated based on the average equivalent diameter of the food to be tested. The probability distribution residual is determined based on the Wasserstein distance between the standard probability density function and the actual probability density function; The total porosity, the probability distribution residual, and the pore distribution uniformity are used as basic indicators for weighted processing to obtain a weighted score.
7. The method for detecting the porosity of food cut surfaces as described in claim 6, characterized in that, Before fitting the average equivalent diameter of the standard qualified sample using a Gaussian mixture model to obtain the equivalent diameter histogram, the method further includes: The original model is trained by forward and backward propagation using binary cross-entropy loss and Dice loss, resulting in a gradient-converged Gaussian mixture model.
8. A system for detecting the porosity of food cut surfaces, characterized in that, include: The module includes a preprocessing module, an extraction and segmentation module, a screening and correction module, an index determination module, and a weighted processing module; among which, The preprocessing module is configured to acquire an initial cross-sectional image of the food to be tested and perform preprocessing to obtain an intermediate cross-sectional image; The extraction and segmentation module is configured to use a pre-trained deep convolutional neural network model to perform feature extraction and feature segmentation on the intermediate cross-section image to obtain a probability distribution map that includes food matrix and pore classification. The screening and correction module is configured to perform binarization and threshold screening on the probability distribution map to obtain an initial segmentation mask map, and to correct the initial segmentation mask map based on connected component attributes and morphological opening operations to obtain a target segmentation mask map. The index determination module is configured to determine the total porosity of the food cross-section based on the ratio of the total number of pore pixels in the target segmentation mask to the total number of effective pixels corresponding to the food cross-section; for each independent pore connected region in the target segmentation mask, the average equivalent diameter of the food cross-section pores is determined by converting the pixel area into the actual physical area; and the intermediate cross-section image is uniformly divided into multiple sub-grids, and the pore distribution uniformity is determined based on the porosity of each sub-grid. The weighted processing module is configured to perform weighted processing on the total porosity, the average equivalent diameter, and the pore distribution uniformity as basic indicators to obtain a weighted score, and determine the quality grade of the food to be tested based on the weighted score.
9. An electronic device, characterized in that, It includes a processor and a memory; the memory stores a computer program, wherein the computer program, when executed by the processor, implements the food cut surface porosity detection method according to any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium, characterized in that, It stores a computer program, wherein the computer program, when executed by a processor, implements the food cut surface porosity detection method as described in any one of claims 1 to 7.
