ImageJ-based method for rapidly and nondestructively measuring fat content in pig muscle

By using ImageJ technology, processing pork samples with methylene blue solution and polarized light, and combining the rolling sphere algorithm and HSB color space, the problem of water film highlight interference in traditional detection methods was solved, achieving non-destructive, rapid, and accurate measurement of intramuscular fat content in pigs.

CN122048797APending Publication Date: 2026-05-15GUIZHOU FUZHIYUAN TECHNOLOGY (GROUP) CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
GUIZHOU FUZHIYUAN TECHNOLOGY (GROUP) CO LTD
Filing Date
2025-12-29
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

Existing technologies for detecting intramuscular fat content in pork mainly rely on destructive and time-consuming Soxhlet extraction or subjective manual scoring methods. Furthermore, traditional image detection cannot distinguish between the water film highlights on the surface of fresh muscle and real fat, resulting in inflated detection data and low recognition accuracy.

Method used

Using an ImageJ-based approach, the reflectivity is reduced by spraying methylene blue solution or by loading polarization components to block specular reflection. A background estimation model is constructed by combining the rolling sphere algorithm, which is then converted to the HSB color space. A threshold range is set, non-fat noise is removed, a region of interest mask is generated, and the percentage of fat content is calculated.

Benefits of technology

It achieves non-destructive, rapid, and accurate measurement of intramuscular fat content in pigs, eliminates specular reflection interference, improves detection accuracy, and avoids sample damage and subjective errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122048797A_ABST
    Figure CN122048797A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of quality detection of agricultural and livestock products, in particular to an ImageJ-based rapid nondestructive measurement method for the content of fat in pig muscle, which comprises the following steps: acquiring a fascia-removed pig longissimus dorsi sample image, and eliminating surface specular reflection interference by spraying methylene blue or loading a polarization component during acquisition. And constructing a background estimation model based on a rolling ball algorithm to execute background subtraction, and performing nonlinear stretching on a color channel to enhance the contrast of fat and muscle. The corrected image is converted to an HSB color space, pixels are screened through a three-dimensional threshold interval to generate a preliminary fat mask, and non-fat noisy points are removed by removing small-area independent connected domains; meanwhile, a sample region-of-interest mask is generated using edge detection or threshold segmentation. And the intramuscular fat content is obtained by calculating the ratio of the fat pixels to the sample pixels. Reflection and background noise interference are effectively eliminated, and objective, accurate and automatic measurement of the fat content in the pig muscle is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of agricultural and livestock product quality testing technology, and in particular to a rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ. Background Technology

[0002] Intramuscular fat content is a core indicator determining pork quality and the genetic selection of breeding pigs. However, existing detection technologies mainly rely on the destructive, time-consuming, and toxic Soxhlet extraction method, or the subjective and lacking continuous quantitative indicators manual scoring method, which is difficult to meet the high-throughput requirements of modern breeding and processing. Although computer vision technology has been gradually introduced, when detecting fresh slaughter samples, it is limited by the specular reflection interference caused by surface tissue fluid and the segmentation problem of tiny fat particles in the muscle background. Traditional image detection mostly uses RGB global threshold segmentation. Since it cannot distinguish between the water film highlights on the surface of fresh muscle and real fat, it causes the detection data to be inflated and the recognition accuracy to be low. Summary of the Invention

[0003] To overcome the above shortcomings, this invention provides a rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ. It aims to improve the problem that traditional image detection methods mostly use RGB global threshold segmentation, which cannot distinguish between the water film highlights on the surface of fresh muscle and real fat, resulting in inflated detection data and low recognition accuracy.

[0004] This invention provides the following technical solution: a rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ, comprising the following steps: S1. Obtain the original image of the longissimus dorsi muscle sample of pig with fascia removed. During acquisition, spray the sample surface with methylene blue solution to reduce reflectivity through specific adsorption, or load a polarization component in the acquisition optical path to block specular reflection light. S2. Define spherical structural elements to construct a background estimation model based on the rolling ball algorithm, fit the background grayscale surface of the original image and perform subtraction operation, and perform nonlinear stretching on the color channels to enhance the contrast between fat and muscle, generating a corrected image. S3. Convert the corrected image from RGB color space to HSB color space, set the threshold range of hue, saturation and brightness channels, filter the pixel points whose pixel values ​​fall in the three ranges of hue, saturation and brightness, and generate the original binary mask image that identifies the initial fat region. S4. Identify independent connected components in the original binary mask image, remove connected components with an area smaller than a preset threshold to remove non-fat noise points, and generate a denoised mask image. S5. Use edge detection or threshold segmentation to separate the sample region from the background region and generate a region of interest mask for the pig longissimus dorsi muscle sample. S6. Count the number of fat pixels in the denoised mask image and the number of sample pixels in the region of interest mask, and calculate the ratio of the two to obtain the percentage of intramuscular fat content.

[0005] By adopting the above technical solution, the synergy between S1 physical anti-reflection and S3 three-dimensional threshold model eliminates specular reflection highlights and accurately separates fat pixels. This improves the problem that traditional image detection mostly uses RGB global threshold segmentation, which cannot distinguish between the water film highlights on the surface of fresh muscle and real fat, resulting in inflated detection data and low recognition accuracy.

[0006] Preferably, in step S1, obtaining the original image of the porcine longissimus dorsi muscle sample with fascia removed includes: Within a predetermined time period after pig slaughter, locate the third thoracic vertebra from the bottom on the left half of the carcass; The longissimus dorsi muscle tissue is dissected posteriorly along the anterior end of the third thoracic vertebra from the bottom, and the fascia layer and subcutaneous fat layer on the surface of the longissimus dorsi muscle tissue are removed using anatomical instruments. The processed longissimus dorsi muscle tissue was vertically cut into sheet-like samples with a predetermined uniform thickness. The sheet-like sample is laid flat at the geometric center of a white background plate made of non-reflective material; Using an image acquisition device, under diffuse illumination that avoids direct light, the optical axis is adjusted to be perpendicular to the surface of the sheet-like sample to acquire and output a digital image in RGB format.

