Magnesium sulfate weight increment detection method based on intelligent sensor

By dynamically monitoring the weight gain of magnesium sulfate using intelligent sensor technology, the problem of inaccurate judgment by human eyes is solved, enabling precise analysis of the color development process and improving the reliability of the results.

CN121544561APending Publication Date: 2026-02-17青海省药品审评核查中心(青海省疫苗检查中心) +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511714514.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-21
Publication Date
2026-02-17

AI Technical Summary

Technical Problem

Existing methods for detecting magnesium sulfate weight gain rely on manual visual judgment, which makes it difficult to make a clear judgment when the color development edge is blurred or the background interference is obvious. They also lack the ability to dynamically monitor the color development process and cannot identify the trend of color intensity change and time evolution characteristics, resulting in inconsistent test results.

Method used

A detection method based on intelligent sensors is adopted. Iodine test paper images are acquired under two-band illumination through image acquisition, and three-channel difference calculation and grayscale correction are performed to generate a reflected light difference image. The color development boundary is tracked and the brightness evolution layer is reconstructed. The color development process is dynamically monitored and the magnesium sulfate weight gain detection result is output.

Benefits of technology

It enables precise identification and positioning of the color development area, improves the stability and reliability of detection, and can accurately determine the weight gain of magnesium sulfate in cases of blurred color development or complex background.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121544561A_ABST
    Figure CN121544561A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image analysis and detection, in particular to a magnesium sulfate weight increment detection method based on an intelligent sensor, which comprises the following steps of: acquiring a dual-band image and generating a pixel difference image, segmenting the image and correcting the gray scale, extracting an edge gray scale difference and tracking a change sequence, calculating a continuous frame brightness difference and screening a sudden change region; and extracting edge fluctuations, uniformly coloring and superposing backgrounds, comparing structure changes, stroking and merging to an original image, and outputting a magnesium sulfate weight increment detection result. According to the invention, the continuous quantitative expression and spatial structure reconstruction of the color development process are realized by constructing the pixel gray difference map under the dual-band illumination and combining the regional center difference to extract the local brightness feature, superposing the edge gray change to construct the closed boundary, dynamically tracking the brightness change path and marking the abrupt change region; the identification precision and the positioning capability of the color difference area are improved, and the detection stability and the result reliability under the condition of blurred color development or complex background are enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image analysis and detection technology, and in particular to a method for detecting magnesium sulfate weight gain based on intelligent sensors. Background Technology

[0002] Image analysis and detection technology involves using image acquisition, image processing, and image recognition to extract features, recognize patterns, and analyze targets. It is widely applied in medical diagnosis, quality control, safety monitoring, agricultural inspection, and other fields. Core aspects of this technology include optical imaging-based image acquisition methods, image preprocessing methods such as denoising and enhancement, target recognition and feature matching algorithms, and image data classification and quantitative analysis methods. In recent years, with the development of computer vision and sensor technology, image analysis and detection has seen a rise in its application in identifying the authenticity and adulteration of traditional Chinese medicine (TCM) materials, particularly in the quality identification of high-value medicinal materials such as Cordyceps sinensis. One such method is the traditional magnesium sulfate weight gain detection method, used to identify whether TCM materials have been illegally weighted through soaking in magnesium sulfate solution. Traditional methods typically rely on chemical colorimetric reactions. The sample is treated with sodium hydroxide solution, causing any soluble magnesium salts to release and react with sodium hydroxide to form precipitates or colorimetric reactants. Iodine test paper is then used to contact the treatment solution, producing a characteristic color change, which indicates whether the sample contains magnesium sulfate residue. This type of method mainly relies on manual visual inspection of color changes, combined with visual experience to make a qualitative judgment on the color rendering.

[0003] Existing detection methods mainly rely on manual visual inspection of the color development of iodine test strips. Due to factors such as blurred color development edges and subtle color differences, it is difficult to make a clear judgment on the changing areas. When faced with samples with similar colors, significant background interference, or uneven color changes, inconsistent judgment results are likely to occur. Furthermore, there is a lack of dynamic monitoring capabilities for the color development process. A one-time judgment is made based solely on the static color state, which cannot identify the trend of color intensity changes and the characteristics of time evolution. The detection results lack regional structure analysis support, and the spatial correlation of color development cannot be clearly extracted, affecting the effective location of abnormal areas and multidimensional information analysis. Summary of the Invention

[0004] To achieve the above objectives, the present invention adopts the following technical solution: a method for detecting magnesium sulfate weight gain based on intelligent sensors, comprising the following steps: S1: Acquire iodine test paper images under two-band illumination by image acquisition information, read the corresponding pixel RGB values, perform three-channel difference operation to generate pixel difference map, divide the image into blocks and use the center difference to correct the grayscale, and generate reflected light difference image; S2: Read the row pixels at the top and bottom edges of the reflected light difference image, calculate the gray level difference between adjacent pixels, mark the changing pixel pairs, track the change sequence with the same direction, close the boundary and draw a stable color difference region to generate a color boundary image block. S3: Extract the regional grayscale of the color boundary image block, calculate the brightness difference of consecutive frames and construct the difference sequence, locate the first reverse change frame, filter the grayscale change area, reconstruct the brightness evolution layer, and generate the color dynamic image trajectory. S4: Call the color dynamic image trajectory, divide the dynamic image frame into grids, extract edge grayscale, analyze grayscale fluctuations in adjacent frames, filter abrupt regions after continuous grayscale growth, uniformly color and overlay the background, and output a brightness tomographic stitched image. S5: Compare the brightness tomographic image with the color boundary image block, identify the area where brightness abrupt change and boundary deformation coexist, outline and merge it into the original image, and output the magnesium sulfate weight gain detection result.

