Meat quality evaluation method and system

By partitioning and dividing the meat into non-overlapping areas, filtering the relevant areas using the routing index matrix, and calculating the relevant features, the problems of single scale and large amount of calculation in the existing technology are solved, and fine-grained detection and accurate evaluation of the meat are achieved.

CN119516537AActive Publication Date: 2025-02-25SHANDONG ANALYSIS AND TEST CENTER
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411740381.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2025-02-25
Estimated Expiration
2044-11-29

AI Technical Summary

Technical Problem

When using transformer network for image segmentation and feature extraction in the prior art, there are problems of single scale and large calculations, which are difficult to discover meat quality characteristics in fine-grained manner, and are not conducive to meat quality evaluation.

Method used

By using texture density features to partition the meat, and divide each meat area with non-overlapping areas, filter the relevant areas using the routing index matrix, calculate the relevant features, reduce the amount of calculation of the transformer network, and improve the accuracy of freshness determination.

Benefits of technology

The fine-grained detection of different meat quality grade areas is achieved, the accuracy of determining the freshness of meat quality is improved, the calculation volume is optimized simultaneously, and the accuracy and efficiency of meat quality evaluation is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119516537A_ABST
    Figure CN119516537A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of image machine vision processing, and particularly relates to a meat quality evaluation method and system, and the method comprises the steps: obtaining a fresh meat image; calculating a texture density matrix of the fresh meat image based on a texture histogram method, and segmenting the image into various meat regions according to the texture density matrix; constructing a meat quality detection model, wherein the meat quality detection model comprises a plurality of parallel transfromer networks, a weighted fusion layer and a full connection layer; and inputting the plurality of segmented meat quality regions into different networks for fine-grained feature extraction, and obtaining a meat quality evaluation result after the features extracted by the plurality of parallel networks sequentially pass through a weighted fusion layer and a full connection layer. According to the method, when the features of each meat quality region are extracted, the related features are calculated after the related regions of the non-overlapping regions are screened by using the routing index matrix, so that the calculation amount of the network can be greatly reduced, and the freshness degree judgment precision of meat is improved.
Need to check novelty before this filing date? Find Prior Art

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 of the meat often determines whether people will buy it. After the pig is slaughtered, the color of the meat will change from dark red at the beginning to bright red to brown as the exposure time increases. This is because the surface color of the meat is mainly determined by the content of myoglobin. After the meat is left in the air for a long time, myoglobin will be strongly oxidized to oxidized myoglobin (when the oxidation degree exceeds 50%, the meat color appears brown), making the meat color appear dark brown. Therefore, it is of great significance to use computer vision to obtain color feature parameter values ​​from the original image of meat products and predict the freshness of meat.

[0003] Marbling in fresh meat refers to the content and distribution of intramuscular fat. Moderate marbling makes the meat more tender, fresh, and easy to chew. Meat with too little or too much marbling appears rough, hard to chew, and has no meaty taste. Therefore, the content and distribution of marbling are very important indicators for determining the quality of meat, and they play a decisive role in the evaluation of meat quality. Therefore, using multimodal learning technology to extract and analyze pork texture information and evaluate the appearance quality of meat 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 for research and application in many 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 technology, as an important part of image processing, can effectively separate objects and backgrounds in images, providing a clear and accurate basis for further image analysis. This technology has important applications in many fields such as medical imaging, remote sensing image processing, and machine vision. Texture analysis technology goes a step further. This includes the evaluation of multiple dimensions such as texture 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 key information for object recognition, classification, and status monitoring, showing great potential.

[0005] At present, 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 defects:

[0006] 1) Single scale: The traditional method divides the image into blocks, directly extracts features from each block, and sends them to the transformer structure. All image blocks have a single scale and cannot explore meat quality features in a fine-grained manner, which is not conducive to meat quality evaluation.

[0007] 2) Large amount of computation: The amount of computation of the transformer is determined by the number of blocks in the image. Summary of the invention

[0008] In order 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 divide meat into zones, divides each meat area into non-overlapping areas, and uses a routing index matrix to screen relevant areas of non-overlapping areas and then calculate relevant features. This can greatly 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 the raw meat image;