[0007] Preferably, in step S1, the step of spraying methylene blue solution onto the sample surface during acquisition to reduce reflectivity through specific adsorption, or loading a polarization component in the acquisition optical path to block specular reflection light, includes: Prepare a methylene blue aqueous solution with a preset concentration, atomize the methylene blue aqueous solution and spray it to cover the cross section of the pig longissimus dorsi muscle sample, so that the solution penetrates into the surface of the muscle fibers and is maintained for a preset time, and the light absorption properties of the dye are used to reduce the reflectivity of the muscle tissue. Alternatively, a linear polarizing filter can be installed in front of the lens of the image acquisition device, and a polarizing filter can be installed in front of the illumination source; Rotate and adjust the angle of the linear polarizing filter, observe the changes in the highlight area in the viewfinder, until the brightness value of the highlight area is lower than the preset threshold, then lock the angle of the linear polarizing filter to block the light path reflected from the mirror.

[0008] Preferably, in step S2, the step of defining the spherical structuring elements to construct a background estimation model based on the rolling ball algorithm includes: Extract the luminance components of the original image and construct a two-dimensional grayscale matrix; Define a spherical structural element in three-dimensional space, wherein the spherical structural element has a preset spherical radius; The two-dimensional grayscale matrix of the original image is regarded as a terrain surface in three-dimensional space, where the pixel grayscale value corresponds to the terrain height; Simulate the spherical structural element rolling below the terrain surface and calculate the set of highest points that the spherical structural element can reach at any position; The smooth surface generated by fitting the set of highest points is defined as the background grayscale surface.

[0009] Preferably, in step S2, generating the corrected image includes: Iterate through the pixel coordinates of the original image one by one; Obtain the original grayscale value of the current coordinate point in the original image, and the corresponding background grayscale value in the background grayscale surface; Calculate the difference between the original grayscale value and the background grayscale value, and add a preset bit depth compensation value to the difference to obtain the corrected grayscale value; Map the corrected grayscale values ​​back to the RGB color space; Separate the red-green channel component and the yellow-blue channel component in the RGB color space; The red-green channel component and the yellow-blue channel component are subjected to nonlinear contrast stretching operations to expand the dynamic range of the color distribution, and the corrected image is synthesized.

[0010] Preferably, in step S3, setting the threshold ranges for the hue, saturation, and brightness channels, and filtering pixels whose values ​​simultaneously fall within the hue, saturation, and brightness ranges, includes: Establish an HSB color space coordinate system and set the first threshold range for the hue channel, the second threshold range for the saturation channel, and the third threshold range for the brightness channel. The RGB value of each pixel in the corrected image is converted into the corresponding hue value, saturation value, and brightness value. Construct a logical discrimination function, which is used to determine whether the hue value of the current pixel falls into the first threshold range, whether the saturation value falls into the second threshold range, and whether the brightness value falls into the third threshold range; If the three conditions of hue, saturation and brightness are met at the same time, the current pixel is determined as the target pixel and assigned a logic high level. If any of the three conditions—hue, saturation, and brightness—is not met, the current pixel will be identified as a background pixel and assigned a logic low level.

[0011] Preferably, in step S3, generating the original binary mask image identifying the initial fat region includes: Create a blank bitmap matrix with the same resolution as the corrected image; The coordinates of all pixels identified as target pixels are marked as foreground colors in the blank bitmap matrix; The coordinates of all pixels identified as background pixels are marked as background colors in the blank bitmap matrix; The bitmap matrix is ​​output as a single-channel binarized image, which serves as the original binary mask image.

[0012] Preferably, in step S4, generating the denoised mask image includes: All independent connected regions in the original binary mask image are retrieved using a connected component labeling algorithm. Iterate through and calculate the total number of pixels contained in each independent connected region to obtain the area value of each connected region; The area value is compared with a preset minimum area threshold; When the area value is less than the minimum area threshold, all pixel values ​​within the independent connected region are flipped to background values. Retain independent connected regions with area values ​​greater than or equal to the minimum area threshold to generate a denoised mask image containing only effective fat particles.

[0013] Preferably, in step S5, the generation of the region of interest mask for the porcine longissimus dorsi muscle sample includes: Convert the corrected image or the original image into a grayscale image; The global segmentation threshold is calculated using the maximum inter-class variance method, and the grayscale image is segmented into a foreground sample region and a background region using the global segmentation threshold. Extract the outer contour edge of the foreground sample region; Perform morphological closing operations or hole filling algorithms on the region surrounded by the outer contour edge to fill the non-connected holes inside the sample with foreground pixels; The filled region is defined as the valid region of interest mask.

[0014] Preferably, in step S6, calculating the ratio of the two to obtain the percentage of intramuscular fat content includes: Histogram statistics are performed on the denoised mask image to obtain the total number of pixels whose grayscale value is the foreground value as the first pixel count; Histogram statistics are performed on the mask of the region of interest, and the total number of pixels with gray values ​​of the foreground value is used as the second pixel count. Calculate the quotient of the first number of pixels divided by the second number of pixels; Multiply the quotient by a percentage conversion factor to output quantified intramuscular fat percentage data.

[0015] The present invention has the following beneficial effects: 1. In this invention, the combination of S1 physical anti-reflection and S3 three-dimensional threshold model eliminates specular reflection highlights and accurately separates fat pixels, thereby improving the problem that traditional image detection mostly uses RGB global threshold segmentation, which cannot distinguish between the water film highlights on the surface of fresh muscle and real fat, resulting in falsely high detection data and low recognition accuracy.

[0016] 2. In this invention, by constructing a digital non-destructive measurement process based on background estimation, quantitative data can be obtained quickly without destroying the sample. This improves the problem that traditional determinations mostly use Soxhlet extraction, which results in a long detection cycle and irreversible sample damage due to the use of chemical reagents for long-term extraction.

[0017] 3. In this invention, by eliminating small-area independent connected domains, non-fatty interference such as microvessels and connective tissue is filtered out, thereby improving the problem that traditional visual methods mostly rely solely on color features and misclassify non-fatty tissue as fat due to ignoring morphological differences, resulting in insufficient segmentation accuracy.