[0005] As a further aspect of the present invention, the reflected light difference image includes pixel grayscale difference distribution, regional brightness correction information and image grid division structure; the color rendering boundary image block includes boundary closure shape, continuous color difference change area and edge grayscale abrupt change feature; the color rendering dynamic image trajectory includes inter-frame brightness change sequence, brightness reversal node and grayscale difference concentration area; the brightness tomographic stitched image includes grayscale fluctuation partition, abnormal abrupt change area and unified color mark layer; and the magnesium sulfate weight gain detection result includes brightness change path, boundary contour line and composite anomaly recognition block.

[0006] As a further aspect of the present invention, the gray-scale abrupt change region refers to the region in the image where the gray-scale value changes discontinuously in time and space.

[0007] As a further aspect of the present invention, the abrupt change region after continuous grayscale increase refers to the region where the grayscale value changes and reverses after continuous increase.

[0008] As a further aspect of the present invention, the specific steps of S1 are as follows: S101: Iodine test paper images recorded under two bands of illumination using image acquisition information, obtain the RGB channel values ​​of the same pixel in the two image frames, perform subtraction operations on the three channel values ​​respectively and combine them to generate a three-channel pixel difference matrix. S102: Based on the three-channel pixel difference matrix, the image is divided into equal-area blocks, and the channel difference of the center pixel is called to construct a set of regional center channel difference values; S103: Call the difference value in the center channel difference set of the region, correct the intensity of the pixel gray value in the corresponding image block, and generate a reflected light difference image.

[0009] As a further aspect of the present invention, the specific steps of S2 are as follows: S201: Based on the reflected light difference image, read the pixel gray values ​​of the upper and lower edges of the image, extract adjacent pixel gray value pairs in sequence, obtain the gray value difference sequence by subtracting each pair, retrieve the position of the pixel pair with the largest difference amplitude in the gray value difference sequence, and generate an edge gray value difference index set. S202: Call the pixel pair positions in the edge grayscale difference index set, make a logical judgment on the direction of grayscale difference change according to the horizontal and vertical arrangement relationship in the image, filter out continuous pixel pairs with the same direction and record the pixel trajectory to obtain a continuous change trajectory sequence. S203: Based on the spatial positions of all pixels in the continuous trajectory sequence, a closed boundary structure is constructed by connecting the points, the corresponding boundary range is drawn on the original image and the corresponding region image block is extracted to generate a colored boundary image block.

[0010] As a further aspect of the present invention, the specific steps of S3 are as follows: S301: Based on the color boundary image block, extract all encapsulation regions in the image block, read the pixel grayscale value of each encapsulation region in a continuous image sequence, and calculate the difference between the average pixel grayscale values ​​of each region in two adjacent frames to construct a brightness difference sequence. S302: Call the brightness difference sequence, retrieve the frame where the brightness difference sign first reverses according to the frame number, record the frame number, extract the brightness change of all encapsulation areas in the two frames before and after, compare the difference and extract the changed area to obtain the key grayscale fluctuation area index. S303: Based on the region marked by the key grayscale fluctuation region index, extract the grayscale values ​​of consecutive frames synchronously in the image sequence, arrange them into a layer structure in chronological order, reorganize them to form a dynamic frame sequence, and generate a color dynamic image trajectory.

[0011] As a further aspect of the present invention, the specific steps of S4 are as follows: S401: Call the continuous frame images in the color dynamic image trajectory, divide each frame image into a regular grid region, extract the gray value of the pixels at the edge of the region, and compare the fluctuation amplitude of the gray value of the same grid region in the continuous frames to obtain the region gray value fluctuation classification result. S402: Based on the classification results of gray-scale fluctuations in the region, retrieve the regions in which the gray-scale difference shows an increase followed by a sudden change in the continuous frames, and perform intensity calculation and filtering of the gray-scale sudden change difference in the continuous frames for the selected regions to obtain the index set of sudden gray-scale regions. S403: Call the region marked by the abrupt grayscale region index set, assign a uniform color value to the region on the original image background, and overlay rendering layers according to the positional relationship to stitch together the entire image view and generate a brightness fault stitched image.

[0012] As a further aspect of the present invention, the specific steps of S5 are as follows: S501: Compare the region contour structure in the brightness tomographic image with the color boundary image block, check the corresponding image block position for each region, determine whether there is a distortion change in the grayscale tomographic boundary and the encapsulation boundary structure at the same time, and record the image block index that meets the conditions to obtain the composite variation region index set. S502: Call the region index in the composite variation region index set, perform contour stroking operation on all marked regions, uniformly set the edge pixel color value within the contour edge, fill the contour range and perform block merging and overlay to generate a structure fusion plot layer. S503: Based on the position of the image region in the structure fusion plot layer, align the layer content with the original image and perform fusion mapping, export the fused image, and generate magnesium sulfate weight gain detection results.

[0013] As a further aspect of the present invention, the distortion and change of the grayscale tomographic boundary and the encapsulation boundary structure refers to the structural change of the region in the image where the brightness grayscale boundary and the physical encapsulation contour are simultaneously deformed and shifted.

[0014] Compared with the prior art, the advantages and positive effects of the present invention are as follows: In this invention, a pixel grayscale difference map under dual-band illumination is constructed and local brightness features are extracted by combining the regional center difference. The edge grayscale changes are superimposed to construct a closed boundary. The brightness change path is dynamically tracked and the abrupt change region is marked. This realizes the continuous quantitative expression and spatial structure reconstruction of the color development process, improves the recognition accuracy and positioning ability of color difference regions, and enhances the detection stability and result reliability in cases of blurred color or complex background. Attached Figure Description

