An adaptive color region segmentation method, computer equipment and storage medium
By using an adaptive color region segmentation algorithm, the problem of inaccurate sample-carrier medium segmentation in smartphone colorimetry is solved, achieving fast and accurate sample region segmentation and color signal extraction, thus improving the accuracy of analysis results.
Patent Information
- Application Number
- CN202211080800.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-05
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2042-09-05
AI Technical Summary
In smartphone colorimetry, inaccurate segmentation of the sample and carrier medium regions leads to deviations in color information extraction, affecting the accuracy of the analysis results.
An adaptive color region segmentation algorithm is adopted to determine the sample boundary threshold by scanning the ratio of neighboring pixels, thereby automatically segmenting the sample region and reducing interference from the carrier medium.
It improves the accuracy and stability of sample color signal extraction, reduces errors, and enhances detection speed and segmentation effect.
Smart Images

Figure CN115578401B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of colorimetric sample analysis of smart phones, and particularly relates to a self-adaptive color region segmentation method, a computer device and a storage medium. BACKGROUND
[0002] Color is the degree of feeling of the human eye to light of different wavelengths, and the understanding of human beings to color has experienced a very long process. The term "color space" originates from the western "Color Space", also known as "color gamut". In color science, people establish various color models according to the characteristics of the human eye's cone cells to represent a certain color by using a space coordinate of different dimensions. The color range defined by this coordinate system is the color space. The color spaces commonly used in modern smart devices mainly include RGB, CMYK, Lab, etc. Among them, the RGB color space is the commonly used color space of smart phones.
[0003] Smart phone colorimetry is a kind of instant and rapid on-site sample detection technology, which is widely used in the fields of biology, chemistry, medicine, clinical treatment, etc. Smart phones have excellent imaging capability and excellent computing efficiency and are convenient to carry. This helps researchers to solve many problems.
[0004] However, the smart phone colorimetry is based on the analysis of sample color signals, so it is crucial to accurately extract the sample color signals. In the actual detection process, the sample droplet needs to be added into the carrier medium first, so the carrier medium and the sample are photographed into the image at the same time. If the sample and the medium region cannot be accurately and stably segmented, the color information extraction deviation will be caused, and finally an undesirable analysis result will be caused. Therefore, in order to accurately and stably extract the color signals of the sample region required by the user, it is very beneficial to develop a self-adaptive color region segmentation method for smart phone colorimetry. SUMMARY
[0005] Technical scheme: In order to solve the problems existing in the current method, the application provides a self-adaptive color region segmentation method, which uses an adaptive color region segmentation algorithm based on neighbor pixel point ratio scanning to accurately and stably segment the image and extract the signals of the sample region required by the user.
[0006] In order to achieve the above purpose, the application adopts the following technical scheme:
[0007] A self-adaptive color region segmentation method, comprising the following steps:
[0008] S1, acquiring a sample image;
[0009] S2, color scanning is performed on the sample image, specifically, taking the center of the sample image as a scanning starting reference point, color scanning is started in each direction to the edge of the sample image, three-channel color values of a pixel point are read at each scanning position, a weighted mean result thereof is taken as a pixel weight value, a current position pixel weight value is stored and scanning is continued;
[0010] S3, a scanning boundary threshold is determined, specifically, for each scanning direction, a weight ratio of a pixel weight value of a current scanning position to a pixel weight value of a last position stored in step S2 is calculated, a color value of a pixel point at a coordinate corresponding to a minimum value of the weight ratio is taken as a boundary threshold of the sample image in the current direction, after scanning in each direction is completed, scanning boundary thresholds of the directions are confirmed;
[0011] S4, a boundary pixel point is determined: taking a center point of the boundary threshold coordinate as a starting point, step S2 is repeated, when a first pixel point in each direction is scanned, the color value of which is less than or equal to a scanning boundary threshold set in the current direction, the pixel point is set as a boundary pixel point of the current scanning direction;
[0012] S5, color region segmentation is completed: after the boundary pixel points of the sample in all directions are confirmed, the boundary pixel point position is determined as a boundary position of the sample, and the boundary pixel point coordinates are extended to a sample boundary according to the boundary pixel points in each direction, the coordinates of the boundary and the scanning boundary threshold are recorded, and the color region segmentation of the sample is completed.
[0013] In an embodiment, the sample image is obtained by a device with a photographing function, by a medium transmission, or by loading a sample image from a local database.
[0014] In an embodiment, in step S2, taking the center of the sample image as a scanning starting reference point, color scanning is started in each direction to the edge of the sample image, including,
[0015] When the sample is a polygon, color scanning is performed in a direction to each side of the sample, taking a center point of the sample image as a starting reference point;
[0016] When the sample is a circle, color scanning is performed according to an angle of 0-2π.
[0017] In an embodiment, a calculation formula of the pixel weight value is:
[0018]
[0019] wherein R, G and B are respectively R, G and B channel color signal values in an RGB color space, and w is a pixel weight value.
[0020] The application further provides a computer readable storage medium, wherein the storage medium stores a computer program, and the computer program is configured to execute the method in any one of claims 1 to 4 when running.
[0021] The application further provides an electronic device comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the computer program to execute the method in any one of claims 1 to 4.
[0022] Advantages
[0023] The application has the advantages that when the application is applied to sample analysis of a smart phone, the sample image preprocessing is automatically completed in the background by the lightweight adaptive color region segmentation algorithm, the running speed is fast, the memory occupation is small, the complex manual color picking process of the traditional method is avoided, the detection speed is greatly improved, and the region segmentation effect is remarkable. By accurately and stably segmenting the sample and the carrier medium, the error caused by irrelevant signals introduced in subsequent sample color extraction is greatly reduced, and the color picking difficulty of the traditional method is better solved. BRIEF DESCRIPTION OF DRAWINGS
[0024] Figure 1 Method flowchart.
[0025] Figure 2 Emodin sample image.
[0026] Figure 3 Standard curve of sample colorimetric analysis before using the algorithm.
[0027] Figure 4 Standard curve of sample colorimetric analysis after using the algorithm.
[0028] Figure 5 Application environment of an embodiment of the application DETAILED DESCRIPTION
[0029] The application will be further illustrated below in conjunction with specific embodiments, which are used to illustrate the application but not to limit the scope of the application. After reading the application, those skilled in the art can make various modifications to the application, and the modifications fall within the scope defined by the appended claims.
[0030] As shown in Figure 1 , the embodiment of the application provides an adaptive color region segmentation method, comprising:
[0031] S1, acquiring a sample image;
[0032] S2, color scanning of the sample image: taking the center of the sample image as the scanning starting reference point, starting color scanning in each direction of the sample image edge, reading the three-channel color value of the pixel point at each scanning position and taking the weighted mean value as the pixel weight value, storing the current position pixel weight value and continuing scanning;
[0033] S3, determining the scanning boundary threshold: for each scanning direction, calculating the weight ratio of the pixel weight value of the current scanning position to the pixel weight value of the last position stored in step S2, taking the color value of the pixel point at the minimum weight ratio value coordinate as the boundary threshold of the sample image in the current direction, and confirming the scanning boundary threshold of each direction after scanning in each direction is completed;
[0034] S4, determining the boundary pixel point: taking the boundary threshold coordinate center point as the starting point, repeating step S2, and when each direction scans to the first pixel point whose color value is less than or equal to the scanning boundary threshold set in the current direction, setting this pixel point as the boundary pixel point of the current scanning direction;
[0035] S5, completing color region segmentation: after confirming the boundary pixel points of all directions of the sample, determining the boundary pixel point position as the boundary position of the sample, extending the boundary pixel point coordinates according to each direction to obtain the sample boundary, recording the coordinates of the boundary and the scanning boundary threshold, and completing the color region segmentation of the sample.
[0036] It should be noted that the electronic device can also be a terminal device such as a smart phone (for example, an Android phone or an iOS phone), a tablet computer, a palm computer, a mobile Internet device (MID), a PAD, and the like.
[0037] In an embodiment, the programming language used by the program and the algorithm is Java / Android.
[0038] In an embodiment, using the method of the present application, the whole analysis process can be completed within 3 minutes.
[0039] Further, the adaptive color region segmentation algorithm in step (b) is specifically as follows: based on the pixel points, taking the center point of the image region as the reference, color scanning is performed in the up, down, left and right four directions (rectangular), and if the sample region shape is circular, scanning is performed according to the angle 0-2π. In the first scanning process, the weight of the current pixel is calculated according to the color weighted mean value, then the ratio of the weight to the previous pixel is calculated, and the minimum ratio in the current direction is determined after scanning. At this time, the color value corresponding to the minimum ratio pixel point coordinates is recorded, and the boundary threshold value is set for the current direction according to the scanning result. After scanning in all directions, the first scanning is ended. Next, the second scanning is performed, and the method is the same as the first scanning. The color value of the current pixel point is calculated during scanning. If the color value of a certain point is less than or equal to the set threshold value, the pixel point scanned at present is the boundary pixel point. The boundary is determined after scanning in all directions, and the coordinates and threshold value are recorded to facilitate the rapid processing of similar samples and complete the region definition (the image (0, 0) point can also be taken as the reference to scan to the (width, height) point, and the maximum ratio in each direction should be determined at this time).
[0040] In an embodiment, the region definition and the calculation to output process are automatically performed in the background.
[0041] In an embodiment, the pixel weight calculation formula in the algorithm is as follows:
[0042]
[0043] Wherein, R, G and B are respectively the R, G and B channel color signal values in the RGB color space, and w is the weight. The RGB color space takes R (Red), G (Green) and B (Blue) three basic colors as the basis, and different degrees of superposition are performed to produce rich and extensive colors, so it is commonly known as the three primary color mode.
[0044] In an embodiment, the boundary threshold value in the algorithm should be determined according to the actual situation of the carrier medium and the sample.
[0045] The adaptive color region segmentation method provided in the application can be applied to the application environment as shown in the figure. Figure 5 The terminal 102 communicates with the server 104 through the network. The terminal 102 can be various personal computers, notebook computers, smart phones, tablet computers and portable wearable devices, but is not limited to this. The server 104 can be implemented by an independent server or a server cluster composed of multiple servers.
[0046] In an embodiment, an adaptive color region segmentation method is provided. It should be noted that the method is exemplarily described by taking the application of the method in the smart phone colorimetric analysis as an example. The specific application scene is as follows:
[0047] The sample used in this embodiment is emodin solution (see Figure 2 ), the surface color of the medium carrier is black, Figure 2 The first row of the standard sample (STD) is added, and the concentration from left to right is 0 μg / mL, 10 μg / mL, 25 μg / mL, 50 μg / mL, 75 μg / mL, and 100 μg / mL. The second row is added with samples S1 and S2, each of which is added in triplicate.
[0048] First, use a smartphone to take a picture of the sample. For example, the standard sample in the first row of the third well is divided into two parts. Load the corresponding image into the program. As shown in the figure, there is a clear color difference between the medium carrier and the sample solution. Figure 2 After loading the image, the program first runs the adaptive color region segmentation method in the background. Specifically, taking the image region center point coordinates (150, 150) as the reference, color retrieval is performed in the up, down, left and right directions (the color region in this embodiment is a square). In the first scanning process, the current pixel weight is calculated according to the color weighted mean value, and then the weight ratio with the previous pixel point is calculated. After scanning, the minimum ratio value in the current direction is determined. At this time, the color value corresponding to the minimum ratio pixel point coordinates is recorded, and the boundary threshold value for the current direction is set according to the scanning result. In this embodiment, the boundary threshold values for all directions are set to (100, 100, 100) according to the scanning result. After all directions are scanned, the first scanning is completed. Next, the second scanning is performed with the boundary threshold center point (90.5, 110) as the center. The method is the same as the first scanning. The current pixel color value is calculated during scanning. When the program scans to the left to the pixel color value (92, 55, 78), since the color values of this pixel point are all less than the left boundary threshold value (100, 100, 100), it is determined that this pixel point is the left boundary pixel point, and the left scanning is ended. After scanning in all directions, the boundary is determined (the method is the same as the left boundary, and the color values of the upper, lower and right boundaries are (99, 52, 72), (88, 57, 72) and (91, 64, 74), respectively). The coordinates and threshold characteristics are recorded to facilitate the rapid processing of similar samples. At this time, the region is defined, and the image and extracted color information are loaded into the interface.
[0049] Results:
[0050] This embodiment tests the analysis before and after using the method of the present application. The results show that, compared with the results after using the algorithm, due to the interference of the medium carrier, the standard curve fitting before using the algorithm is poor Figure 3 ), the quantitative result accuracy is poor and the RSD is large (Table 1), and after using the algorithm, the above-mentioned conditions are greatly improved Figure 4 , Table 2).
[0051] Table 1 Colorimetric analysis results of samples before using algorithm
[0052]
[0053] Table 2 Colorimetric analysis results of samples after using algorithm
[0054]
[0055] The standard results come from the ultraviolet-visible spectrophotometer (Table 3). Finally, we use Photoshop to measure the standard color value of the sample area, and then extract the color value of the sample before and after the algorithm respectively. The comparison of the results shows that after applying this color region segmentation algorithm, the extracted color value is close to the standard value, while the color extraction result without using the algorithm has a large deviation from the standard value (Table 4).
[0056] Table 3 Ultraviolet-visible spectrophotometer measurement results
[0057]
[0058] Table 4 Comparison of color extraction results before and after using algorithm with standard value
[0059]
[0060] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer readable storage medium. When the computer program is executed, it can include the processes of the above-mentioned embodiments of each method. Any reference to memory, storage, database or other medium used in each embodiment provided by the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0061] Any combination of the technical features in the above embodiments can be made, and for the sake of brevity, not all possible combinations are described above, however, as long as the combination of the technical features does not exist in contradiction, it shall be considered within the scope of the present disclosure.
[0062] The above embodiments only express several implementation manners of the present application, and the description is relatively specific and detailed, but it shall not be understood as a limitation on the patent scope of the present application. It shall be pointed out that, for ordinary skilled persons in the art, several modifications and improvements can be made without departing from the concept of the present application, and these shall be within the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the appended claims.
Claims
1. An adaptive color region segmentation method, characterized in that, Includes the following steps: S1. Obtain sample images; S2. Perform color scanning on the sample image, specifically: take the center of the sample image as the scanning starting reference point, start color scanning in all directions of the edge of the sample image, read the three-channel color values of the pixel at each scanning position, and use the weighted average result as the pixel weight, store the pixel weight at the current position and continue scanning. S3. Determine the scanning boundary threshold. Specifically, for each scanning direction, calculate the weight ratio of the pixel weight at the current scanning position to the pixel weight at the previous position stored in step S2. Take the color value of the pixel at the coordinate corresponding to the minimum weight ratio as the boundary threshold of the sample image in the current direction. After scanning in each direction, confirm the scanning boundary threshold of each direction. S4. Determine the boundary pixel: Starting from the center point of the boundary threshold coordinates, repeat step S2. When the first pixel whose color value is less than or equal to the scanning boundary threshold set in the current direction is scanned in each direction, this pixel is set as the boundary pixel of the current scanning direction. S5. Complete color region segmentation: After confirming the boundary pixels of the sample in all directions, determine the boundary pixel positions as the sample boundary positions, and extend the sample boundary according to the coordinates of the boundary pixels in each direction. Record the coordinates of the boundary and the scanning boundary threshold to complete the color region segmentation of the sample.
2. The color region segmentation method according to claim 1, characterized in that, The acquisition of sample images includes: acquiring sample images through a device with photographic or video recording capabilities, transmitting them through a medium, and loading them into a local database.
3. The color region segmentation method according to claim 1, characterized in that, In step S2, the center of the sample image is used as the starting reference point for scanning, and color scanning begins in all directions towards the edge of the sample image. include, When the sample is a polygon, the center point of the sample image is used as the starting reference point, and color scanning is performed in the direction of each side of the sample. When the sample is circular, color scanning is performed based on an angle of 0-2π.
4. The color region segmentation method according to claim 1, characterized in that, The formula for calculating the pixel weight is: Where R, G, and B are the color signal values of the R, G, and B channels in the RGB color space, respectively, and w is the pixel weight.
5. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to execute the method described in any one of claims 1 to 4 when it is run.
6. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Color image segmentation method and system
CN101699511A
Retina image exudation area segmentation method and device, and computing device
CN107038704A