[0013] The texture density matrix of the fresh meat image is calculated based on the texture histogram method, and the image is segmented into multiple meat quality areas according to the hierarchical segmentation method;

[0014] Divide each meat quality region into multiple non-overlapping regions, and determine the input features of each non-overlapping region;

[0015] Input features of non-overlapping regions corresponding to multiple meat quality regions are input into multiple parallel transfromer networks of the meat quality detection model according to the differences in meat quality regions, and an adjacency relationship matrix between input features of non-overlapping regions within each meat quality region is established. Based on the adjacency relationship matrix, other regions most relevant to each non-overlapping region are determined;

[0016] The multi-head attention mechanism of the transformer network is used to calculate the relevant features of each non-overlapping region and the non-overlapping region and its most relevant regions;

[0017] Based on the relevant features obtained from multiple parallel transfromer networks, the freshness and quality of fresh meat are evaluated.

[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 a texture density matrix of the fresh meat image based on a 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 area into a plurality of non-overlapping areas, and determine an input feature of each non-overlapping area;

[0023] The similarity calculation module is configured to: input the input features of the non-overlapping regions corresponding to the multiple meat quality regions into the multiple parallel transfromer networks of the meat quality detection model according to the differences of 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 other regions that are most relevant to 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 of each non-overlapping region and the non-overlapping region and its most relevant regions;

[0025] The classification module is configured to evaluate the freshness and quality of the fresh meat based on the relevant features obtained by multiple parallel transfromer networks.

[0026] The 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 a 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 in a 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 detect meat quality in different meat quality areas. Because the color performance is different under different textures 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 into zones using texture density features, and then divides each meat area 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 greatly reduce the computational complexity of the transfromer network, improve the accuracy of determining the freshness of the meat, 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 textures of different areas are different, and the sizes of the image blocks are also different.

[0032] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] The accompanying drawings in the specification, 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 grid division of a fresh meat image according to 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] Embodiment 1

[0042] This embodiment discloses a method for evaluating meat quality.

[0043] A method for evaluating meat quality, comprising:

[0044] Get the raw meat image;

[0045] The texture density matrix of the fresh meat image is calculated based on the texture histogram method, and the image is segmented into multiple meat quality areas according to the hierarchical segmentation method;

[0046] Divide each meat quality region into multiple non-overlapping regions, and determine the input features of each non-overlapping region;

[0047] Input features of non-overlapping regions corresponding to multiple meat quality regions are input into multiple parallel transfromer networks of the meat quality detection model according to the differences in meat quality regions, and an adjacency relationship matrix between input features of non-overlapping regions within each meat quality region is established. Based on the adjacency relationship matrix, other regions most relevant to each non-overlapping region are determined;

[0048] The multi-head attention mechanism of the transformer network is used to calculate the relevant features of each non-overlapping region and the non-overlapping region and its most relevant regions;

[0049] Based on the relevant features obtained from multiple parallel transfromer networks, the freshness and quality of fresh meat are evaluated.

[0050] In some embodiments, the method of 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 a plurality of 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 number of rows and the grayscale of its neighboring squares as the number of columns, and add 1 to the corresponding row and column numbers of the texture density matrix.

[0054] When approaching the border of the image, according to the selected distance and direction, if the current square has no neighboring squares, 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 in 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 degree T of the current initial window is lower than the set variance threshold M, the current initial window is further segmented, and the main gradient direction of the pixels in the initial window is extracted using a gradient filter. The main texture direction is determined by the main gradient direction, and the continued segmentation direction is determined according to the vertical direction of the main texture direction;

[0060] Step 3: If the texture variance V is less than the meat texture T, the window is shrunk along the main direction of the texture to divide 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 again, and repeat the above steps 1 to 3 until the entire image is traversed; when the pixels of the newly divided area are lower than the set pixel threshold G, no further segmentation is performed, the traversal ends, and the meat texture degree of all squares in the image is obtained;