[0015] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0016] Figure 1 This is a schematic diagram of the steps of the present invention; Figure 2 This is a detailed schematic diagram of S1 of the present invention; Figure 3 This is a detailed schematic diagram of S2 of the present invention; Figure 4 This is a detailed schematic diagram of S3 of the present invention; Figure 5 This is a detailed schematic diagram of S4 of the present invention; Figure 6 This is a detailed schematic diagram of S5 of the present invention. Detailed Implementation

[0017] The technical solution of the present invention will now be described with reference to the accompanying drawings.

[0018] In embodiments of the present invention, words such as "exemplarily," "for example," etc., are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" in the present invention should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the word "exemplary" is intended to present the concept in a concrete manner. Furthermore, in embodiments of the present invention, the meaning expressed by "and / or" can be both, or either one.

[0019] In the embodiments of this invention, the terms "image" and "picture" may sometimes be used interchangeably. It should be noted that, without emphasizing the distinction between them, their intended meanings are consistent. Similarly, the terms "of," "corresponding (relevant)," and "corresponding" may sometimes be used interchangeably. It should be noted that, without emphasizing the distinction between them, their intended meanings are consistent.

[0020] In this embodiment of the invention, sometimes a subscript such as W1 may be written in a non-subscript form such as W1. When the difference is not emphasized, the meaning they express is the same.

[0021] To make the technical problems, technical solutions and advantages of the present invention clearer, a detailed description will be given below in conjunction with the accompanying drawings and specific embodiments.

[0022] Please see Figure 1 This invention provides a method for detecting the weight gain of magnesium sulfate based on a smart sensor, comprising the following steps: S1: Iodine test paper images recorded under two wavelengths of light by image acquisition information, read the RGB channel values ​​of pixels at the same position in the image, perform subtraction operation on the three channel values ​​and combine them into a single frame pixel difference image, divide the image into equal area blocks and call the difference value of the center pixel, correct the pixel gray intensity in the corresponding area according to the difference value, and generate a reflected light difference image. S2: Read the row pixels at the top and bottom edges of the reflected light difference image, calculate the gray level difference between adjacent pixels in each row and mark the pixel pair with the largest change value, determine the pixel sequence with the same continuous change direction and trace to the termination point, connect all pixels into a closed boundary structure, draw the encapsulated area with stable color difference change in the image, and generate a color boundary image block. S3: Extract all regions in the color boundary image block, read the pixel grayscale value of the region in each frame in the continuous image sequence, calculate the brightness change value between each frame and the previous frame and construct the brightness difference sequence, identify the image frame with the first reverse brightness change trend, and filter the region with the largest grayscale change between the previous and next frames, reconstruct the complete brightness evolution layer, and generate the color dynamic image trajectory. S4: Call the continuous frame images in the color dynamic image trajectory, divide each frame into partitions according to the image grid, extract the gray value of the pixel at the edge of the partition, judge the degree of gray fluctuation in each region in adjacent frames and classify them, filter the regions where the gray difference increases continuously and then abruptly change, uniformly color them and overlay them on the image background, and output the brightness tomographic stitched image. S5: Compare the regional contour structure in the brightness tomographic image and the color boundary image block, identify the image block that has both brightness abrupt change and boundary deformation, merge the block into the original image after unifying the contour outline, generate a detection map including brightness change trajectory and structural boundary information, and output the magnesium sulfate weight gain detection result.

[0023] The reflected light difference image includes pixel gray-level difference distribution, regional brightness correction information, and image grid division structure. The color boundary image block includes boundary closure shape, continuous color difference change area, and edge gray-level abrupt change feature. The color dynamic image trajectory includes inter-frame brightness change sequence, brightness reversal node, and gray-level difference concentration area. The brightness tomographic stitched image includes gray-level fluctuation partition, abnormal abrupt change area, and uniform color mark layer. The magnesium sulfate weight gain detection result includes brightness change path, boundary contour line, and composite anomaly recognition block.

[0024] Please see Figure 2 The specific steps of S1 are as follows: S101: Iodine test paper images recorded under two bands of illumination using image acquisition information, obtain the RGB channel values ​​of the same pixel in the two image frames, perform subtraction operations on the three channel values ​​respectively and combine them to generate a three-channel pixel difference matrix. Images of iodine test strips were recorded under two wavelengths of light using image acquisition information. Iodine test strips at the same physical plane location were imaged under both short-wave red and long-wave blue light illumination conditions using industrial cameras of the same model and resolution. After each acquisition, the images were uniformly adjusted to a consistent size and resolution to ensure a one-to-one correspondence of subsequent pixel coordinates. Then, the RGB channel values ​​were extracted from the two images in pixel coordinate order. The image under short-wave red light was named image frame A, and the image under long-wave blue light was named image frame B for image frame pairing. Subsequently, the red, green, and blue channel values ​​of each pixel in image frame A were compared one-to-one with the red, green, and blue channel values ​​at the same pixel coordinates in image frame B. The difference values ​​are calculated for the red, green, and blue channels, respectively. These three channel differences are then combined sequentially at each position to construct a three-channel difference record for that position. The differences of all pixels within the image range are then arranged sequentially according to the original image structure. If a channel value is negative during the difference calculation, it is either zeroed out or its absolute value is taken to ensure data stability. For example, in image frame A, the RGB values ​​of pixel (300, 400) are 210, 185, and 160, respectively. In image frame B, the RGB values ​​of the same pixel are 140, 130, and 125, respectively. Therefore, the three-channel difference values ​​for that pixel are 70, 55, and 35. This process is repeated throughout the entire image, combining the three-channel differences pixel by pixel, ultimately yielding a three-channel pixel difference matrix.