[0018] 4. In this invention, by generating a mask of the region of interest and calculating the pixel ratio, an objective quantitative analysis based on the physical area ratio is realized. This improves the problem that traditional marble texture scoring methods mostly rely on manual visual comparison, and the evaluation results are easily affected by personnel experience and environment, resulting in large subjective errors and a lack of continuous indicators. Attached Figure Description

[0019] Figure 1 The flowchart shows the rapid and non-destructive measurement method for intramuscular fat content in pigs based on ImageJ proposed in this invention. Figure 2 This is a flowchart of the rapid and non-destructive measurement method for intramuscular fat content in pigs based on ImageJ proposed in this invention. Figure 3 This is an image acquisition architecture diagram of the rapid and non-destructive measurement method for intramuscular fat content in pigs based on ImageJ proposed in this invention. Figure 4 The HSB color threshold and fat recognition map of the rapid and non-destructive measurement method of intramuscular fat content in pigs based on ImageJ proposed in this invention; Figure 5 This is a comparison chart of the measurement and verification values ​​of the rapid and non-destructive measurement method for intramuscular fat content in pigs based on ImageJ proposed in this invention. Detailed Implementation

[0020] The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0021] Example 1: In the first embodiment of the present invention, the present invention provides a rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ, such as... Figures 1-5 As shown, it includes the following steps: S1. Obtain the original image of the longissimus dorsi muscle sample of pig with fascia removed. During acquisition, spray the sample surface with methylene blue solution to reduce reflectivity through specific adsorption, or load a polarization component in the acquisition optical path to block specular reflection light. Furthermore, in step S1, obtaining the original image of the porcine longissimus dorsi muscle sample with fascia removed includes: Within a predetermined time period after pig slaughter, locate the third thoracic vertebra from the bottom on the left half of the carcass; The longissimus dorsi muscle tissue was dissected posteriorly from the anterior end of the third thoracic vertebra from the bottom, and the fascia layer and subcutaneous fat layer on the surface of the longissimus dorsi muscle tissue were removed using anatomical instruments. The processed longissimus dorsi muscle tissue was vertically cut into sheet-like samples with a predetermined uniform thickness. Place the sheet sample flat at the geometric center of a white background plate made of non-reflective material; Using an image acquisition device, under diffuse illumination that avoids direct light, the optical axis is adjusted to be perpendicular to the surface of the sheet sample to acquire and output a digital image in RGB format.

[0022] In step S1, during acquisition, spraying methylene blue solution onto the sample surface utilizes specific adsorption to reduce reflectivity, or loading a polarization component into the acquisition optical path to block specular reflection light includes: Prepare a methylene blue aqueous solution with a preset concentration, atomize the methylene blue aqueous solution and spray it to cover the cross section of the longissimus dorsi muscle sample, so that the solution penetrates into the surface of the muscle fibers and is maintained for a preset time, and the reflectivity of the muscle tissue is reduced by utilizing the light absorption properties of the dye. Alternatively, a linear polarizing filter can be installed in front of the lens of the image acquisition device, and a polarizing filter can be installed in front of the illumination source; Rotate and adjust the angle of the linear polarizing filter, observe the changes in the highlight area in the viewfinder, until the brightness value of the highlight area is lower than the preset threshold, then lock the angle of the linear polarizing filter to block the light path reflected from the mirror.

[0023] Specifically, the third thoracic vertebra from the bottom of the left half of the torso was chosen as the sampling reference point because the longissimus dorsi muscle in this area has a large cross-sectional area and the intramuscular fat distribution is representative. Removing the surface fascia and subcutaneous fat layers is to eliminate high reflectivity interference from non-target tissues. The fascia layer appears as a bright white highlight under illumination; if not removed, fascia pixels will be misidentified as intramuscular fat pixels by the algorithm during subsequent image binarization, leading to an overestimation of the fat area. Vertically cutting the samples to a preset uniform thickness ensures consistent surface flatness when placed on the background, avoiding depth-of-field deviations or localized shadows caused by uneven thickness.

[0024] A white background with a non-reflective material forms a high grayscale peak in the image histogram, creating a significant bimodal distribution with the red muscle region. This facilitates rapid separation of sample regions by subsequent algorithms using thresholding. The diffuse lighting environment, combined with shooting along the perpendicular optical axis, eliminates shadows cast by the tilted light source angle, ensuring that the brightness of each pixel in the image depends primarily on the reflectivity of the object's surface, rather than its geometric location.

[0025] Fresh muscle sections contain a large amount of tissue fluid and blood, forming a smooth, specular reflective layer. Specular light does not carry information about the muscle's internal texture, and its high intensity obscures the characteristics of fat particles.

[0026] Methylene blue is a cationic dye that specifically adsorbs onto proteins in muscle fibers, but has no affinity for fat particles composed of triglycerides. After spraying with a 0.5% concentration solution, the muscle fibers absorb the dye and turn deep blue, reducing the spectral reflectance of the muscle region. Fat particles retain their original color or are only slightly stained, with high reflectivity. The change is small. According to Weber's contrast formula, image contrast... Enhanced: Among them, with The reduction in contrast Increased, resulting in increased saturation components in the subsequent HSB color space and brightness component Increased differences improve segmentation accuracy.

[0027] This technology utilizes the polarization properties of light. A polarizer in front of the light source converts unpolarized light into linearly polarized light. When linearly polarized light strikes the moist muscle surface and undergoes specular reflection, the reflected light retains its original polarization direction; however, light that enters the muscle tissue and undergoes diffuse reflection is depolarized due to multiple scattering. By rotating the linearly polarizing filter in front of the lens to an angle orthogonal to the polarization direction of the light source, the specularly reflected linearly polarized light is blocked, while the depolarized diffuse reflection partially passes through the lens. Let the light intensity entering the camera be... The specular reflection component is The diffuse reflection component is At this time, the input relationship of the imaging system is: ; ; This process physically removes the highlight noise caused by the water film, preserving the true muscle and fat texture information.