[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 areas, 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 multiple areas 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 further 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 judgment threshold, the meat quality area to which each square belongs is judged, and the meat quality area includes a high-quality meat area, a medium-quality meat area, and a low-quality meat area;

[0071] The meat quality is graded based on the percentage of the face value of high-quality meat areas, medium-quality meat areas and low-quality meat areas.

[0072] In some embodiments, determining the input feature 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 according to the color histogram to construct a color feature vector;

[0074] Probabilistic analysis is performed on the texture density matrix of non-overlapping areas to calculate contrast, energy, entropy, homogeneity, correlation, and difference parameters, and to 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 meat region, and determine other regions most relevant to each non-overlapping region based on the adjacency relationship matrix, including:

[0078] Calculate the query vector and the key vector of the non-overlapping region according to the color feature vector and the texture density feature vector of the non-overlapping region;

[0079] Use matrix multiplication between the query vector and the key vector to calculate the similarity between different non-overlapping regions and generate an adjacency relationship matrix for each non-overlapping region;

[0080] Based on the adjacency matrix, the top h other regions 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 of each non-overlapping region and other regions that the non-overlapping region is most related to, specifically including:

[0082] Based on the routing index matrix, the top h other regions most relevant to the current non-overlapping region are queried through the multi-head attention mechanism;

[0083] First, calculate the transformer's attention of the features in the grid divided by the current non-overlapping area and its own area to get the first attention;

[0084] Then, 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 is ​​calculated to obtain the second attention;

[0085] Based on the first attention and the second attention, relevant features are obtained.

[0086] In this embodiment, based on the first attention and the second attention, relevant features are obtained, 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 weighted and fused to obtain the 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] Next, the technical solution of this embodiment will be explained 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 multiple 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 successively passed through the weighted fusion layer and the fully connected layer to obtain the meat quality evaluation results.

[0096] Fresh meat texture information affects the quality level of meat. Therefore, the present invention extracts the texture features of pork surface and uses the texture features to make a preliminary analysis and grading of fresh meat quality. For meat quality evaluation, the quality of each piece of meat is not uniform. Some parts have good quality and high quality, while some parts have poor quality. Therefore, in order to comprehensively evaluate the quality of each piece of meat, the present invention proposes a fast meat quality segmentation and evaluation method based on texture density feature representation, which specifically includes:

[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, such as Figure 2 As shown, the image is divided into multiple squares.

[0099] Considering that each piece of meat has a unique texture and the texture distribution is also uneven, the present invention first converts the image into a grayscale image, normalizes it to a uniform size, and divides the grayscale image into H*W grids. After that, take each small square in the image, perform texture analysis, and calculate the texture information at the current small square scale.

[0100] Step 212: adjusting the grayscale of the image, using the adjusted grayscale as the number of rows and columns, and constructing a texture density matrix with an initial value of 0;

[0101] Specifically, the grayscale adjustment includes: as required, reducing the grayscale number of the image to N levels. For example, quantizing an 8-bit image (0-255 grayscales) to 16 grayscales, 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, and for each square in the image, find the neighboring square 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: taking the grayscale of the current square as the number of rows and the grayscale of its neighboring square as the number of columns, and adding 1 to the corresponding row and column positions of 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 border of the image, according to the selected distance and direction, if the current square has no neighboring squares, the current square is skipped;

[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 the grayscale difference of the neighboring pixels, not the probability value. In order 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 texture density matrices in different directions and perform normalization processing respectively;

[0112] Specifically, redefine multiple specific distances (d) and directions (θ) and calculate a new texture density matrix again. Repeat the above steps, each time using a different direction.

[0113] Step 2016: Calculate 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: for multiple texture density matrices obtained from different directions, averaging them 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 rotationally invariant geometric mean is:

[0117]

[0118] Step 202: Segment the image level into multiple fleshy regions according to the texture density matrix, including:

[0119] Step 221: setting an initial window of the image, performing probability analysis on the texture density matrix of the squares in the window, and obtaining 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 or texture consistency of the image.

[0124] Energy = ∑_i,jP(i,j) 2

[0125] (3) Entropy, which indicates 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 between the grayscale values ​​of 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 textures, 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 in the window; specifically, the following steps are performed:

[0137] (b) Setting a threshold: Set a variance threshold, such as M. When the meat texture is lower than M, it is considered that this area needs further exploration and segmentation. When the meat texture is higher than M, it is considered that this area has good meat quality and rich texture.

[0138] (c) Calculate the direction of the next texture segmentation: 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 texture segmentation direction of the next step 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 of the image, take the 3x3 area around 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: It is 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 gradient of a pixel. 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 maximum 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 the gradient direction θ in 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 principal directions, further segmentation can be performed along the principal texture directions, and typically segmentation is performed along directions perpendicular to the principal directions 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 into multiple areas;

[0160] (d) Window expansion rule: If the variance is less than T and the texture direction is clear, the window is shrunk along the main texture direction, for example, by dividing the window into multiple square regions 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] At the beginning, the original image is divided into small grids of fixed size, and 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 feature is higher than the set threshold, the texture is considered rich and no further subdivision is performed; if it is lower than 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 regions, vertical texture is divided into vertical strip-shaped regions, and diagonal texture is divided into diamond-shaped regions.

[0166] If the texture directionality in the area is not obvious, uniform refinement segmentation is used to evenly divide the grid into multiple small square grids. After each refinement, the texture features and directions of the newly generated small grids are recalculated, and this process is repeated until the stop 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 is stopped 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 the overall computational efficiency is improved.

[0171] Specifically, in this embodiment, the division method is as follows:

[0172] The division is performed in the direction perpendicular to the main texture direction, with the center point being the maximum value of the gradient amplitude. With the maximum value of the gradient amplitude as the center, four small squares of changing direction are divided at k times the side length of the small grid of the previous level, k=1.3 in the present invention, which is called the next level square area. At this time, one square of the previous level is divided into four squares of the next level.

[0173] Step 2024: Probability analysis of the texture density matrix is ​​performed for each newly divided area, and the above steps are repeated until the entire image is traversed; when the pixels of the newly divided area are lower than the set pixel threshold G, no further segmentation is performed, and the traversal is terminated to obtain 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 flesh texture of all grids, including the newly divided grids.

[0178] Step 2025: The meat quality regions are divided by counting the meat texture of all the squares in the image; the different meat quality regions include: high-quality meat quality region, medium-quality meat quality region and ordinary meat quality region.

[0179] When the meat texture is higher than M, it is considered to be a high-quality meat area; when the meat texture is lower than M but higher than P, it is considered to be a medium-quality meat area; when the meat texture is lower than P but higher than U, it is considered to be a normal meat area; when the meat texture is lower than U, it is considered to be an edge or blank. Among them, M, P, and U are hyperparameters, which are set manually.

[0180] (I) Count the percentage of the face value of high-quality meat area, medium-quality meat area, and ordinary meat area. The statistical method is that if the pixel position belongs to the grid division of the high-quality meat area, then the pixel point is the high-quality meat area. The same applies to the others.

[0181] (g) The meat quality is graded by the proportion of the face value of the high-quality meat area, the medium-quality meat area, and the ordinary meat area. The larger the area of ​​the high-quality meat area, the higher the grade and the higher the meat quality.

[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 result.

[0183] For each divided area, all the texture density grids of the area are extracted. The texture density grids of the high-quality meat area, the intermediate-quality meat area, and the ordinary meat area are of different sizes and scales, and are sent to different transformer networks for meat freshness judgment and calculation.

[0184] Since the number of grids in each area is huge and many grid features are very similar, the calculation of all grids involved in the transformer network will bring a huge amount of calculation. Therefore, the present invention proposes a routing affinity pruning transformer network to greatly reduce the amount of calculation while ensuring feature identification.

[0185] In step 3, the segmented meat regions are input 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 the non-overlapping regions is established to capture the correlation between the 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 the input feature of the transformer network.

[0192] Step 3013: 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;

[0193] Specifically: average all features in each region to obtain the region-level query vector Q s and the key vector K s .

[0194] g represents the number of grids in each region. 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) establishing the adjacency relationship matrix includes: using Q s and K s The similarity between regions is calculated by matrix multiplication between them, generating a regional 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 a 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 meat area are calculated. During the feature extraction process, the relevant area of ​​the non-overlapping area is obtained by querying the routing index matrix, and the relevant features between the non-overlapping area and its relevant area are calculated.

[0205] Among them, the calculation of the regional multi-head attention mechanism includes: each region contains m finer-grained grid features, such as 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 calculations with 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 respectively 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, we process the feature extraction of different scales and meat quality regions. The extraction method is to capture the correlation between regions by establishing the adjacency relationship matrix between the regional input features, and then select the most relevant part from this region to perform fine-grained attention calculation to reduce the amount of calculation.

[0211] Second, for the output of each transformer model, which represents the features of different meat quality areas and different size areas, all output features are fused by feature concatenation or addition. For the output of each transformer model after feature fusion, weighted fusion is performed because the output of each transformer model after feature fusion represents the feature output of different meat quality areas. The weighted fusion method is weighted addition of features.

[0212] 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 make a comprehensive judgment on the meat quality and give 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, based on the output of the comprehensive meat quality judgment and the area ratios of the high-quality meat area, intermediate-quality meat area, and ordinary meat quality area, the final meat quality evaluation opinion is given.

[0214] Embodiment 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 areas according to the texture density matrix;

[0218] The meat quality evaluation module is configured to: construct a meat quality detection model, which includes multiple parallel transfromer networks, a weighted fusion layer, and a fully connected layer; input the segmented meat 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 meat regions are input into different transformer networks for fine-grained feature extraction, including:

[0220] The meat area is divided into multiple non-overlapping areas, and an adjacency relationship matrix between 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 multiple adjacency relationship matrices of the meat area.

[0221] Based on the multi-head attention mechanism module, the features of each non-overlapping area in the meat area are calculated. During the feature extraction process, the relevant area of ​​the non-overlapping area is obtained by querying the routing index matrix, and the relevant features between the non-overlapping area and its relevant area are calculated.

[0222] Embodiment 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 in a meat quality evaluation method as described in Example 1 of the present disclosure.

[0225] Embodiment 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 in a meat quality evaluation method as described in Example 1 of the present disclosure are implemented.

[0228] The steps involved in the apparatuses of the above embodiments 2, 3 and 4 correspond to the method embodiment 1, and the specific implementation methods can refer to the relevant description part of embodiment 1. The term "computer-readable storage medium" should be understood as a single medium or multiple media including one or more instruction sets; it should also be understood to include any medium that can store, encode or carry an instruction set for execution by a processor and enable the processor to execute any method in the present invention.

[0229] Those skilled in the art should understand that the modules or steps of the present invention described above can be implemented by a general-purpose computer device, or alternatively, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made 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 implementation mode 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 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 the raw meat image; The texture density matrix of the fresh meat image is calculated based on the texture histogram method, and the image is segmented into multiple meat quality areas according to the hierarchical segmentation method; Divide each meat quality region into multiple non-overlapping regions, and determine the input features of each non-overlapping region; Input features of non-overlapping regions corresponding to multiple meat quality regions are input into multiple parallel transfromer networks of the meat quality detection model according to the differences in meat quality regions, and an adjacency relationship matrix between input features of non-overlapping regions within each meat quality region is established. Based on the adjacency relationship matrix, other regions most relevant to each non-overlapping region are determined; The multi-head attention mechanism of the transformer network is used to calculate the relevant features of each non-overlapping region and the non-overlapping region and its most relevant regions; Based on the relevant features obtained from multiple parallel transfromer networks, the freshness and quality of fresh meat are evaluated.

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 a plurality of 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 number of rows and the grayscale of its neighboring squares as the number of columns, and add 1 to the corresponding row and column numbers of the texture density matrix. When approaching the border of the image, according to the selected distance and direction, if the current square has no neighboring squares, 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. A meat quality evaluation method according to claim 2, characterized in that: According to the hierarchical segmentation method, the image is segmented 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 in 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 degree T of the current initial window is lower than the set variance threshold M, the current initial window is further segmented, and the main gradient direction of the pixels in the initial window is extracted using a gradient filter. The main texture direction is determined by the main gradient direction, and the continued segmentation direction is determined according to the vertical direction of the main texture direction; Step 3: If the texture variance V is less than the meat texture T, the window is shrunk along the main direction of the texture to divide 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 again, and repeat the above steps 1 to 3 until the entire image is traversed; when the pixels of the newly divided area are lower than the set pixel threshold G, no further segmentation is performed, the traversal ends, and the meat texture degree of all squares in the image is obtained; Step 5: Divide the meat area by counting the meat texture of all squares in the image.

4. A meat quality evaluation method according to claim 3, characterized in that: In the 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 areas, 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 multiple areas are multiple small square grids; or, 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 judgment threshold, the meat quality area to which each square belongs is judged, and the meat quality area includes a high-quality meat area, a medium-quality meat area, and a low-quality meat area; The meat quality is graded based on the percentage of the face value of high-quality meat areas, medium-quality meat areas and low-quality meat areas.

5. A meat quality evaluation method according to claim 1, characterized in that: 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 according to the color histogram to construct a color feature vector; Probabilistic analysis is performed on the texture density matrix of non-overlapping areas to calculate contrast, energy, entropy, homogeneity, correlation, and difference parameters, and to construct texture density feature vectors; Construct input features for each non-overlapping region based on the color feature vector and the texture density feature vector; or, Establish an adjacency relationship matrix between the input features of non-overlapping regions within each meat region, and determine other regions most relevant to each non-overlapping region based on the adjacency relationship matrix, including: Calculate the query vector and the key vector of the non-overlapping region according to the color feature vector and the texture density feature vector of the non-overlapping region; Use matrix multiplication between the query vector and the key vector to calculate the similarity between different non-overlapping regions and generate an adjacency relationship matrix for each non-overlapping region; Based on the adjacency matrix, the top h other regions most relevant to each non-overlapping region are clipped to create a routing index matrix.

6. A meat quality evaluation method according to claim 5, characterized in that: The multi-head attention mechanism of the transformer network is used to calculate the relevant features of 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 most relevant to the current non-overlapping region are queried through the multi-head attention mechanism; First, calculate the transformer's attention of the features in the grid divided by the current non-overlapping area and its own area to get the first attention; Then, 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 is ​​calculated to obtain the second attention; Based on the first attention and the second attention, relevant features are obtained.

7. A meat quality evaluation method according to claim 1, characterized in that: Based on the relevant features obtained from multiple parallel transfromer networks, the freshness and quality of fresh meat are evaluated, including: 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 weighted and fused to obtain the 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.

8. 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 a texture density matrix of the fresh meat image based on a 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 area into a plurality of non-overlapping areas, and determine an input feature of each non-overlapping area; The similarity calculation module is configured to: input the input features of the non-overlapping regions corresponding to the multiple meat quality regions into the multiple parallel transfromer networks of the meat quality detection model according to the differences of 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 other regions that are most relevant to each non-overlapping region based on the adjacency relationship matrix; The attention mechanism module is configured to: use the multi-head attention mechanism of the transformer network to calculate the relevant features of each non-overlapping region and the non-overlapping region and its most relevant regions; The classification module is configured to evaluate the freshness and quality of the fresh meat based on the relevant features obtained by multiple parallel transfromer networks.

9. A computer-readable storage medium having a program stored thereon, characterized in that: When the program is executed by a processor, the steps of a meat quality evaluation method as described in any one of claims 1 to 7 are implemented.

10. An electronic device comprising a memory, a processor, and a program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps in the meat quality evaluation method as described in any one of claims 1-7 are implemented.

Citation Information

Patent Citations

  • Device for detecting beef tenderness based on color image textural features and method thereof

    CN103185731A

  • Meat quality detection system and method based on ultrasonic signals

    CN103729642A

  • Meat quality quantitative analysis and evaluation method based on three-dimensional texture characteristics

    CN110097537A

  • Product appearance defect classification method based on GLCM and CNN-Transform fusion and storage medium

    CN114494254A

  • Self-attention-based method for detecting defective area of color-textured fabric

    WO2023070911A1