[0025] S102: Based on the three-channel pixel difference matrix, the image is divided into equal-area blocks, and the channel difference of the center pixel is called to construct a set of channel difference values ​​of the center of the region. The entire difference image is further partitioned. Based on the image size, it is divided into several rectangular image blocks of the same size. Each image block contains a fixed number of pixels. For example, if the size of a single image block is set to 40×40 pixels, then the 1024×768 pixel image can be divided into 480 image blocks. Then, the center coordinates of each image block are obtained. The center pixel position of each block is determined by integer division. For example, if the center pixel position coordinates of the m-th image block are (i, j), then the three-channel difference value recorded at that coordinate can be found in the three-channel pixel difference matrix, which serves as the center pixel position of that image block. The center channel difference is recorded as the feature value of the region. All image blocks are traversed sequentially and the center channel difference extraction operation is completed. If the pixel difference at the center of some image blocks fails (such as the image edge block exceeding the boundary), the center value can be replaced by calling the adjacent valid pixel differences in the image block and performing an averaging operation to ensure the integrity of the region difference set. For example, the center point of the 50th image block is located at (200, 160), and the three channel differences corresponding to this point are 40, 32, and 28. Then the channel difference of this region is the data set, which is written into the set, and finally the construction of the region center channel difference set is completed.

[0026] S103: Call the difference in the center channel difference set of the region, correct the intensity of the pixel gray value in the corresponding image block, and generate a reflected light difference image; For each pixel within an image block M, the center channel difference is a fixed set of RGB differences. A channel-weighted method is used to convert these three channel differences into a regional grayscale reference value for the corresponding image block. All pixels within the corresponding image block also have their respective three channel differences converted to their original grayscale values ​​using the same weighted method. Then, by comparing the grayscale value of each pixel in the image block with the center grayscale reference value, it is determined whether each pixel should undergo grayscale correction. If the grayscale value deviation exceeds a set threshold, intensity adjustment is performed. For example, if the center grayscale reference value deviation threshold is set to 20, then a grayscale value with a difference exceeding 20 from the center value will be considered grayscale corrected. Each pixel needs to undergo intensity correction. The correction method is to add or subtract a certain intensity correction value from the original grayscale value. The correction value can be set as a percentage of the difference between the center value and the current pixel value. For example, 60% of the difference can be used as the intensity correction factor. In a specific example, if the image block number is 128 and its center grayscale reference value is 60, and the grayscale value of a certain pixel in this block is 85, which exceeds the threshold of 20, the difference between the two is 25. After the correction, the grayscale value of this pixel is 85-25×60%=70. After the intensity adjustment of this pixel, it is written as the grayscale value of the differential reflection image into the output image. By repeating the above process for all image blocks, the reflected light difference image of the entire image can be obtained.

[0027] Please see Figure 3 The specific steps of S2 are as follows: S201: Based on the reflected light difference image, read the pixel gray values ​​of the upper and lower edges of the image, extract adjacent pixel gray value pairs in sequence, obtain the gray value difference sequence by subtracting each pair, retrieve the position of the pixel pair with the largest difference amplitude in the gray value difference sequence, and generate the edge gray value difference index set. First, the grayscale value of each pixel is read from the top and bottom edges of the image. The top edge reads the first row of pixel grayscale values ​​from left to right, and the bottom edge reads the last row in the same order, forming two sets of grayscale sequence data. Then, adjacent pixel grayscale values ​​in each sequence are paired. Every two consecutive grayscale values ​​form a pair, and a grayscale subtraction operation is performed on each pair to obtain the grayscale difference between adjacent pixels. The grayscale difference sequences from the top and bottom edges are then organized and stored as a complete grayscale difference sequence. Next, this sequence is traversed, and the absolute value of each grayscale difference is calculated and compared item by item to find the several pixel pairs with the largest values, recording their position indices in the image. To avoid false differences caused by weak noise, an amplitude threshold is introduced during the difference selection process. This threshold is set based on the statistical results of grayscale differences in multiple sets of iodine test paper images. In multiple experiments, the average grayscale difference between edge and non-edge regions was approximately 20 to 30. Therefore, the threshold is fixed at 25, meaning that only when the absolute value of the grayscale difference is greater than or equal to 25 is it considered to have a significant brightness difference. In practice, if the grayscale value sequence of a certain region at the upper edge is [100, 125, 150, 160], and the calculated grayscale difference is [25, 25, 10], then the pixel positions corresponding to the first two grayscale differences will be retained, while the portion with a difference of 10 will be discarded. After traversal, the positions of all pixel pairs with the largest difference amplitude exceeding the threshold are recorded, and the final result is the edge grayscale difference index set.