[0028] The input for this step is a physical sample of pork. The output is a digitized RGB image matrix. The process is defined as follows: Input sample [Physical Pretreatment: Staining / Polarization] [Optical Imaging: Diffuse Reflection + Vertical Optical Path] Photoelectric conversion Output the original image The output image Each pixel in It contains brightness values ​​from three channels, namely This provides a high signal-to-noise ratio data foundation for background correction in the subsequent S2 step.

[0029] S2. Define spherical structural elements to construct a background estimation model based on the rolling ball algorithm, fit the background grayscale surface of the original image and perform subtraction operation, and perform nonlinear stretching on the color channels to enhance the contrast between fat and muscle, generating a corrected image. Furthermore, in step S2, defining the spherical structuring elements to construct a background estimation model based on the rolling ball algorithm includes: Extract the luminance component of the original image and construct a two-dimensional grayscale matrix; Define a sphere structural element in three-dimensional space, which has a preset sphere radius; The two-dimensional grayscale matrix of the original image is regarded as a terrain surface in three-dimensional space, where the pixel grayscale value corresponds to the terrain height; Simulate the rolling operation of a spherical structural element below a terrain surface and calculate the set of highest points that the spherical structural element can reach at any position; The smooth surface generated by fitting the set of highest points is defined as the background grayscale surface.

[0030] In step S2, generating the corrected image includes: Iterate through the pixel coordinates of the original image one by one; Get the original grayscale value of the current coordinate point in the original image, and the corresponding background grayscale value in the background grayscale surface; Calculate the difference between the original grayscale value and the background grayscale value, and add the difference to the preset bit depth compensation value to obtain the corrected grayscale value; Map the corrected grayscale values ​​back to the RGB color space; Separate the red-green channel components and the yellow-blue channel components in the RGB color space; Nonlinear contrast stretching operations are performed on the red-green channel components and the yellow-blue channel components respectively to expand the dynamic range of the color distribution and synthesize the corrected image.

[0031] Specifically, this step utilizes grayscale morphology principles to address the problem of uneven illumination. The brightness distribution of the original image typically contains low-frequency background illumination components and high-frequency target texture components. The two-dimensional grayscale matrix... Mapped to a three-dimensional topological surface, where coordinates Represents spatial location, pixel grayscale value Represents terrain height. Defined spherical structural element. With a preset radius The radius The value ranges from 50 to 100 pixels. When the sphere rolls beneath the terrain surface, due to the curvature of the sphere, it cannot enter the trough region narrower than its diameter, which contains high-frequency fat texture details. The envelope formed by the highest point of the sphere constitutes the background grayscale surface. This process is mathematically equivalent to performing a grayscale morphological opening operation on an image function, and its mathematical model is expressed as follows: ; in The calculated background grayscale value, The grayscale function of the original image. The neighborhood defined for the projection of the sphere. Let be the radius of the sphere. These are relative coordinate variables within the neighborhood. This algorithm geometrically separates slowly changing background lighting from rapidly changing target features.

[0032] Additive illumination noise is eliminated through background subtraction, ensuring a consistent brightness baseline across all areas of the image. Since direct subtraction may result in negative value overflow, a bit depth compensation value is introduced. The corrected grayscale value is shown below. Calculation formula: ;in This is a preset bit depth compensation constant, typically set to 128 or according to the bit depth, ensuring that the output grayscale values ​​fall within the effective dynamic range. This operation flattens the image background and highlights the morphological features of intramuscular fat.

[0033] In pork samples, fat appears yellowish-white, while muscle appears red. In the RGB color space, the two are highly correlated. However, in the Lab color space or similar contrasting color spaces, the red-green component (a channel) and the yellow-blue component (b channel) can more effectively separate the spectral features of fat and muscle.3 After mapping the image to this color space, the separated red-green channel components... With yellow-blue channel components The distribution range is relatively narrow. A non-linear contrast stretching operation is performed to expand the grayscale histogram distribution of the region of interest. This is applied to the channel components. Its mapping function Defined as: ; in For input channel values, This is the output value after stretching. The gain coefficient is used to control the contrast slope. The value is the center value of the intensity. This represents the maximum dynamic range of the channel. This operation increases the Euclidean distance between fat and muscle pixels in the color vector space, enabling subsequent threshold-based segmentation algorithms to distinguish between these two tissue types with higher accuracy.

[0034] The data input for this step is the original RGB image containing the illumination gradient, which is the output of step S1. The data processing flow is as follows: original image →[Brightness Extraction]→2D Gray Scale Matrix→[Rolling Ball Morphological Filtering]→Background Surface →[Subtraction + Compensation]→Brightness Flattening →[Color Space Mapping]→[Channel Separation]→[Non-linear Stretching]→Compositing. The final output of this step is a corrected image with uniform background brightness and enhanced color contrast. This serves as the input data for HSB threshold segmentation in step S3.

[0035] S3. Convert the corrected image from RGB color space to HSB color space, set the threshold range for hue, saturation and brightness channels, filter pixels whose pixel values ​​fall within the three ranges of hue, saturation and brightness, and generate the original binary mask image that identifies the initial fat region. Furthermore, in step S3, threshold ranges are set for the hue, saturation, and brightness channels, and pixels whose values ​​simultaneously fall within these three ranges are selected, including: Establish an HSB color space coordinate system and set the first threshold range for the hue channel, the second threshold range for the saturation channel, and the third threshold range for the brightness channel. Convert the RGB value of each pixel in the corrected image into its corresponding hue, saturation, and brightness values; Construct a logical discrimination function to determine whether the hue value of the current pixel falls into the first threshold range, the saturation value falls into the second threshold range, and the brightness value falls into the third threshold range; If the three conditions of hue, saturation and brightness are met at the same time, the current pixel is determined as the target pixel and assigned a logic high level. If any of the three conditions—hue, saturation, and brightness—is not met, the current pixel will be identified as a background pixel and assigned a logic low level.

[0036] In step S3, generating the original binary mask image that identifies the initial fat region includes: Create a blank bitmap matrix with the same resolution as the corrected image; Mark the coordinates of all pixels identified as target pixels in the blank bitmap matrix as the foreground color; Mark the coordinates of all pixels identified as background pixels in the blank bitmap matrix as the background color; The bitmap matrix is ​​output as a single-channel binarized image, which serves as the original binary mask image.

