A meat quality evaluation method and system
By dividing meat images into non-overlapping areas and calculating relevant features in parallel, the problems of single scale and large computational complexity in traditional methods are solved, and accurate evaluation of meat freshness and improved computational efficiency are achieved.
Patent Information
- Application Number
- CN202411740381.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2044-11-29
AI Technical Summary
Existing technologies in meat quality evaluation have problems of single scale and high computational complexity. Traditional methods divide images into blocks and directly extract features before inputting them into the transformer network, which makes it impossible to discover meat quality features in a fine-grained manner and requires high computational complexity.
Texture density features are used to partition the meat quality, and the routing index matrix is used to filter the relevant areas of non-overlapping areas. Multiple parallel transformer networks are used to calculate the relevant features, reducing the amount of calculation and improving the accuracy.
It achieves accurate judgment of meat freshness, reduces the amount of calculation, and improves the accuracy and efficiency of meat quality evaluation.
Smart Images

Figure CN119516537B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image machine vision processing, and in particular relates to a meat quality evaluation method and system. Background Art
[0002] When buying fresh meat, the color often determines whether people will buy it. After slaughtering a pig, the color of the meat changes from dark red to bright red to brown over time. This is because the surface color of the meat is primarily determined by the content of myoglobin. After prolonged exposure to air, myoglobin is strongly oxidized to oxymyoglobin (when the oxidation level exceeds 50%, the meat appears brown), resulting in a dark brown color. Therefore, using computer vision to obtain color feature parameters from raw meat images is of great significance for predicting meat freshness.
[0003] Marbling in fresh meat refers to the content and distribution of intramuscular fat. Moderate marbling makes meat tender, fresh, and easy to chew. Excessive or excessive marbling makes meat appear tough, difficult to chew, and lacks flavor. Therefore, marbling content and distribution are crucial indicators of meat quality and play a decisive role in meat quality assessment. Therefore, using multimodal learning techniques to extract and analyze pork texture information and evaluate meat appearance has significant economic and social benefits.
[0004] With the rapid development of image processing technology, image segmentation and texture analysis have become cutting-edge technologies in research and application across numerous fields. The core of these technologies lies in extracting valuable information from complex image data and conducting in-depth analysis and interpretation of this information. Image segmentation, a key step in image processing, effectively separates objects from their background within an image, providing a clear and accurate foundation for further image analysis. This technology has important applications in a variety of fields, including medical imaging, remote sensing image processing, and machine vision. Texture analysis technology goes a step further, encompassing the assessment of texture across multiple dimensions, including direction, intensity, and regularity. Advanced applications of texture analysis can reveal complex patterns and structures in images that are difficult to detect with the naked eye, providing critical information for object recognition, classification, and condition monitoring, demonstrating enormous potential.
[0005] When using transformer networks for image segmentation and feature extraction, the traditional method is to input all features into the transformer for calculation. This method has two drawbacks:
[0006] 1) Single scale: Traditional methods divide the image into blocks, directly extract features from each block, and feed them into the transformer structure. All image blocks have a single scale, which cannot explore meat quality features in a fine-grained manner, making it difficult to evaluate meat quality.
[0007] 2) The amount of computation is large; the amount of computation of the transformer is determined by the number of blocks in the image. Summary of the Invention
[0008] To overcome the shortcomings of the above-mentioned prior art, the present invention provides a meat quality evaluation method and system, which uses texture density features to partition meat quality, divides each meat quality area into non-overlapping areas, and uses a routing index matrix to filter related areas of non-overlapping areas and then calculate related features. This can significantly reduce the computational complexity of the transfromer network, improve the accuracy of meat freshness judgment, and achieve simultaneous optimization of accuracy and computational complexity.
[0009] To achieve the above objectives, one or more embodiments of the present invention provide the following technical solutions:
[0010] A first aspect of the present invention provides a method for evaluating meat quality.
[0011] A method for evaluating meat quality, comprising:
[0012] Get fresh meat images;
[0013] The texture density matrix of the fresh meat image is calculated based on the texture histogram method, and the image is segmented into various meat quality areas using a hierarchical segmentation method.
[0014] Divide each meat quality area into multiple non-overlapping areas and determine the input features of each non-overlapping area;
[0015] The input features of non-overlapping regions corresponding to various meat quality regions are input into multiple parallel transformer networks of the meat quality detection model according to the differences in meat quality regions. An adjacency relationship matrix is established between the input features of non-overlapping regions within each meat quality region. Based on the adjacency relationship matrix, the other regions that are most correlated with each non-overlapping region are determined.
[0016] The multi-head attention mechanism of the transformer network is used to calculate the relevant features within each non-overlapping region and the relevant features of the non-overlapping region and its most relevant regions;
[0017] The freshness and quality of fresh meat are evaluated based on the relevant features obtained from multiple parallel transfromer networks.
[0018] A second aspect of the present invention provides a meat quality evaluation system.
[0019] A meat quality evaluation system comprising:
[0020] The image acquisition module is configured to: acquire an image of fresh meat;
[0021] The image segmentation module is configured to: calculate the texture density matrix of the fresh meat image based on the texture histogram method, and segment the image into multiple meat quality areas according to a hierarchical segmentation method;
[0022] The feature acquisition module is configured to: divide each meat quality region into a plurality of non-overlapping regions and determine an input feature of each non-overlapping region;
[0023] The similarity calculation module is configured to: input the input features of non-overlapping regions corresponding to the various meat quality regions into multiple parallel transformer networks of the meat quality detection model according to the differences in the meat quality regions, establish an adjacency relationship matrix between the input features of the non-overlapping regions within each meat quality region, and determine the other regions that are most correlated with each non-overlapping region based on the adjacency relationship matrix;
[0024] The attention mechanism module is configured to use the multi-head attention mechanism of the transformer network to calculate the relevant features within each non-overlapping region and the relevant features of the non-overlapping region and its most relevant regions;
[0025] The classification module is configured to evaluate the freshness and quality of fresh meat based on the relevant features obtained by multiple parallel transfromer networks.
[0026] A third aspect of the present invention provides a computer-readable storage medium having a program stored thereon, which, when executed by a processor, implements the steps of the meat quality evaluation method as described in the first aspect of the present invention.
[0027] The fourth aspect of the present invention provides an electronic device comprising a memory, a processor and a program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the meat quality evaluation method as described in the first aspect of the present invention are implemented.
[0028] One or more of the above technical solutions have the following beneficial effects:
[0029] (1) The present invention establishes a transfromer network for different meat quality areas to realize meat quality detection in different meat quality areas. Because the color performance is different under different texture and meat quality conditions, this method can identify the freshness of meat in a finer granularity and more accurately.
[0030] (2) The present invention first divides the meat quality into zones using texture density features, and then divides each meat quality zone into non-overlapping areas. When extracting features, the routing index matrix is used to filter the relevant areas of the non-overlapping areas and then calculate the relevant features. This can significantly reduce the computational complexity of the transfromer network, improve the accuracy of meat freshness determination, and achieve simultaneous optimization of accuracy and computational complexity.
[0031] (3) The present invention proposes a fast meat segmentation method based on texture density feature representation, which divides the meat into different areas according to the texture density feature. The texture of different areas is different, and the size of the image blocks is also different.
[0032] Advantages of additional aspects of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] The accompanying drawings, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0034] Figure 1 This is a flow chart of a meat quality evaluation method according to the first embodiment.
[0035] Figure 2 This is a schematic diagram of the grid division of the fresh meat image in the first embodiment.
[0036] Figure 3 This is a schematic diagram of the window expansion result of the first embodiment.
[0037] Figure 4 This is a schematic diagram of non-overlapping area division in the first embodiment.
[0038] Figure 5 This is a schematic diagram of the transfromer network structure of the first embodiment.
[0039] Figure 6 This is a schematic diagram of the meat quality detection model structure of the first embodiment.
[0040] Figure 7 (a), (b), and (c) are schematic diagrams of meat quality evaluation results of different grades in the first embodiment. DETAILED DESCRIPTION
[0041] Example 1
[0042] This embodiment discloses a method for evaluating meat quality.
[0043] A method for evaluating meat quality, comprising:
[0044] Get fresh meat images;
[0045] The texture density matrix of the fresh meat image is calculated based on the texture histogram method, and the image is segmented into various meat quality areas using a hierarchical segmentation method.
[0046] Divide each meat quality area into multiple non-overlapping areas and determine the input features of each non-overlapping area;
[0047] The input features of non-overlapping regions corresponding to various meat quality regions are input into multiple parallel transformer networks of the meat quality detection model according to the differences in meat quality regions. An adjacency relationship matrix is established between the input features of non-overlapping regions within each meat quality region. Based on the adjacency relationship matrix, the other regions that are most correlated with each non-overlapping region are determined.
[0048] The multi-head attention mechanism of the transformer network is used to calculate the relevant features within each non-overlapping region and the relevant features of the non-overlapping region and its most relevant regions;
[0049] The freshness and quality of fresh meat are evaluated based on the relevant features obtained from multiple parallel transfromer networks.
[0050] In some embodiments, calculating the texture density matrix of the fresh meat image based on the texture histogram method includes:
[0051] After converting the acquired fresh meat image into a grayscale image and normalizing it, the image is gridded to obtain multiple squares;
[0052] Adjust the grayscale of the image, use the adjusted grayscale as the number of rows and columns, and construct a texture density matrix with an initial value of 0;
[0053] Set the distance and direction. For each square in the image, find the neighboring squares at the given distance and direction. Use the grayscale of the current square as the row number and the grayscale of its neighboring square as the column number, and add 1 to the corresponding row and column numbers in the texture density matrix.
[0054] When approaching the edge of the image, if the current square has no neighboring squares according to the selected distance and direction, the current square is skipped; each square in the image is traversed until all squares in the image are processed, and the texture density matrix in the current direction is obtained and normalized;
[0055] Set different distances and directions, repeat the above steps, obtain the texture density matrices in different directions and perform normalization processing respectively;
[0056] The texture density matrix table of the image is calculated based on multiple texture density matrices obtained from different directions.
[0057] In some embodiments, the image is segmented into multiple fleshy areas according to a hierarchical segmentation method, including:
[0058] Step 1: Set the initial window of the image, perform probability analysis on the texture density matrix of the squares within the initial window, and obtain the meat texture degree T and texture variance V of the current initial window;
[0059] Step 2: If the meat texture T of the current initial window is lower than the set variance threshold M, the current initial window is further segmented. The main gradient direction of the pixels in the initial window is extracted using a gradient filter. The main texture direction is determined based on the main gradient direction, and the next segmentation direction is determined based on the perpendicular direction to the main texture direction.
[0060] Step 3: If the texture variance V is less than the meat texture T, shrink the window along the main direction of the texture to create multiple new regions.
[0061] Step 4: Perform a probability analysis of the texture density matrix for each newly divided area. Use the newly divided area as the initial window and repeat steps 1 to 3 until the entire image is traversed. When the number of pixels in the newly divided area falls below the set pixel threshold G, no further segmentation is performed and the traversal ends, obtaining the meat texture degree of all squares in the image.
[0062] Step 5: Divide the meat area by counting the meat texture of all squares in the image.
[0063] In some embodiments, in step 3, if the texture variance V is less than the meat texture degree T, the window is shrunk along the main direction of the texture to newly divide multiple regions, specifically including:
[0064] Determine whether the texture direction in the initial window is obvious based on the main gradient direction:
[0065] If the texture direction in the initial window is obvious, the initial window is further subdivided along the main gradient direction. The main gradient direction includes horizontal, vertical or diagonal directions. The corresponding newly divided regions are horizontal strip regions, vertical strip regions and diamond regions.
[0066] If the texture direction in the initial window is not obvious, uniform refinement segmentation is used to evenly divide the initial window into multiple small square grids, and the newly divided regions are multiple small square grids;
[0067] In this embodiment, whether the texture direction in the initial window is obvious is determined based on the main gradient direction. The main gradient direction can be preset with a threshold value, and the magnitude between the main gradient direction and the preset threshold value can be determined to determine whether the texture direction in the initial window is obvious.
[0068] or,
[0069] In the step 5, the meat texture of all squares in the image is counted to divide the meat area, which specifically includes:
[0070] First, based on the set meat texture threshold, the meat quality area to which each square belongs is determined. The meat quality areas include high-quality meat area, medium-quality meat area and low-quality meat area.
[0071] The meat quality is graded based on the proportion of the face value of the high-quality meat area, the medium-quality meat area and the low-quality meat area.
[0072] In some embodiments, determining the input features of each non-overlapping region specifically includes:
[0073] Calculate the color histogram of the non-overlapping area, and calculate the color mean, median and mode of the non-overlapping area based on the color histogram to construct the color feature vector;
[0074] Perform probabilistic analysis on the texture density matrix of non-overlapping areas, calculate contrast, energy, entropy, homogeneity, correlation and difference parameters, and construct texture density feature vectors;
[0075] Construct input features for each non-overlapping region based on the color feature vector and the texture density feature vector;
[0076] or,
[0077] Establish an adjacency relationship matrix between the input features of non-overlapping regions within each meaty region. Based on the adjacency relationship matrix, determine the other regions that are most relevant to each non-overlapping region, including:
[0078] Calculate the query vector and key vector of the non-overlapping area according to the color feature vector and texture density feature vector of the non-overlapping area;
[0079] Use matrix multiplication between the query vector and the key vector to calculate the similarity between different non-overlapping regions and generate the adjacency relationship matrix of each non-overlapping region;
[0080] Based on the adjacency matrix, the top h other regions that are most relevant to each non-overlapping region are clipped to create a routing index matrix.
[0081] In some embodiments, the multi-head attention mechanism of the transformer network is used to calculate the relevant features within each non-overlapping region and the non-overlapping region and its most relevant regions, specifically including:
[0082] Based on the routing index matrix, the top h other regions that are most relevant to the current non-overlapping region are queried through the multi-head attention mechanism;
[0083] First, calculate the transformer attention of the features in the grid divided by the current non-overlapping area and its own area to obtain the first attention;
[0084] Then calculate the transformer attention of the features in the grid divided by the current non-overlapping area and the first h other areas in the routing index matrix to obtain the second attention;
[0085] Based on the first attention and the second attention, relevant features are obtained.
[0086] In this embodiment, the relevant features are obtained based on the first attention and the second attention, specifically:
[0087] By inputting the first attention and the second attention (i.e. the output of the multi-head attention mechanism) into the ADD Normalization (normalization layer), Feed Forward (feedforward network layer), and ADD Normalization (normalization layer) of the transformer network, multiple related features can be obtained.
[0088] In some embodiments, the freshness and quality of fresh meat are evaluated based on the relevant features obtained by multiple parallel transfromer networks, specifically including:
[0089] The multiple related features obtained by each transfromer network are fused by feature concatenation or addition to obtain the output of each transfromer network;
[0090] The outputs of multiple transfromer networks are weightedly fused to obtain feature outputs of different meat quality areas;
[0091] Based on the feature output of different meat quality areas, the classification results of meat freshness and the comprehensive classification results of meat quality are obtained.
[0092] The following will explain the technical solution of this embodiment in detail with reference to the accompanying drawings. The technical solution of this embodiment may specifically include:
[0093] Step 1: Obtain fresh meat images;
[0094] Step 2: Calculate the texture density matrix of the fresh meat image based on the texture histogram method, and segment the image into various meat quality areas according to the texture density matrix;
[0095] Step 3: Construct a meat quality detection model, which includes multiple parallel transfromer networks, weighted fusion layers, and fully connected layers. The segmented meat areas are input into different transfromer networks for fine-grained feature extraction. The features extracted by the multiple parallel transfromer networks are sequentially passed through the weighted fusion layer and the fully connected layer to obtain the meat quality evaluation results.
[0096] Fresh meat texture affects its quality. Therefore, this paper extracts texture features from the pork surface and uses them to perform a preliminary analysis and grading of fresh meat quality. Meat quality assessment involves evaluating the quality of each piece of meat. Some parts are high-quality, while others are low-quality. Therefore, to comprehensively assess the quality of each piece of meat, this paper proposes a rapid meat quality segmentation and assessment method based on texture density feature representation, specifically including:
[0097] Step 201: extracting a texture density matrix of the fresh meat image based on a texture histogram method, including:
[0098] Step 211: Convert the acquired fresh meat image into a grayscale image, normalize the grayscale image, and then divide the image into grids, as shown in the following example: Figure 2 As shown, the image is divided into multiple squares.
[0099] Considering that each piece of meat has a unique texture and that texture distribution is also uneven, the method first converts the image into a grayscale image, normalizes it to a uniform size, and then divides the grayscale image into H*W grids. Texture analysis is then performed on each small square in the image to calculate the texture information at that small square scale.
[0100] Step 2012: adjust the grayscale of the image, use the adjusted grayscale as the number of rows and columns, and construct a texture density matrix with an initial value of 0;
[0101] Specifically, grayscale adjustment includes: as needed, reducing the number of grayscale levels of the image to N. For example, an 8-bit image (0-255 grayscales) is quantized to 16 grayscales, where N=16.
[0102] Initialize an NxN matrix to zero, denoted as the texture density matrix, where N is the number of gray levels of the image.
[0103] Step 2013: Set the distance and direction. For each square in the image, find the neighboring squares with the given distance and direction.
[0104] Specifically, setting the distance and direction includes: selecting a specific distance (d) and direction (θ), for example, d=1 and θ=0° (indicating a horizontal direction).
[0105] Traverse every pixel in the image, and for each pixel (i, j) in the image, find its neighboring pixels at a given distance and direction.
[0106] Step 2014: take the grayscale of the current square as the row number and the grayscale of its neighboring square as the column number, and add 1 to the corresponding row and column numbers in the texture density matrix;
[0107] Specifically, construct a texture density matrix: suppose the grayscale of the current pixel is g1 and the grayscale of its neighboring pixel is g2, then add 1 to the g1th row and g2th column of the texture density matrix.
[0108] Step 2015: When approaching the edge of the image, based on the selected distance and direction, if the current square has no neighboring squares, skip the current square;
[0109] Step 2016: Traverse each square in the image until all squares in the image are processed, obtain the texture density matrix in the current direction and perform normalization processing;
[0110] Specifically, the normalization includes: the texture density matrix constructed by the present invention represents the frequency of occurrence of grayscale differences of neighboring pixels, not the probability value. To obtain a probability representation, each element of the matrix is divided by the sum of all elements in the matrix.
[0111] Step 2017: Set different distances and directions, repeat the above steps, obtain the texture density matrices in different directions and perform normalization processing respectively;
[0112] Specifically, we redefine multiple calculations for specific distances (d) and directions (θ), and calculate a new texture density matrix again. Repeat the above steps, using a different direction each time.
[0113] Step 2016: Calculating a texture density matrix table of the image based on a plurality of texture density matrices obtained from different directions;
[0114] Specifically, the synthesis direction includes: averaging multiple texture density matrices obtained from different directions to obtain a rotationally invariant texture density matrix representation; the calculation formula is as follows:
[0115] Take the arithmetic average of the GLCM (texture density matrix) in each direction; assuming that the GLCMs in four directions are calculated: P 0° ,P 45° ,P 90° ,P135° For each element ij in GLCM, its rotation invariant version is:
[0116] For each GLCM element ij, its rotation-invariant geometric mean is:
[0117]
[0118] Step 202: Segment the image layer into multiple fleshy regions based on the texture density matrix, including:
[0119] Step 221: Set the initial window of the image, perform probability analysis on the texture density matrix of the squares in the window, and obtain the meat texture degree T and texture variance V of the current window;
[0120] Among them, the probability analysis of the texture density matrix includes: contrast, energy, entropy, homogeneity, correlation, and difference. The calculation formula is as follows:
[0121] (1) Contrast: Contrast describes the size of elements outside the diagonal elements of the GLCM. A large contrast value usually means that the image has higher frequency changes or stronger textures.
[0122] Contrast=∑_i,j(ij) 2 ×P(i,j)
[0123] (2) Energy or Angular Second Moment (ASM), which represents the quadratic sum of GLCM, captures the uniformity of the image or the consistency of the texture.
[0124] Energy = ∑_i,jP(i,j) 2
[0125] (3) Entropy, which represents the complexity or randomness of the texture. A high entropy value means that the texture information is more complex.
[0126] Entropy=-∑_i,jP(i,j)×log(P(i,j))
[0127] (4) Homogeneity or Inverse Difference Moment (IDM), which indicates the similarity or consistency of local responses in the image.
[0128]
[0129] (5) Correlation, which describes the linear correlation between two gray levels i and j and is calculated by the mean and standard deviation of each gray level.
[0130] (6) Dissimilarity, which indicates the difference in grayscale values between two pixels.
[0131] Dissimilarity=∑_i,j|ij|×P(i,j)
[0132] (a) Perform texture density matrix analysis on each small grid and calculate the texture density contrast and local variance of each small grid. The local variance is calculated using the original grayscale pixels: a higher variance may indicate that this area has rich texture, and a larger contrast means that the image has higher frequency changes and textures. V represents the weighted sum of texture density contrast and local variance.
[0133] T=f(V,Contrast)
[0134] in:
[0135] T is defined as the meat texture. V is the grid texture variance, u is the mean, and pi represents the meat texture density probability.
[0136] Step 2022: If the meat texture T of the current window is lower than the set variance threshold M, continue segmentation and determine the main direction of the texture by calculating the gradient direction within the window. Specifically, the process includes:
[0137] (b) Threshold setting: Set a variance threshold, such as M. When the meat texture is lower than M, the region is considered to require further exploration and segmentation is continued. When the meat texture is higher than M, the region is considered to have good meat quality and rich texture.
[0138] (c) Calculate the direction of the texture segmentation in the next step: Calculate the gradient direction within the window and determine the main direction of the texture. This can be done using a Sobel or Prewitt filter.
[0139] Here’s how:
[0140] The direction of the next texture segmentation can be determined by calculating the gradient direction of the pixels in the current window. The horizontal gradient (Gx) and vertical gradient (Gy) calculated by the present invention using Sobel or Prewitt filters are performed for each pixel. Specifically, these filters apply a small convolution kernel to each pixel of the image to estimate the grayscale change of the pixel in the horizontal and vertical directions.
[0141] Horizontal Sobel kernel (Gx):
[0142]
[0143] Vertical Sobel kernel (Gy):
[0144]
[0145] Convolution operation: For each pixel in the image, take the 3x3 area around it with the pixel as the center and perform convolution operation with the horizontal and vertical kernels respectively. The convolution result is the horizontal and vertical gradient value of the pixel, expressed as Gx and Gy respectively. The calculation formula is:
[0146] Gx(x,y) = horizontal kernel * image area
[0147] Gy(x,y) = vertical kernel * image area
[0148] After obtaining the horizontal and vertical gradients, calculate the gradient direction for each pixel:
[0149] Gradient Direction: used to represent the gradient direction of a pixel. The calculation formula is:
[0150]
[0151] The gradient direction θ represents the angle from the current pixel to the direction with the maximum gradient change.
[0152] Gradient Magnitude: It is used to measure the intensity of the pixel gradient. The formula is:
[0153]
[0154] Determine the main direction of the texture, and the gradient direction θ represents the angle from the current pixel to the direction with the largest gradient change.
[0155] By counting the gradient direction θ of each pixel in the window, the overall main texture direction can be determined:
[0156] 1. Direction distribution analysis: Count the distribution of gradient directions θ within the window and find the direction with the highest frequency as the main texture direction.
[0157] 2. Weighted average direction: The gradient magnitude is weighted averaged to more accurately reflect the direction of the strong texture area.
[0158] Based on the determination of the dominant direction, further segmentation can be performed along the dominant texture direction, usually along a direction perpendicular to the dominant direction to ensure that details in important texture directions are preserved.
[0159] Step 2023: If the texture variance V is less than the meat texture degree T, shrink the window along the main direction of the texture to divide it into multiple areas;
[0160] (d) Window expansion rule: If the variance is less than T and the texture direction is clear, shrink the window along the main texture direction, for example, divide the window into multiple square areas along the main texture direction, such as Figure 3 shown.
[0161] More specifically:
[0162] The above shrinking window along the main texture direction, the shrinking process is:
[0163] Initially, the original image is divided into small grids of fixed size. Each grid is used as a basic unit to extract texture and color features, such as texture contrast, local variance, and color mean. The texture complexity of each grid is further analyzed. If the texture features are above a set threshold, the texture is considered rich and no further subdivision is performed. If the texture features are below the threshold, the texture direction is calculated (along the main direction) to further refine the segmentation to capture more details.
[0164] The method is as follows: First, use the gradient filter to extract the texture direction information within the grid and count the main gradient directions:
[0165] If the regional texture direction is significant, the grid is further subdivided along the main direction (such as horizontal, vertical or diagonal direction), for example, horizontal texture is divided into horizontal strip-shaped areas, vertical texture is divided into vertical strip-shaped areas, and diagonal texture is divided into diamond-shaped areas.
[0166] If the texture directionality within the region is not obvious, uniform segmentation is used to evenly divide the grid into multiple small square grids. After each refinement, the texture features and direction of the newly generated small grid are recalculated, and this process is repeated until the stopping condition is met. When the texture features of the grid tend to be uniform, or the grid area is less than the set minimum threshold, the refinement stops and the grid is marked as the final segmentation area.
[0167] Through this dynamic adjustment and gradually refined shrinkage process, the multi-level segmentation of the image is finally completed, accurately capturing the local details and overall distribution characteristics of the meat texture. The advantages are:
[0168] Detail capture: Make full use of the texture direction information in the region and capture local details through refined segmentation along the main direction.
[0169] Adaptability: The segmentation strategy is dynamically adjusted according to the texture complexity, so that the segmentation result can cover the texture-rich areas while avoiding redundant processing of the texture-uniform areas.
[0170] Efficiency: Through threshold judgment and segmentation stop conditions, meaningless segmentation operations are significantly reduced and overall computational efficiency is improved.
[0171] Specifically, in this embodiment, the division method is as follows:
[0172] The division is performed in a direction perpendicular to the main texture direction, with the center point being the maximum gradient amplitude. With the maximum gradient amplitude as the center, four small squares of changing direction are divided, which are called the next level square area, at k times the side length of the previous level small square. In this invention, k = 1.3. In this case, one square in the previous level is divided into four squares in the next level.
[0173] Step 2024: Perform a probability analysis of the texture density matrix for each newly divided area, and repeat the above steps until the entire image is traversed. When the number of pixels in the newly divided area is lower than the set pixel threshold G, no further segmentation is performed, and the traversal ends, obtaining the meat texture degree of all squares in the image.
[0174] (e) If the newly divided square area exceeds the original grid range, the newly divided grid will be used as the main area. Because the final segmentation is based on pixel statistics, the grid that exceeds the limit is equivalent to a little more calculation, which does not affect the final segmentation.
[0175] (f) Texture density matrix analysis is performed on each newly divided small grid, and the meat texture is recalculated. When the meat texture is lower than M, it is considered that this area needs further exploration and segmentation continues.
[0176] (g) When the pixel size of the small grid area is less than G pixels, no further segmentation is performed.
[0177] (h) Traversing the image: Repeat the above steps to traverse the entire image and obtain the fleshy texture of all grids, including the newly divided grids.
[0178] Step 2025: Divide the meat quality areas by counting the meat texture of all squares in the image; different meat quality areas include: high-quality meat area, medium-quality meat area and ordinary meat area.
[0179] When the meat texture index is higher than M, it is considered to be a high-quality meat area; when the meat texture index is lower than M but higher than P, it is considered to be an intermediate meat area; when the meat texture index is lower than P but higher than U, it is considered to be a normal meat area; when the meat texture index is lower than U, it is considered to be an edge or blank area. M, P, and U are hyperparameters and are set manually.
[0180] (I) Count the face value percentages of high-quality meat, medium-quality meat, and ordinary meat. The statistical method is: if the pixel position belongs to the grid division of the high-quality meat area, then the pixel point is in the high-quality meat area. The same applies to the other areas.
[0181] (g) Meat quality is graded based on the percentage of premium, intermediate, and standard meat quality areas. The larger the premium meat quality area, the higher the grade and the higher the quality of the meat.
[0182] In step 3, different meat quality grade areas are input into different transfromer networks for fine-grained feature extraction. The outputs of multiple transfromer networks are sequentially passed through the weighted fusion layer and the fully connected layer to obtain the final meat quality evaluation results.
[0183] For each divided region, all texture density grids within that region are extracted. The texture density grids for high-quality, intermediate-quality, and standard meat regions have different sizes and scales, and are fed into different transformer networks to determine meat freshness.
[0184] Since there are a huge number of grids in each area and many grid features are very similar, the calculation of all of them in the transformer network will bring a huge amount of computation. Therefore, the present invention proposes a routing affinity pruning transformer network to greatly reduce the computational cost while ensuring feature identification.
[0185] In step 3, the segmented meat regions are fed into different transformer networks for fine-grained feature extraction, including:
[0186] Step 301: Divide the meat area into multiple non-overlapping areas, establish an adjacency relationship matrix between input features of the non-overlapping areas to capture the correlation between the non-overlapping areas, and construct a routing index matrix based on the multiple adjacency relationship matrices of the meat area;
[0187] For each meat quality grade area, it is divided into S non-overlapping areas, such as Figure 4 As shown, it is divided into 4 major areas.
[0188] Among them, the adjacency relationship matrix between the input features of non-overlapping regions is established to capture the correlation between non-overlapping regions, including:
[0189] Step 3011: Calculate the color histogram of the non-overlapping area, and calculate the color mean, median and mode of the non-overlapping area according to the color histogram to construct the color feature vector C n ;
[0190] Step 3012: Calculate the contrast, energy, entropy, homogeneity, correlation and difference parameters based on the texture density matrix of the non-overlapping area to construct the texture density feature vector R n ;
[0191] The input feature of the non-overlapping area is T n , T n =[C n ,R n ], T n It is called integrated discriminant feature and is used as input feature of transformer network.
[0192] Step 3013: Calculate the query vector and key vector of the non-overlapping area based on the color feature vector and texture density feature vector of the non-overlapping area;
[0193] Specifically: calculate the average value of all features in each region to obtain the region-level query vector Q s and key vector K s .
[0194] g represents the number of grids in each region, and s represents the sth region.
[0195] W K , W Q is the feature map matrix, trainable, randomly initialized.
[0196] Step 3014: Calculate the similarity between non-overlapping regions based on the query vector and the key vector, obtain the adjacency relationship matrix of the non-overlapping regions, and perform trimming.
[0197] Among them, (1) establish the adjacency relationship matrix, including: using Q s and K s The similarity between regions is calculated by matrix multiplication between them, generating a region affinity matrix A. This matrix measures the degree of semantic association between two regions. The calculation method is:
[0198] A1=[Q1·K1,…,Q1·K s ,Q1·K S ]
[0199] …
[0200] A s =[Q s K1,…,Q s ·K s ,Q s ·K S ]
[0201] As above, A1 represents the affinity between region 1 and all other regions. s Represents the affinity between region S and all other regions.
[0202] (2) Tailoring the affinity matrix, including: based on the affinity matrix A1 or A s , select the top h most relevant regions for each region affinity matrix. The result of this step is to obtain a pruned affinity matrix where each region is only connected to its h most relevant other regions.
[0203] Step 3015: Generate routing index matrix: Based on the pruned affinity matrix, create a routing index matrix, R1 S The i-th row of R1 contains the k region indices that are most relevant to the h-th region. S There are S rows and h columns in total.
[0204] Step 302: Based on the multi-head attention mechanism module, the features of each non-overlapping area in the fleshy area are calculated. During the feature extraction process, the related areas of the non-overlapping area are obtained by querying the routing index matrix, and the related features between the non-overlapping area and its related areas are calculated.
[0205] Among them, the calculation of the regional multi-head attention mechanism includes: each region contains m finer-grained grid features. For example, each region of the present invention has 4 fine-grained grid features. When calculating the attention of the transformer, each grid feature first calculates the attention of the transformer with the features in its own grid, and then queries the routing index matrix of its own region, and calculates the attention of the transformer with the grid features in h related regions in the routing index matrix.
[0206] like Figure 5 As shown in the figure, the red boxes are h related areas. The grids in the area perform multi-head attention mechanism calculations on each other, but do not perform attention calculations with other grids.
[0207] like Figure 5 As shown in the figure, the features of multiple small grids in each non-overlapping area are encoded with position information and input into the Masked Multi-head Attention of the transformer for multi-head attention calculation to obtain the output of the multi-head attention mechanism;
[0208] The output of the multi-head attention mechanism is input into ADD Normalization (normalization layer), Feed Forward (feedforward network layer), and ADD Normalization (normalization layer) to obtain multiple related features, namely Figure 5 The output feature vector in .
[0209] For different texture meat areas, the grid size is different, and the area size is also different. The present invention respectively imitates the above and establishes different transformer models for processing. The present invention constructs a cascade transformer model structure to achieve the final feature fusion of all texture meat areas. The model structure is as follows Figure 6 shown.
[0210] First, for each transformer model, feature extraction is performed for regions of varying scales and textures. This extraction method captures inter-region correlations by establishing an adjacency matrix between regional input features. The most relevant parts of these regions are then selected for fine-grained attention calculations, reducing computational effort.
[0211] Second, for each transformer model's output, which represents features of different meat quality regions and sizes, all output features are fused using either feature concatenation or addition. Weighted fusion is performed on the fused output of each transformer model, as the fused output represents features of different meat quality regions. Weighted fusion is performed using weighted addition.
[0212] Third, the weighted fusion features pass through two fully connected layers to achieve two functional outputs. The first fully connected layer is used to judge the freshness; the second fully connected layer is used to make a comprehensive judgment on the meat quality, giving a classification grade of 1-10, where Figure 7 (a), (b), and (c) show the classification results of level 1, level 2, and level 3, respectively.
[0213] Finally, the final meat quality evaluation opinion is given based on the output of the comprehensive meat quality judgment and the area ratios of the high-quality meat quality area, intermediate meat quality area, and ordinary meat quality area as mentioned above.
[0214] Example 2
[0215] This embodiment discloses a meat quality evaluation system, comprising:
[0216] The image acquisition module is configured to: acquire an image of fresh meat;
[0217] The image segmentation module is configured to: calculate a texture density matrix of the fresh meat image based on a texture histogram method, and segment the image into multiple meat quality regions according to the texture density matrix;
[0218] The meat quality evaluation module is configured to: construct a meat quality detection model comprising multiple parallel transfromer networks, a weighted fusion layer, and a fully connected layer; input the segmented meat quality regions into different transfromer networks for fine-grained feature extraction; and obtain meat quality evaluation results after the features extracted by the multiple parallel transfromer networks are sequentially passed through the weighted fusion layer and the fully connected layer.
[0219] The segmented meaty regions are input into different transformer networks for fine-grained feature extraction, including:
[0220] The meaty area is divided into multiple non-overlapping areas, and an adjacency relationship matrix between the input features of the non-overlapping areas is established to capture the correlation between the non-overlapping areas. A routing index matrix is constructed based on the multiple adjacency relationship matrices of the meaty areas.
[0221] Based on the multi-head attention mechanism module, the features of each non-overlapping area in the meaty area are calculated. During the feature extraction process, the related areas of the non-overlapping area are obtained by querying the routing index matrix, and the related features between the non-overlapping area and its related areas are calculated.
[0222] Example 3
[0223] The purpose of this embodiment is to provide a computer-readable storage medium.
[0224] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of a meat quality evaluation method as described in Example 1 of the present disclosure.
[0225] Example 4
[0226] The purpose of this embodiment is to provide an electronic device.
[0227] An electronic device includes a memory, a processor, and a program stored in the memory and executable on the processor. When the processor executes the program, the steps of a meat quality evaluation method as described in Example 1 of the present disclosure are implemented.
[0228] The steps involved in the apparatuses of Examples 2, 3, and 4 above correspond to those of Method Example 1. For detailed implementations, please refer to the relevant description of Example 1. The term "computer-readable storage medium" should be understood to mean a single medium or multiple media containing one or more instruction sets; it should also be understood to include any medium capable of storing, encoding, or carrying an instruction set for execution by a processor and causing the processor to perform any method of the present invention.
[0229] Those skilled in the art will appreciate that the modules or steps of the present invention described above can be implemented using a general-purpose computer device. Alternatively, they can be implemented using program code executable by a computing device, which can then be stored in a storage device and executed by the computing device. Alternatively, they can be fabricated into separate integrated circuit modules, or multiple modules or steps can be fabricated into a single integrated circuit module for implementation. The present invention is not limited to any specific combination of hardware and software.
[0230] Although the above describes the specific embodiments of the present invention in conjunction with the accompanying drawings, it is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art on the basis of the technical solution of the present invention without any creative work are still within the scope of protection of the present invention.
Claims
1. A method for evaluating meat quality, characterized in that: include: Get fresh meat images; The texture density matrix of the fresh meat image is calculated based on the texture histogram method, and the image is segmented into various meat quality areas using a hierarchical segmentation method. Divide each meat quality area into multiple non-overlapping areas and determine the input features of each non-overlapping area; The input features of the non-overlapping regions corresponding to the various meat quality regions are input into multiple parallel transformer networks of the meat quality detection model according to the differences in meat quality regions. An adjacency relationship matrix is established between the input features of the non-overlapping regions within each meat quality region. Based on the adjacency relationship matrix, the other regions that are most relevant to each non-overlapping region are determined, including: According to the color feature vector and texture density feature vector of the non-overlapping area, the query vector and key vector of the non-overlapping area are calculated; the average of all features in each area is calculated to obtain the region-level query vector and key vector : , g represents the number of grids in each region, and s represents the sth region; , , is the feature mapping matrix; Use matrix multiplication between the query vector and the key vector to calculate the similarity between different non-overlapping regions and generate the adjacency relationship matrix of each non-overlapping region; Based on the adjacency matrix, the top h regions that are most relevant to each non-overlapping region are cut out to create a routing index matrix. The multi-head attention mechanism of the transformer network is used to calculate the relevant features within each non-overlapping region and the non-overlapping region and its most relevant regions, including: Based on the routing index matrix, the top h other regions that are most relevant to the current non-overlapping region are queried through the multi-head attention mechanism; First, calculate the transformer attention of the features in the grid divided by the current non-overlapping area and its own area to obtain the first attention; Then calculate the transformer attention of the features in the grid divided by the current non-overlapping area and the first h other areas in the routing index matrix to obtain the second attention; Based on the first attention and the second attention, relevant features are obtained; The multiple related features obtained by each transfromer network are fused by feature concatenation or addition to obtain the output of each transfromer network; The outputs of multiple transfromer networks are weightedly fused to obtain feature outputs of different meat quality areas; Based on the feature output of different meat quality areas, the classification results of meat freshness and the comprehensive classification results of meat quality are obtained; Based on the relevant features obtained by multiple parallel transfromer networks, the freshness and quality of fresh meat are evaluated; Construct a cascade transformer model structure to achieve the final feature fusion of all textured meat areas: First, for each transformer model, feature extraction is performed on regions of different scales and textures. This extraction method captures the correlation between regions by establishing an adjacency matrix between regional input features. The most relevant parts of these regions are then selected for fine-grained attention calculations, reducing computational effort. Second, for each transformer model's output, which represents features of different meat quality regions and regions of different sizes, all output features are fused using feature concatenation or addition. Weighted fusion is performed on the fused output of each transformer model, as the fused output of each transformer model represents the features of different meat quality regions. Third, the weighted fusion features are passed through two fully connected layers to achieve two functional outputs. The first fully connected layer is used to judge the freshness; the second fully connected layer is used to comprehensively judge the meat quality, giving a classification grade of 1-10. According to the hierarchical segmentation method, the image is divided into various fleshy areas, including: Step 1: Set the initial window of the image, perform probability analysis on the texture density matrix of the squares within the initial window, and obtain the meat texture degree T and texture variance V of the current initial window; Step 2: If the meat texture T of the current initial window is lower than the set variance threshold M, the current initial window is further segmented. The main gradient direction of the pixels in the initial window is extracted using a gradient filter. The main texture direction is determined based on the main gradient direction, and the next segmentation direction is determined based on the perpendicular direction to the main texture direction. Step 3: If the texture variance V is less than the meat texture T, shrink the window along the main direction of the texture to create multiple new regions. Step 4: Perform a probability analysis of the texture density matrix for each newly divided area. Use the newly divided area as the initial window and repeat steps 1 to 3 until the entire image is traversed. When the number of pixels in the newly divided area falls below the set pixel threshold G, no further segmentation is performed and the traversal ends, obtaining the meat texture degree of all squares in the image. Step 5: Divide the meat area by counting the meat texture of all squares in the image; In step 3, if the texture variance V is less than the meat texture degree T, the window is shrunk along the main direction of the texture to newly divide multiple regions, specifically including: Determine whether the texture direction in the initial window is obvious based on the main gradient direction: If the texture direction in the initial window is obvious, the initial window is further subdivided along the main gradient direction. The main gradient direction includes horizontal, vertical or diagonal directions. The corresponding newly divided regions are horizontal strip regions, vertical strip regions and diamond regions. If the texture direction in the initial window is not obvious, uniform refinement segmentation is used to evenly divide the initial window into multiple small square grids, and the newly divided regions are multiple small square grids; In the step 5, the meat texture of all squares in the image is counted to divide the meat area, which specifically includes: First, based on the set meat texture threshold, the meat quality area to which each square belongs is determined. The meat quality areas include high-quality meat area, medium-quality meat area and low-quality meat area. The meat quality is graded based on the proportion of the face value of the high-quality meat area, the medium-quality meat area and the low-quality meat area.
2. A meat quality evaluation method according to claim 1, characterized in that: The method of calculating the texture density matrix of the fresh meat image based on the texture histogram method includes: After converting the acquired fresh meat image into a grayscale image and normalizing it, the image is gridded to obtain multiple squares; Adjust the grayscale of the image, use the adjusted grayscale as the number of rows and columns, and construct a texture density matrix with an initial value of 0; Set the distance and direction. For each square in the image, find the neighboring squares at the given distance and direction. Use the grayscale of the current square as the row number and the grayscale of its neighboring square as the column number, and add 1 to the corresponding row and column numbers in the texture density matrix. When approaching the edge of the image, if the current square has no neighboring squares according to the selected distance and direction, the current square is skipped; each square in the image is traversed until all squares in the image are processed, and the texture density matrix in the current direction is obtained and normalized; Set different distances and directions, repeat the above steps, obtain the texture density matrices in different directions and perform normalization processing respectively; The texture density matrix table of the image is calculated based on multiple texture density matrices obtained from different directions.
3. The meat quality evaluation method according to claim 1, wherein: Determine the input features of each non-overlapping region, including: Calculate the color histogram of the non-overlapping area, and calculate the color mean, median and mode of the non-overlapping area based on the color histogram to construct the color feature vector; Perform probabilistic analysis on the texture density matrix of non-overlapping areas, calculate contrast, energy, entropy, homogeneity, correlation and difference parameters, and construct texture density feature vectors; The input features of each non-overlapping region are constructed based on the color feature vector and the texture density feature vector.
4. A meat quality evaluation system, characterized in that: include: The image acquisition module is configured to: acquire an image of fresh meat; The image segmentation module is configured to: calculate the texture density matrix of the fresh meat image based on the texture histogram method, and segment the image into multiple meat quality areas according to a hierarchical segmentation method; The feature acquisition module is configured to: divide each meat quality region into a plurality of non-overlapping regions and determine an input feature of each non-overlapping region; The similarity calculation module is configured to: input the input features of non-overlapping regions corresponding to multiple meat quality regions into multiple parallel transformer networks of the meat quality detection model according to the differences in meat quality regions, establish an adjacency relationship matrix between the input features of non-overlapping regions within each meat quality region, and based on the adjacency relationship matrix, determine other regions that are most relevant to each non-overlapping region, including: According to the color feature vector and texture density feature vector of the non-overlapping area, the query vector and key vector of the non-overlapping area are calculated; the average of all features in each area is calculated to obtain the region-level query vector and key vector : , g represents the number of grids in each region, and s represents the sth region; , , is the feature mapping matrix; Use matrix multiplication between the query vector and the key vector to calculate the similarity between different non-overlapping regions and generate the adjacency relationship matrix of each non-overlapping region; Based on the adjacency matrix, the top h regions that are most relevant to each non-overlapping region are cut out to create a routing index matrix. The attention mechanism module is configured to use the multi-head attention mechanism of the transformer network to calculate the relevant features within each non-overlapping region and the relevant features of the non-overlapping region and its most relevant regions, including: Based on the routing index matrix, the top h other regions that are most relevant to the current non-overlapping region are queried through the multi-head attention mechanism; First, calculate the transformer attention of the features in the grid divided by the current non-overlapping area and its own area to obtain the first attention; Then calculate the transformer attention of the features in the grid divided by the current non-overlapping area and the first h other areas in the routing index matrix to obtain the second attention; Based on the first attention and the second attention, relevant features are obtained; The multiple related features obtained by each transfromer network are fused by feature concatenation or addition to obtain the output of each transfromer network; The outputs of multiple transfromer networks are weightedly fused to obtain feature outputs of different meat quality areas; Based on the feature output of different meat quality areas, the classification results of meat freshness and the comprehensive classification results of meat quality are obtained; The classification module is configured to evaluate the freshness and quality of fresh meat based on the relevant features obtained by multiple parallel transformer networks, construct a cascade transformer model structure, and finally achieve feature fusion of all texture and meat regions: First, for each transformer model, feature extraction is performed on regions of different scales and textures. This extraction method captures the correlation between regions by establishing an adjacency matrix between regional input features. The most relevant parts of these regions are then selected for fine-grained attention calculations, reducing computational effort. Second, for each transformer model's output, which represents features of different meat quality regions and regions of different sizes, all output features are fused using feature concatenation or addition. Weighted fusion is performed on the fused output of each transformer model, as the fused output of each transformer model represents the features of different meat quality regions. Third, the weighted fusion features are passed through two fully connected layers to achieve two functional outputs. The first fully connected layer is used to judge the freshness; the second fully connected layer is used to comprehensively judge the meat quality, giving a classification grade of 1-10. According to the hierarchical segmentation method, the image is divided into various fleshy areas, including: Step 1: Set the initial window of the image, perform probability analysis on the texture density matrix of the squares within the initial window, and obtain the meat texture degree T and texture variance V of the current initial window; Step 2: If the meat texture T of the current initial window is lower than the set variance threshold M, the current initial window is further segmented. The main gradient direction of the pixels in the initial window is extracted using a gradient filter. The main texture direction is determined based on the main gradient direction, and the next segmentation direction is determined based on the perpendicular direction to the main texture direction. Step 3: If the texture variance V is less than the meat texture T, shrink the window along the main direction of the texture to create multiple new regions. Step 4: Perform a probability analysis of the texture density matrix for each newly divided area. Use the newly divided area as the initial window and repeat steps 1 to 3 until the entire image is traversed. When the number of pixels in the newly divided area falls below the set pixel threshold G, no further segmentation is performed and the traversal ends, obtaining the meat texture degree of all squares in the image. Step 5: Divide the meat area by counting the meat texture of all squares in the image; In step 3, if the texture variance V is less than the meat texture degree T, the window is shrunk along the main direction of the texture to newly divide multiple regions, specifically including: Determine whether the texture direction in the initial window is obvious based on the main gradient direction: If the texture direction in the initial window is obvious, the initial window is further subdivided along the main gradient direction. The main gradient direction includes horizontal, vertical or diagonal directions. The corresponding newly divided regions are horizontal strip regions, vertical strip regions and diamond regions. If the texture direction in the initial window is not obvious, uniform refinement segmentation is used to evenly divide the initial window into multiple small square grids, and the newly divided regions are multiple small square grids; In the step 5, the meat texture of all squares in the image is counted to divide the meat area, which specifically includes: First, based on the set meat texture threshold, the meat quality area to which each square belongs is determined. The meat quality areas include high-quality meat area, medium-quality meat area and low-quality meat area. The meat quality is graded based on the proportion of the face value of the high-quality meat area, the medium-quality meat area and the low-quality meat area.
5. A computer-readable storage medium having a program stored thereon, characterized in that: When the program is executed by a processor, the steps of the meat quality evaluation method according to any one of claims 1 to 3 are implemented.
6. An electronic device comprising a memory, a processor, and a program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the meat quality evaluation method according to any one of claims 1 to 3 are implemented.
Citation Information
Patent Citations
Device for detecting beef tenderness based on color image textural features and method thereof
CN103185731A
Product appearance defect classification method based on GLCM and CNN-Transform fusion and storage medium
CN114494254A