[0028] S202: Call the pixel pair positions in the edge gray-level difference index set, make logical judgments on the direction of gray-level difference change based on the horizontal and vertical arrangement relationship in the image, filter out continuous pixel pairs with the same direction and record the pixel trajectory to obtain a continuous change trajectory sequence. The coordinate information of each pair of pixels is read sequentially, and the arrangement of these pixels in the horizontal and vertical directions of the image is analyzed. First, the column coordinate difference between adjacent pixel pairs is judged. If the column coordinate distance between two adjacent pixel pairs is 1 pixel, it means that they are adjacent in the horizontal direction of the image. Then, the direction of change of the gray-level difference between these two sets of pixels is compared. The consistency of direction is determined by judging whether the increase or decrease trend of the difference is consistent. For example, if the gray-level difference of the first pair is +30 and the gray-level difference of the second pair is +28, it is judged that the change is in the same direction; if the first pair is +30 and the second pair is -10, the direction is judged to be reversed. On this basis, all pixel pairs are continuously judged in column coordinate order. Pixel pairs with consistent direction and a continuous number reaching a set threshold are grouped into a trajectory. The threshold is set with reference to the continuity statistics of multiple sets of image samples. Five pixel pairs are taken as the minimum continuous number threshold. That is, only when the gray-level change direction of five adjacent pixel pairs is consistent is it recorded as a valid continuous change segment. The threshold is set primarily based on statistical results of noise levels and edge transition features in the image. When local fluctuations caused by noise do not exceed a range of 3 pixels, setting a continuous threshold of 5 can effectively eliminate random fluctuations. For example, if the pixel grayscale differences corresponding to columns 100 to 106 in the image are +26, +28, +29, +31, +33, and +34 respectively, then these six pairs of pixels have the same direction and a quantity greater than the threshold of 5, thus being recorded as a continuous change trajectory. All trajectory data meeting the conditions are recorded to generate a complete sequence of continuous change trajectories.

[0029] S203: Based on the spatial positions of all pixels in the continuous trajectory sequence, a closed boundary structure is constructed by connecting the points. The corresponding boundary range is drawn on the original image and the corresponding region image patch is extracted to generate a colored boundary image patch. For each trajectory, pixels are connected point by point in the order they appear in the image, connecting adjacent coordinates sequentially into line segments until a closed trajectory structure is formed. To confirm whether the trajectory is closed, the distance between the first and last points is determined. If the distance is less than two pixel intervals, it is considered a closed structure. Then, the specific location of the boundary region is determined based on the coordinate range of the closed structure. The start and end coordinates of the boundary are extracted, and all pixels within this range are extracted to form a new image region. The threshold is determined based on the image's pixel density characteristics. If the image pixel interval is 0.2 mm, the closure threshold is set to less than or equal to 3 pixels, meaning a physical distance of no more than 0.6 mm is considered closed. In actual execution, if the trajectory start coordinates are (120, 50) and the end coordinates are (135, 65), the pixel distance between the two points is approximately 2.8 pixels, satisfying the closure condition, and the closed boundary is recorded. The corresponding range is drawn on the original image according to the boundary coordinates, and a marker line is used to distinguish the boundary from the background. Then, all pixels within the closed boundary are copied to form an independent image block file. If there are multiple closed boundary structures in the image, repeat the above extraction steps, perform coordinate extraction and pixel copying operations on each region, and finally generate a series of colored boundary image blocks.

[0030] Please see Figure 4 The specific steps of S3 are as follows: S301: Based on the color boundary image block, extract all encapsulation regions in the image block, read the pixel grayscale value of each encapsulation region in a continuous image sequence, and calculate the difference of the average pixel grayscale value of each region in two adjacent frames to construct a brightness difference sequence. First, all encapsulated regions defined by closed boundary structures are read from each image. The boundary range of each encapsulated region is determined using a set of two-dimensional coordinates of the region contour. Then, all pixels within this range are extracted. After the initial extraction of the encapsulated regions, the corresponding continuous image sequence is loaded, and each frame is processed sequentially. The pixels of the identified encapsulated regions in each frame are re-located, and the grayscale values ​​of the corresponding pixels within each frame are extracted. The average of all grayscale values ​​within the region is calculated and recorded as the grayscale mean of that region in that frame. To ensure the accuracy of the average value, the influence of edge interference pixels within the region needs to be avoided. This is done by ignoring the 2-3 pixel width of the region edge and extracting grayscale values ​​only from the effective pixels inside. After the extraction of all frames is completed, a grayscale mean sequence of each encapsulated region in the continuous image frames is formed. Then, based on the frame order, pairwise difference operations are performed on the grayscale mean values ​​between adjacent frames to calculate the brightness difference between the current frame and the previous frame. The brightness difference change results are recorded for each region. Finally, each encapsulation region obtains a set of brightness difference sequences arranged in frames. If the total number of frames in the image is 10, then each region will generate 9 brightness difference records. For example, if the grayscale average of a certain region is 132 in the 3rd frame and 118 in the 4th frame, then the brightness difference is -14. And so on to complete the entire image sequence processing and finally construct the brightness difference sequence.

[0031] S302: Call the brightness difference sequence, retrieve the frame where the brightness difference sign first reverses according to the frame number, record the frame number, extract the brightness change of all encapsulation areas in the two frames before and after, compare the difference and extract the changed area to obtain the key grayscale fluctuation area index. First, the brightness difference sequence of each region is traversed according to the time frame order. The sign of the brightness difference between adjacent frames is compared to determine whether the direction of change has reversed. When the brightness difference changes from positive to negative or vice versa for the first time, the time frame is determined to be a turning point frame for brightness fluctuation, and the frame number is recorded as the key node frame number. Next, the average brightness data of all encapsulated regions is extracted from the frame before and after the key node frame. Then, the average brightness of each region in the subsequent frame is subtracted from the average brightness of the corresponding region in the previous frame to calculate the brightness change. The changes in all regions are compared with a set threshold in turn, and the encapsulated regions with significant brightness changes are extracted as key grayscale fluctuation regions. The threshold used was set to grayscale level 10, based on statistical analysis of brightness variation trends in encapsulated areas across a large number of test images. The minimum grayscale change that effectively distinguishes chemical reaction changes from background fluctuations was selected as the standard. If a region's brightness is 130 in the previous frame and then drops to 117 in the next, the change is 13, exceeding the threshold of 10. This region is then considered a region with drastic brightness fluctuations and added to the index set. After completing all region traversal and judgment operations, the region numbers and locations that meet the conditions are summarized to form a key grayscale fluctuation region index.