[0037] Specifically, in the RGB color space, the brightness and chromaticity information of the corrected image are highly coupled. Even small changes in light intensity can cause nonlinear fluctuations in the R, G, and B components simultaneously, leading to misclassification of intramuscular fat in pork by color-based segmentation algorithms. The HSB model decomposes color information into hue.

[0038] saturation and brightness The transformation employs three orthogonal components. The hue component reflects the inherent color attribute of a pixel, representing the fundamental spectral difference between the yellowish-white of pork fat and the red of muscle. The saturation component reflects color purity and is used to eliminate reflective points or light-colored impurities. The luminance component reflects light intensity and is used to distinguish shadows from objects. This transformation converts the complex color segmentation problem into a geometric region determination problem in three-dimensional space.

[0039] Let any pixel in the corrected image The RGB components are Normalized to interval ,make , , The mathematical model for RGB to HSB conversion is as follows: Brightness Defined as: ; Saturation Defined as: ; Hue Defined as: ; In the above formula Characterizes pixel brightness. Indicating the vibrancy of colors, It represents the angular position on the color wheel.

[0040] This step utilizes the specific distribution patterns of porcine intramuscular fat in the HSB space to construct a classifier. Adipose tissue exhibits a specific yellowish-white hue, medium to high saturation, and high brightness, while muscle tissue has a reddish hue and lower brightness. The hue threshold range is defined as follows: The saturation threshold range is The brightness threshold range is Construct a logical discriminant function. For coordinates in the image The feature vector of the pixel is: Decision logic: ;in This is an indicator function; it takes the value 1 when the condition is met, and 0 otherwise. This function represents a logical AND operation. It ensures that a pixel is identified as a fat target pixel only when all three components of the pixel fall within their respective set threshold ranges, effectively eliminating background noise interference caused by single-channel segmentation.

[0041] The original binary mask image is a digital mapping of the target region. This is achieved by creating a bitmap matrix with the same resolution as the original image. , the logical discriminant function The output is directly mapped to this matrix: ; In the matrix, regions with a value of 1 correspond to a high logic level in the image, i.e., the foreground fat region; regions with a value of 0 correspond to a low logic level, i.e., the background muscle and environment region. This step achieves dimensionality reduction from multidimensional color data to single-dimensional structural data, providing a standardized data format for subsequent morphological denoising and area integration.

[0042] The input data for this step is the illumination homogenization correction image output from step S2. The data processing flow is as follows: Input →[Color Space Nonlinear Transformation]→Eigenvector Matrix →[3D Threshold Comparison]→Logic State Matrix→[Bitmap Mapping]→Output. The output data of this step is the original binary mask image. .

[0043] S4. Identify independent connected components in the original binary mask image, remove connected components with an area smaller than a preset threshold to remove non-fat noise, and generate a denoised mask image. Furthermore, in step S4, generating the denoised mask image includes: The connected component labeling algorithm is used to retrieve all independent connected regions in the original binary mask image; Iterate through and calculate the total number of pixels contained in each independent connected region to obtain the area value of each connected region; Compare the area value with a preset minimum area threshold; When the area value is less than the minimum area threshold, all pixel values ​​within the independent connected region are flipped to the background value. Retain independent connected regions with area values ​​greater than or equal to the minimum area threshold to generate a denoised mask image containing only effective fat particles.

[0044] Specifically, the original binary mask image contains two types of foreground objects: real intramuscular fat particles and non-fat noise. Non-fat noise mainly originates from reflective points on muscle fiber cross-sections, microvascular cross-sections, and connective tissue fragments, characterized by discrete spatial distribution and small geometric area. A connected component labeling algorithm is used to combine discrete pixels into independent objects with topological meaning. Let the binary image be... For any two foreground pixels and If there exists a path consisting entirely of foreground pixels... and If the two pixels belong to the same connected component, then they are determined to be connected components. The algorithm traverses the image matrix and assigns a unique label index to all pixels belonging to the same connected component according to the 8-neighbor or 4-neighbor connectivity rule. The generated label matrix Defined as: ;in This represents the total number of independent connected regions in the image, with background pixels marked as 0.

[0045] This step utilizes differences in geometric features to separate noise. Fat particles typically exhibit a large-area aggregated state, while noise exhibits a small-area discrete state. For each labeled... Independent connected regions Its area Defined as the total number of pixels contained within the region. The calculation formula is: ; in Let Kronecker function be used when The value is 1 if the condition is met, and 0 otherwise. Preset minimum area threshold. This threshold is set based on the scale calibration coefficient and the statistical characteristics of the noise, typically corresponding to a circular area with a radius of 2 pixels or directly set to 50 pixels. A denoising filter function is then constructed. For each connected region, perform a binary classification decision: ; in This is the output denoised mask image. This operation preserves the true fat morphology while forcibly flipping the pixel values ​​of noise regions with an area smaller than a threshold to the background value of 0, thus achieving morphological-based spatial filtering.

[0046] The input data for this step is the original binary mask image containing noise, which is the output of step S3. The data processing flow is as follows: Input →[Neighborhood Connectivity Analysis]→Label Matrix →[Histogram Statistics]→Area Feature Vector →[Threshold Comparison Logic]→Pixel State Flip→Output. The output data of this step is the denoised mask image. The image contains only statistically significant effective fat particles, serving as the molecular data source for the final fat content calculation in step S6.

[0047] S5. Use edge detection or threshold segmentation to separate the sample region from the background region and generate a region of interest mask for the pig longissimus dorsi muscle sample. Furthermore, in step S5, generating the region of interest mask for the porcine longissimus dorsi muscle sample includes: Convert the corrected image or the original image to a grayscale image; The global segmentation threshold is calculated using the maximum inter-class variance method, and the grayscale image is segmented into foreground sample region and background plate region using the global segmentation threshold. Extract the outer contour edge of the foreground sample region; Perform morphological closing operations or hole filling algorithms on regions surrounded by outer contour edges to fill non-connected holes located inside the sample with foreground pixels; The filled region is defined as the valid region of interest mask.

[0048] Specifically, this step utilizes the statistical differences in grayscale distribution between the sample and the background to achieve automatic segmentation. The white background appears as a high-brightness peak distribution in the grayscale histogram, while the pig longissimus dorsi muscle sample appears as a medium-to-low brightness distribution. The Otsu's algorithm, also known as the maximum inter-class variance method, finds the optimal threshold by traversing the grayscale levels, maximizing the variance between the segmented foreground and background classes. Let the grayscale range of the image be 0 to... The total number of pixels is For any threshold Images are categorized into background classes. and foreground .definition The probability of occurrence is The average gray level is ; The probability of occurrence is The average gray level is Between-class variance The calculation formula is: ; Optimal global segmentation threshold To maximize the inter-class variance value: ; Apply this threshold The image is binarized to generate a preliminary binary mask, which separates the sample area from the background area at the pixel level.

[0049] The initial binary mask may contain holes located inside the sample. These holes originate from localized high-brightness reflections or extremely pale areas on the sample surface, causing their grayscale values ​​to exceed the threshold. This is misclassified as background. The hole-filling algorithm ensures the topological integrity of the region of interest (ROI), preventing omissions when calculating the total sample area. Morphological closing operations consist of a series of dilation and erosion operations. Let the initial binary mask be... The structural element is Closing operation Defined as: ;in This represents the expansion operation. The erosion operation represents the process of filling in small holes inside the foreground object and connecting adjacent fractured areas. The erosion operation restores the original dimensions of the object's outer contour. The hole-filling algorithm is based on connected component retrieval, identifying all background connected components surrounded by foreground pixels and flipping the pixel values ​​of these connected components to foreground values. The final generated mask covers the entire physical area of ​​the sample.

[0050] The input data for this step is the corrected image output from step S2. Or the original image output in step S1 The data processing flow is as follows: Input image → [Grayscale conversion] → Grayscale matrix → [Histogram statistics] → [Otsu threshold calculation] → Preliminary segmentation mask → [Contour extraction] → [Closing / filling] → Output. The output data of this step is the region of interest mask. The sample area pixels are marked as 1 and the background area pixels are marked as 0, which serve as the denominator data source for calculating fat content in step S6.

[0051] S6. Count the number of fat pixels in the denoised mask image and the number of sample pixels in the region of interest mask, and calculate the ratio of the two to obtain the percentage of intramuscular fat content. Furthermore, in step S6, calculating the ratio of the two to obtain the percentage of intramuscular fat content includes: Histogram statistics are performed on the denoised mask image, and the total number of pixels with grayscale values ​​of foreground values ​​is used as the first pixel count; Histogram statistics are performed on the mask of the region of interest, and the total number of pixels with grayscale values ​​of foreground values ​​is used as the second pixel count. Calculate the quotient of the number of first pixels divided by the number of second pixels; Multiply the quotient by a percentage conversion factor to output quantified intramuscular fat percentage data.

[0052] Specifically, this step aims to transform geometric information at the image segmentation level into quantitative indicators at the physical level. In digital images, when the sample slice thickness is uniform and the imaging plane is parallel to the sample plane, the number of pixels in the image is linearly positively correlated with the physical surface area. Therefore, the area percentage of intramuscular fat content... This can be characterized by calculating the ratio of the number of pixels in the fat region to the total number of pixels in the sample region. This method avoids the cumbersome process of physically weighing the sample required in traditional chemical detection, and achieves direct quantification based on visual data.

[0053] Histogram analysis of binary images is an efficient algorithm for obtaining the number of pixels at a specific gray level. For a binary mask with a bit depth of 1, the gray-level histogram contains only two intervals, corresponding to a background value of 0 and a foreground value of 1. Let the denoising mask image be... The region of interest mask is... The image domain is The number of first pixels is the total number of fat pixels. The result is obtained by integral calculation of the denoised mask image: The second pixel count is the total number of sample pixels. The following results were obtained by integrating the mask over the region of interest: ;in For pixel coordinates. Percentage of intramuscular fat content. The calculation formula is defined as follows: ; in To count the total number of effective fat particles, This represents the total number of pixels in the sample region of the longissimus dorsi muscle of pigs obtained through statistical analysis. This is the percentage conversion factor, with a value of 100. The formula outputs a dimensionless percentage value, reflecting the distribution density of adipose tissue on the sample section.

[0054] The input data for this step includes two independent data sources: the denoised mask image output from step S4. and the region of interest mask output from step S5 The data processing flow is as follows: Input mask and →[Histogram Traversal / Matrix Summation]→Extract Foreground Pixel Count Values and →[Division]→Area Ratio Coefficient→[Multiplication]→Output. The output data of this step is the final quantitative indicator: percentage of intramuscular fat content. This data can be directly used for pork quality grading or breeding screening and evaluation.

[0055] Example 2: In the quality inspection workshops of modern pig breeding bases or large-scale slaughtering and processing enterprises, technicians need to perform meat quality trait tests on the left half of the pig carcass within 40 minutes after slaughter to screen for high-quality individuals with high intramuscular fat content. In the assembly line environment, quality inspectors take fresh slices of the longissimus dorsi muscle from the third thoracic vertebra from the bottom. The sample surface is covered with a moist film composed of tissue fluid and blood. The inspectors place the sample on a standard white background and use an image acquisition terminal equipped with the technical solution of this invention to capture images. The aim is to obtain accurate fat content percentage data within minutes without damaging the physical integrity of the sample, serving as a key quantitative basis for genetic evaluation of breeding pigs or grading of commercial meat.