[0032] S303: Based on the region marked by the key grayscale fluctuation region index, extract the grayscale values ​​of consecutive frames synchronously in the image sequence, arrange them into a layer structure in chronological order, reorganize them to form a dynamic frame sequence, and generate a color dynamic image trajectory. The grayscale data of these regions in each frame of the original image sequence is extracted sequentially. During processing, the position of the regions in the image remains unchanged. Each frame is retrieved according to its frame number, and the pixel grayscale value data corresponding to each key region in that frame is read. Simultaneously, using the frame order as a time index, the extracted key region image content of each frame is superimposed to construct a layer structure. Each layer corresponds to the grayscale state of a region in one frame, and is managed uniformly using a combination index of region number and frame order. After all frames are processed, the image content of the key regions is completely arranged in different layers, forming a temporally continuous and spatially consistent image data sequence, creating a dynamic frame sequence. In this dynamic frame sequence, each layer retains complete pixel grayscale details, ensuring accurate reproduction of the dynamic evolution of the region. All layers are arranged in chronological order during construction, combined into a set of continuously changing images. After completing layer construction and recombination, the frame sequence is output as complete dynamic image data, ultimately generating a color-coded dynamic image trajectory.

[0033] Please see Figure 5 The specific steps of S4 are as follows: S401: Call the continuous frame images in the color dynamic image trajectory, divide each frame image into a regular grid region, extract the gray value of the pixels at the edge of the region, and compare the fluctuation amplitude of the gray value of the same grid region in the continuous frames to obtain the region gray value fluctuation classification result. First, each frame of the image is divided into several regular rectangular grid regions at fixed intervals, using equidistant horizontal and vertical division. The size of each grid region is set according to the image resolution and analysis accuracy requirements, using 40×40 pixels as the baseline to maintain computational stability while preserving image detail. After division, each grid region is assigned a number, and the coordinate range of its upper left and lower right corners is recorded. Then, edge pixel grayscale values ​​are extracted from each grid region. The extraction order is from the upper left corner, reading along the outer edge of the grid sequentially to the right, down, left, and up until returning to the starting position, forming an edge pixel grayscale sequence. After extracting one frame, the same grid region with the corresponding number in the next frame is processed. A grayscale value comparison is performed on the same grid region in consecutive frames. By calculating the grayscale difference of pixels at the same position between adjacent frames, the amplitude of the grayscale difference change is recorded, and the average grayscale fluctuation of the entire edge of the region is calculated. The obtained average grayscale fluctuation is compared with a preset threshold, and different grayscale fluctuation levels are classified according to the magnitude of the fluctuation. The threshold values ​​were determined based on statistical results from the sample images. In a multi-frame color change sequence, the regional grayscale fluctuation amplitude was concentrated in the range of 0 to 20. Therefore, 8 was selected as the boundary value between low and medium fluctuation, and 15 as the boundary value between medium and strong fluctuation. Specifically, if the average grayscale fluctuation of a region is less than 8, it is classified as a stable region; if it is between 8 and 15, it is classified as a slightly fluctuating region; and if it exceeds 15, it is defined as a strongly fluctuating region. For example, if the average grayscale fluctuation of a grid in three consecutive frames is 10, 13, and 14 respectively, it is classified as a slightly fluctuating region. After all grids are analyzed, the regional grayscale fluctuation classification results for the entire image are generated.

[0034] S402: Based on the classification results of regional grayscale fluctuations, retrieve regions in continuous frames where the grayscale difference shows an increase followed by a sudden change. Perform intensity calculation and filtering of grayscale abrupt change differences in continuous frames for the selected regions to obtain an index set of abrupt change grayscale regions. First, the grayscale change trends of these regions in consecutive frames are sequentially read and compared. The grayscale differences between frames are arranged in chronological order, and the direction of grayscale change in adjacent frames is determined by comparing the positive and negative signs of the grayscale difference between two adjacent frames. When a region shows an increasing trend in grayscale value for three consecutive frames, followed by a decrease in grayscale value in the next frame, it is considered that a grayscale abrupt change has occurred in that region. The amount of grayscale change in the two frames before and after the abrupt change is extracted and calculated to obtain the abrupt change intensity value, and the result is compared with the abrupt change intensity threshold. The abrupt change intensity threshold is set through experimental sample determination. During the continuous color development process of iodine test paper, the average change in grayscale abrupt change is concentrated in the range of 8 to 12. Therefore, 10 is selected as the judgment boundary, indicating that when the average grayscale change of a region between two adjacent frames reaches or exceeds 10, it is considered that abrupt change has occurred. For example, if a region has an average grayscale value of 130 in frame 5, 142 in frame 6, 155 in frame 7, and 138 in frame 8, then the grayscale value drops by 17 in frame 8. This change exceeds the threshold of 10 compared to the previous frame, and the region is marked as a mutation region. All regions that meet the mutation criteria are recorded sequentially, and their location numbers, frame indices, and grayscale change values ​​are written into the mutation grayscale region index set, forming a complete mutation region dataset.

[0035] S403: Call the region marked by the abrupt grayscale region index set, assign a uniform color value to the region on the original image background, and overlay rendering layers according to positional relationship to stitch together the entire image view and generate a brightness tomographic stitched image. First, the abrupt change areas are located in the original image based on the coordinate range recorded in the index. Then, a uniform color is assigned to these areas, using a fixed value to distinguish them from the background. A red marker is set, with an R channel value of 255 and G and B channel values ​​set to 0, creating a monochrome filled area. After assignment, all abrupt change areas are rendered to their corresponding layers according to their index numbers. During rendering, the original image proportions and coordinate positions are maintained. Rendered areas are overlaid and blended layer by layer to form a complete layer structure. If areas overlap, the later rendered area will cover the pixels of the previous area during overlay. After all layers are rendered, layer stitching is performed on the entire image, combining the layers according to their corresponding positions to restore the original image size and proportions. Non-abrupt areas retain their original grayscale information, while abrupt change areas are displayed with a uniform color, creating a complete image with spatial contrast. After stitching, the output image is a brightness tomographic image, used to present the distribution and boundary characteristics of abrupt grayscale areas on the original image.

[0036] Please see Figure 6 The specific steps of S5 are as follows: S501: Compare the regional contour structures in the brightness tomographic mosaic image and the color boundary image block, check the corresponding image block position for each region, determine whether there are simultaneous distortion changes in the grayscale tomographic boundary and encapsulation boundary structures, record the image block index that meets the conditions, and obtain the composite variation region index set. First, the regional structures in the two types of images are classified by number, and a one-to-one corresponding index table is established. Spatial matching is then performed in this index table based on the position coordinates of the image patches. The boundaries of regions with color-assigned markers in the brightness tomographic stitched image are superimposed with the outlines of the encapsulated regions in the color boundary image patches. An error threshold of ±2 pixels is set for coordinate matching accuracy to ensure a reasonable correspondence in spatial positions. After completing the structural comparison, structural consistency and gray-level abrupt change overlap are judged for each pair of image regions. Structural consistency judgment refers to whether the encapsulated region outline exhibits offset, deformation, or distortion in continuous images. This process is achieved by calculating the centroid offset and shape of the region outline. Once the change rate is completed, if the centroid offset exceeds 5 pixels or the contour area changes by more than 15%, the region is considered to have undergone structural distortion. The gray-scale abrupt change coincidence judgment refers to whether there is color marker information for gray-scale abrupt changes in the brightness tomographic image within the region. If the corresponding regions in both types of images meet the above two conditions, the number of the patch position is recorded as a composite variation region and added to the index set to form a composite variation region index set. For example, if the patch number is A07, its contour area in the color boundary image changes from 84 pixels to 102 pixels, an increase of more than 21%. At the same time, this region has abrupt red markers in the brightness tomographic image, so it is marked as a composite variation region and written into the index.

[0037] S502: Call the region index in the composite variation region index set, perform contour stroking operation on all marked regions, uniformly set the edge pixel color value within the contour edge, fill the contour range and perform block merging and overlay to generate a structure fusion plot layer. First, the spatial coordinates of the original tiles are located based on the index. The region outline point set is extracted, and the coordinates of all boundary pixels are sorted. The sorting principle is to arrange the boundary points in a clockwise order according to the polar angle, with the outline centroid as the center point. After sorting, closed polygons are drawn one by one along the sorted point set to generate a closed outline path. Then, the edge color assignment operation is performed on the region enclosed by the closed outline path. The edge pixel color is set to a fixed value, taking RGB (0, 255, 0), which is a green border. The color filling operation is uniformly performed on the region within the outline, and the fill color is set to RGB value (0, 0, 255), which is a blue fill, used to distinguish it from the edge mark. After the filling is completed, all structural tiles are merged according to the region number. The merging method is to render all tiles uniformly onto a blank canvas according to the image space coordinates. When processing overlapping areas, the last processed tile is used as the reference for overlay, forming a tile overlay result layer. During the overlay process, the pixels are guaranteed not to be rotated or scaled. All tiles retain pixel consistency according to their original size. Finally, the structural fusion layer of all composite variation regions is constructed on the entire canvas, generating a structural fusion plot layer.

[0038] S503: Based on the position of the image region in the structure fusion plot layer, align the layer content with the original image and perform fusion mapping, export the fused image, and generate the magnesium sulfate weight gain detection result; The corresponding coordinates are called in the original image for matching and alignment. The layer content is mapped pixel by pixel onto the original image. Overlay operation is performed on the pixel overlapping areas during the mapping process. The color content assigned in the structure fusion layer is retained, and the background unassigned areas retain the original image information unchanged. After the full-frame matching of the layer to the original image is completed, pixel-level data fusion is performed to generate the fused image. The fused image uses the original image as the base and the structure plotting layer as the foreground content. During the overlay process, the image alignment accuracy error is kept to no more than 1 pixel to ensure that the fused result has structural continuity and grayscale consistency. After processing, the final fused image is exported as an image file in a specified format, and its image index and layer configuration information are recorded. The image file name can be automatically generated according to the image processing batch or sample number. The output image file is the magnesium sulfate weight gain detection result image. All structural variations and grayscale change areas are visually identified in the image, providing image basis for subsequent sample judgment.

[0039] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method for detecting magnesium sulfate weight gain based on smart sensor, characterized in that, The method comprises the following steps: S1: acquiring images of iodine test paper under two-waveband illumination through image acquisition information, reading corresponding pixel RGB values, performing three-channel difference operation to generate a pixel difference image, correcting gray scale after image block division with central difference, and generating a reflected light difference image; S2: reading row pixels of upper and lower edges of the reflected light difference image, calculating adjacent gray scale difference, marking change pixel pairs, tracking change sequences with consistent directions, closing boundaries and drawing stable color difference regions to generate a color development boundary image block; S3: extracting region gray scale of the color development boundary image block, calculating continuous frame brightness difference and constructing a difference sequence, locating the first reverse change frame, screening gray scale mutation regions, reconstructing a brightness evolution layer, and generating a color development dynamic image track; S4: calling the color development dynamic image track, partitioning dynamic image frame grids, extracting edge gray scale, analyzing adjacent frame gray scale fluctuations, screening gray scale continuous growth and mutation regions, uniformly coloring and superimposing a background, and outputting a brightness tomographic splicing image; S5: comparing the brightness tomographic splicing image with the color development boundary image block, identifying regions where brightness mutation and boundary deformation coexist, and outputting a magnesium sulfate weight gain detection result.