[0056] In this application scenario, the main problems faced by existing technologies are as follows: The surface of freshly slaughtered muscle samples contains irregular water films and tissue fluid, which produce strong specular reflections during optical imaging, resulting in a large number of high-brightness non-fat noise spots in the image. Traditional RGB thresholding algorithms struggle to distinguish these from real white fat particles, leading to inflated detection data. Simultaneously, due to the low color contrast between muscle tissue and intramuscular fat in the visible light band, simple grayscale processing or global thresholding methods cannot accurately define the boundary between fat and connective tissue. Furthermore, while the traditional Soxhlet extraction method is accurate, it requires sample destruction and takes over 24 hours; the artificial marbling scoring method has large subjective errors and lacks continuous quantitative indicators. These shortcomings collectively prevent existing technologies from meeting the practical needs of rapid, non-destructive, and high-precision detection of intramuscular fat content in industrial settings. To address these problems, this invention provides a rapid and non-destructive measurement method for porcine intramuscular fat content based on ImageJ, the structure of which is as follows... Figure 1 As shown. The specific implementation process of this method is as follows: Freshly slaughtered pig longissimus dorsi muscle samples are covered with a liquid film composed of tissue fluid and blood, which produces a high-brightness specular reflection area during optical imaging. Methylene blue solution, as a cationic dye, specifically binds to proteins on muscle fibers, giving them a deep blue color, while having no staining effect on fat particles, whose main component is triglycerides. This differential staining reduces the spectral reflectance of the muscle background, increasing the contrast between fat and muscle in the visible light band. The polarization component scheme utilizes the wave properties of light. A polarizer is placed in front of the light source to generate linearly polarized light, and an analyzer is placed in front of the lens to block specular reflection light that maintains its original polarization state, allowing only diffuse reflection light that has undergone depolarization after multiple scatterings within the muscle to pass through. These physical processing methods eliminate highlight noise in the image, preventing subsequent algorithms from misclassifying bright reflective areas as fat pixels and ensuring the signal-to-noise ratio of the input data.

[0057] Original images often suffer from uneven illumination due to variations in light source distribution or minute surface undulations. The rolling sphere algorithm treats a 2D grayscale image as a 3D topological surface, simulating morphological opening operations on the surface using spherical structural elements of a preset radius. The troughs that the sphere cannot reach represent high-frequency target textures, while the envelope formed by the rolling sphere represents the low-frequency background surface. By subtracting the background surface and compensating for the brightness bit depth, the illumination gradient is corrected, making the baseline brightness of each region of the image more consistent. The nonlinear stretching operation expands the histogram distribution of the color channels, increasing the Euclidean distance between fat and muscle pixels in the color vector space, resulting in higher signal-level separation and providing clear boundary conditions for thresholding.

[0058] In the RGB color space, the luminance and chrominance components are highly coupled, making them susceptible to interference from changes in luminance. Converting to the HSB color space decouples luminance and chrominance information. Preset hue, saturation, and luminance threshold ranges constitute a three-dimensional logical classifier. This classifier classifies pixels point-by-point based on the specific spectral characteristics of porcine intramuscular fat, namely, specific yellowish-white tones, medium-to-high saturation, and high luminance attributes. Only when the three-dimensional feature vectors of a pixel simultaneously fall within the set range is it labeled as a fat target. This multi-dimensional constraint mechanism effectively eliminates background interference with similar single-color features but not fat, generating binary data that accurately describes the distribution pattern of fat.

[0059] The original binary mask often contains non-fat noise such as microvascular cross-sections and connective tissue fragments. These noises morphologically appear as discrete connected regions with small areas. The connected component labeling algorithm constructs the topological structure of the image, enabling the quantification and identification of the pixel area of ​​each independent region. By setting a minimum area threshold to construct a spatial filter, the system forcibly filters out isolated spots with areas smaller than the threshold, retaining only statistically significant fat particle regions. This step corrects the segmentation redundancy caused by the complexity of biological tissues, ensuring that the retained mask regions truly represent intramuscular adipose tissue.

[0060] Calculating the percentage fat content requires establishing the total physical area of ​​the sample as the denominator. A white background panel forms a distinct highlight peak in the grayscale histogram, creating a bimodal distribution with the sample area. The Otsu's method automatically finds the optimal segmentation threshold using statistical principles to separate the foreground sample from the background panel. Morphological closing operations are then used to fill in holes inside the sample caused by highlights or light colors, constructing a complete sample contour mask. This step defines an effective statistical range, eliminates interference from background pixels in the content calculation, and ensures the accuracy of the quantitative calculation benchmark.

[0061] This method transforms geometric information at the image level into quantitative indicators at the physical level. Under the premise of uniform sample thickness and vertical shooting, the number of pixels is linearly positively correlated with the physical area. Histogram statistics are used to obtain the total number of fat pixels in the denoising mask and the total number of sample pixels in the region of interest mask, and the ratio of these two values ​​directly represents the area ratio of intramuscular fat. This calculation method avoids the cumbersome physical weighing and extraction processes in chemical testing, providing objective and quantifiable meat quality testing data.

[0062] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ, characterized in that, Includes the following steps: S1. Obtain the original image of the longissimus dorsi muscle sample of pig with fascia removed. During acquisition, spray the sample surface with methylene blue solution to reduce reflectivity through specific adsorption, or load a polarization component in the acquisition optical path to block specular reflection light. S2. Define spherical structural elements to construct a background estimation model based on the rolling ball algorithm, fit the background grayscale surface of the original image and perform subtraction operation, and perform nonlinear stretching on the color channels to enhance the contrast between fat and muscle, generating a corrected image. S3. Convert the corrected image from RGB color space to HSB color space, set the threshold range of hue, saturation and brightness channels, filter the pixel points whose pixel values ​​fall in the three ranges of hue, saturation and brightness, and generate the original binary mask image that identifies the initial fat region. S4. Identify independent connected components in the original binary mask image, remove connected components with an area smaller than a preset threshold to remove non-fat noise points, and generate a denoised mask image. S5. Use edge detection or threshold segmentation to separate the sample region from the background region and generate a region of interest mask for the pig longissimus dorsi muscle sample. S6. Count the number of fat pixels in the denoised mask image and the number of sample pixels in the region of interest mask, and calculate the ratio of the two to obtain the percentage of intramuscular fat content.