2. The smart sensor based magnesium sulfate weight gain detection method of claim 1, wherein, The reflected light difference image comprises pixel gray scale difference distribution, region brightness correction information, and image grid division structure; the color development boundary image block comprises boundary closed morphology, continuous color difference change region, and edge gray scale mutation feature; the color development dynamic image track comprises interframe brightness change sequence, brightness inversion node, and gray scale difference concentration area; the brightness tomographic splicing image comprises gray scale fluctuation partition, abnormal mutation region, and uniform color marking layer; and the magnesium sulfate weight gain detection result comprises brightness change path, boundary contour line, and composite abnormality identification block.

3. The smart sensor based magnesium sulfate weight gain detection method of claim 1, wherein, The gray scale mutation region refers to a region where gray scale values discontinuously jump in time and space.

4. The smart sensor based magnesium sulfate weight gain detection method of claim 1, wherein, The gray scale continuous growth and mutation region refers to a region where gray scale values change and reverse after continuous rising.

5. The smart sensor based magnesium sulfate weight gain detection method as claimed in claim 1, wherein, The specific steps of S1 are as follows: S101: acquiring images of iodine test paper recorded under two-waveband illumination through image acquisition information, obtaining RGB channel values of the same position pixels in two image frames, respectively performing subtraction operation of three-channel values and combining to generate a three-channel pixel difference matrix; S102: based on the three-channel pixel difference matrix, dividing the image into equal-area blocks, calling channel difference values of central pixels, and constructing a region central channel difference value set; S103: calling difference values in the region central channel difference value set, performing intensity correction on pixel gray scale values in corresponding image blocks, and generating a reflected light difference image.

6. The smart sensor based magnesium sulfate weight gain detection method as claimed in claim 1, wherein, The specific steps of S2 are as follows: S201: based on the reflected light difference image, reading pixel gray scale values of upper and lower edges of the image, sequentially extracting adjacent pixel gray scale pairs, obtaining gray scale difference value sequences through pairwise subtraction, retrieving positions of pixel pairs with maximum difference value amplitude in the gray scale difference value sequences, and generating an edge gray scale difference value index set; S202: Call the pixel pair position in the edge gray difference value index set, logically judge the gray difference value change direction according to the horizontal and vertical arrangement relationship in the image, filter the continuous pixel pairs with consistent direction and record the pixel track, and obtain the continuous change track sequence; S203: According to the spatial position of all pixel points in the continuous change track sequence, the closed boundary structure is constructed by connecting the points, the corresponding boundary range is drawn on the original image, and the corresponding region image block is extracted, and the color development boundary image block is generated.

7. The smart sensor based magnesium sulfate weight gain detection method as claimed in claim 1, wherein, The specific steps of S3 are: S301: Based on the color development boundary image block, extract all encapsulated regions in the image block, read the pixel gray value of each encapsulated region in the continuous image sequence in turn, calculate the difference value of the average pixel gray value of each region in the adjacent two frames, and construct the brightness difference value sequence; S302: Call the brightness difference value sequence, retrieve the position frame where the sign of the brightness difference value occurs first inversion according to the frame number, record the frame number, and extract the brightness change amount of all encapsulated regions in the previous and next two frames respectively, compare the difference values and extract the changed regions to obtain the key gray fluctuation region index; S303: According to the region marked by the key gray fluctuation region index, the continuous frame gray values are synchronously extracted in the image sequence, and are arranged in time sequence as a layer structure, and are reorganized to form a dynamic frame sequence, and a color development dynamic image track is generated.

8. The smart sensor based magnesium sulfate weight gain detection method of claim 1, wherein, The specific steps of S4 are: S401: Call the continuous frame image in the color development dynamic image track, divide each frame image into regular grid regions, extract the gray values of the region edge pixels, and compare the fluctuation amplitude of the gray values of the same grid region in the continuous frames in turn to obtain the region gray fluctuation classification result; S402: According to the region gray fluctuation classification result, retrieve the region where the gray difference value increases and then mutates in the continuous frames, perform intensity calculation and selection of the gray mutation difference value in the selected region in the continuous frames, and obtain a mutation gray region index set; S403: Call the region marked by the mutation gray region index set, perform uniform color assignment on the region on the original image background, and superimpose and render the layer according to the positional relationship to splice the whole image view and generate a brightness tomographic splicing image.

9. The smart sensor based magnesium sulfate weight gain detection method as claimed in claim 1, wherein, The specific steps of S5 are: S501: Compare the brightness tomographic splicing image with the region outline structure in the color development boundary image block, compare the corresponding image block position region by region, judge whether there is a gray tomographic boundary and an encapsulated boundary structure distortion change at the same time, record the image block index meeting the condition, and obtain a composite variation region index set; S502: Call the region index in the composite variation region index set, perform contour outlining operation on all marked regions, and uniformly set the color value of the edge line pixels in the contour edge, fill the contour range and perform image block merging and superimposition to generate a structure fusion plotting layer; S503: According to the image region position in the structure fusion plotting layer, align the layer content with the original image and perform fusion mapping, export the fused image to generate the magnesium sulfate weight gain detection result.

10. The smart sensor based magnesium sulfate weight gain detection method of claim 9, wherein, The gray scale tomographic boundary and package boundary structure distortion change refers to the area structure change of the deformation and offset of the brightness gray scale boundary and the physical package profile in the image at the same time.