2. The rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ according to claim 1, characterized in that, In step S1, obtaining the original image of the porcine longissimus dorsi muscle sample after fascia removal includes: Within a predetermined time period after pig slaughter, locate the third thoracic vertebra from the bottom on the left half of the carcass; The longissimus dorsi muscle tissue is dissected posteriorly along the anterior end of the third thoracic vertebra from the bottom, and the fascia layer and subcutaneous fat layer on the surface of the longissimus dorsi muscle tissue are removed using anatomical instruments. The processed longissimus dorsi muscle tissue was vertically cut into sheet-like samples with a predetermined uniform thickness. The sheet-like sample is laid flat at the geometric center of a white background plate made of non-reflective material; Using an image acquisition device, under diffuse illumination that avoids direct light, the optical axis is adjusted to be perpendicular to the surface of the sheet-like sample to acquire and output a digital image in RGB format.

3. The rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ according to claim 1, characterized in that, In step S1, the steps of spraying methylene blue solution onto the sample surface during acquisition to reduce reflectivity through specific adsorption, or loading a polarization component in the acquisition optical path to block specular reflection light, include: Prepare a methylene blue aqueous solution with a preset concentration, atomize the methylene blue aqueous solution and spray it to cover the cross section of the pig longissimus dorsi muscle sample, so that the solution penetrates into the surface of the muscle fibers and is maintained for a preset time, and the light absorption properties of the dye are used to reduce the reflectivity of the muscle tissue. Alternatively, a linear polarizing filter can be installed in front of the lens of the image acquisition device, and a polarizing filter can be installed in front of the illumination source; Rotate and adjust the angle of the linear polarizing filter, observe the changes in the highlight area in the viewfinder, until the brightness value of the highlight area is lower than the preset threshold, then lock the angle of the linear polarizing filter to block the light path reflected from the mirror.

4. The rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ according to claim 1, characterized in that, In step S2, defining the spherical structuring elements to construct the background estimation model based on the rolling ball algorithm includes: Extract the luminance components of the original image and construct a two-dimensional grayscale matrix; Define a spherical structural element in three-dimensional space, wherein the spherical structural element has a preset spherical radius; The two-dimensional grayscale matrix of the original image is regarded as a terrain surface in three-dimensional space, where the pixel grayscale value corresponds to the terrain height; Simulate the spherical structural element rolling below the terrain surface and calculate the set of highest points that the spherical structural element can reach at any position; The smooth surface generated by fitting the set of highest points is defined as the background grayscale surface.

5. The rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ according to claim 1, characterized in that, In step S2, generating the corrected image includes: Iterate through the pixel coordinates of the original image one by one; Obtain the original grayscale value of the current coordinate point in the original image, and the corresponding background grayscale value in the background grayscale surface; Calculate the difference between the original grayscale value and the background grayscale value, and add a preset bit depth compensation value to the difference to obtain the corrected grayscale value; Map the corrected grayscale values ​​back to the RGB color space; Separate the red-green channel component and the yellow-blue channel component in the RGB color space; The red-green channel component and the yellow-blue channel component are subjected to nonlinear contrast stretching operations to expand the dynamic range of the color distribution, and the corrected image is synthesized.

6. The rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ according to claim 1, characterized in that, In step S3, setting the threshold ranges for the hue, saturation, and brightness channels, and filtering pixels whose values ​​simultaneously fall within the hue, saturation, and brightness ranges, includes: Establish an HSB color space coordinate system and set the first threshold range for the hue channel, the second threshold range for the saturation channel, and the third threshold range for the brightness channel. The RGB value of each pixel in the corrected image is converted into the corresponding hue value, saturation value, and brightness value. Construct a logical discrimination function, which is used to determine whether the hue value of the current pixel falls into the first threshold range, whether the saturation value falls into the second threshold range, and whether the brightness value falls into the third threshold range; If the three conditions of hue, saturation and brightness are met at the same time, the current pixel is determined as the target pixel and assigned a logic high level. If any of the three conditions—hue, saturation, and brightness—is not met, the current pixel will be identified as a background pixel and assigned a logic low level.

7. The rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ according to claim 1, characterized in that, In step S3, generating the original binary mask image identifying the initial fat region includes: Create a blank bitmap matrix with the same resolution as the corrected image; The coordinates of all pixels identified as target pixels are marked as foreground colors in the blank bitmap matrix; The coordinates of all pixels identified as background pixels are marked as background colors in the blank bitmap matrix; The bitmap matrix is ​​output as a single-channel binarized image, which serves as the original binary mask image.

8. The rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ according to claim 1, characterized in that, In step S4, generating the denoised mask image includes: All independent connected regions in the original binary mask image are retrieved using a connected component labeling algorithm. Iterate through and calculate the total number of pixels contained in each independent connected region to obtain the area value of each connected region; The area value is compared with a preset minimum area threshold; When the area value is less than the minimum area threshold, all pixel values ​​within the independent connected region are flipped to background values. Retain independent connected regions with area values ​​greater than or equal to the minimum area threshold to generate a denoised mask image containing only effective fat particles.

9. The rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ according to claim 1, characterized in that, In step S5, the region of interest mask for generating the porcine longissimus dorsi muscle sample includes: Convert the corrected image or the original image into a grayscale image; The global segmentation threshold is calculated using the maximum inter-class variance method, and the grayscale image is segmented into a foreground sample region and a background region using the global segmentation threshold. Extract the outer contour edge of the foreground sample region; Perform morphological closing operations or hole filling algorithms on the region surrounded by the outer contour edge to fill the non-connected holes inside the sample with foreground pixels; The filled region is defined as the valid region of interest mask.

10. The rapid and non-destructive method for measuring intramuscular fat content in pigs based on ImageJ according to claim 1, characterized in that, In step S6, calculating the ratio of the two to obtain the percentage of intramuscular fat content includes: Histogram statistics are performed on the denoised mask image to obtain the total number of pixels whose grayscale value is the foreground value as the first pixel count; Histogram statistics are performed on the mask of the region of interest, and the total number of pixels with gray values ​​of the foreground value is used as the second pixel count. Calculate the quotient of the first number of pixels divided by the second number of pixels; Multiply the quotient by a percentage conversion factor to output quantified intramuscular fat percentage data.