Traditional Chinese medicine tongue image viscera partitioning method based on edge detection

Through the edge detection method, the accuracy problem of the existing tongue image partitioning algorithm when facing individual differences and irregular tongue patterns is solved, and more accurate tongue organ partitioning is achieved, which improves the reliability of tongue image analysis.

CN119624988APending Publication Date: 2025-03-14BEIJING UNIV OF CHINESE MEDICINE
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411709998.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-03-14

AI Technical Summary

Technical Problem

When existing tongue image partitioning algorithms face individual differences, irregular tongue patterns and pathological skewed tongues, it is difficult to accurately partition the internal organs, resulting in partition misalignment and errors, affecting the reliability of tongue image analysis.

Method used

Using the Chinese medicine tongue image viscera partition method based on edge detection, the tongue image was collected through a high-definition camera, and the tongue was separated from the background using the DeeplabV3+ semantic segmentation model, the minimum external rectangle was determined and the image was cropped. Then, the left and right boundary points, top and bottom boundary key points of the tongue were determined through edge detection, and the tangent was drawn as the boundary, and the area was divided according to the polygon area creation mask.

Benefits of technology

This method can more accurately adapt to different tongue morphology, reduce partition misalignment and error, improve the reliability of tongue image analysis, and comply with the theoretical specifications of traditional Chinese medicine and the actual situation of tongue image morphology.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119624988A_ABST
    Figure CN119624988A_ABST
Patent Text Reader

Abstract

The invention relates to the field of tongue image viscera partitioning, and discloses a traditional Chinese medicine tongue image viscera partitioning method based on edge detection, and the method comprises the steps: collecting a tongue image through a built-in high-definition camera of a tongue diagnosis instrument; in order to avoid interference of other parts such as the face and the lip on tongue picture analysis, on the basis of manually marking a tongue body image area, a DeeplabV3 + semantic segmentation model is used to separate the tongue from the background; automatic batch processing is carried out through a customization algorithm, and after the tongue body is segmented and processed, the minimum bounding rectangle of the tongue body is determined; detecting the upper, lower, left and right edges of the tongue, determining left and right boundary points and top and bottom boundary key points of the tongue in the image, and drawing four tangent lines according to the edge form; and by taking the tangent line as a boundary, creating a mask according to a corresponding polygonal region, and completing region division and extraction. The method has the advantages that the problem that a traditional rectangular partitioning rule is insufficient in adaptability to the tongue shape is solved, the accuracy is higher, and the partitioning result is more reliable.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of tongue image viscera partitioning, and in particular to a method for traditional Chinese medicine tongue image viscera partitioning based on edge detection. Background Art

[0002] Traditional Chinese medicine believes that there is a close relationship between the tongue and the internal organs. Generally speaking, the tip of the tongue belongs to the heart and lungs, the sides of the tongue belong to the liver and gallbladder, the middle of the tongue belongs to the spleen and stomach, and the root of the tongue belongs to the kidneys. This distribution pattern provides an important reference for tongue diagnosis in traditional Chinese medicine. When a certain internal organ is diseased, the corresponding tongue area often shows corresponding changes in tongue image, such as changes in color, shape, texture, etc. Therefore, observing the changes in tongue image can understand the functional status and pathological changes of the internal organs. With the development of modern science and technology, the collection, processing and analysis of tongue images have gradually become standardized and objective. Using high-definition cameras, image processing technology and other means, clear and consistent tongue image photos can be obtained, and accurate and quantitative tongue image features can be obtained through methods such as feature extraction and classification diagnosis.

[0003] Tongue diagnosis in Chinese medicine:

[0004] Definition: Tongue diagnosis is an important part of TCM visual diagnosis. By observing the changes in the shape, color, texture, etc. of the tongue, the functional status and pathological changes of the internal organs of the human body can be inferred.

[0005] Tongue area: Traditional Chinese medicine believes that there is a close relationship between the tongue and internal organs, and different tongue areas correspond to different internal organs:

[0006] Tip of tongue: corresponds to the heart and lungs

[0007] Tongue side: Corresponding to liver and gallbladder

[0008] Center of tongue: corresponds to spleen and stomach

[0009] Tongue root: corresponds to the kidney

[0010] Tongue characteristics:

[0011] Color: A healthy tongue is light pink. When abnormal, it may appear pale, red, purple, and other colors, reflecting different pathological conditions.

[0012] Morphology: The normal tongue is thin, but abnormally it may be fat, thin, cracked, or have tooth marks, reflecting different pathological changes.

[0013] Texture: A healthy tongue is soft and moist. When abnormal, it may appear dry, slippery, rough, etc., reflecting changes in yin and yang, qi and blood in the body.

[0014] The role of tongue diagnosis in TCM diagnosis:

[0015] Etiology diagnosis: Observing changes in tongue patterns can help identify the cause of the disease, such as internal heat, cold and dampness, qi stagnation, blood stasis, etc.

[0016] The current tongue image analysis algorithm also attaches importance to the diagnosis of the tongue's internal organs and has standardized tongue image partitioning. The traditional tongue image partitioning method uses a relatively standard tongue shape as a blueprint to identify the tongue image and divide the tongue tip, tongue edge, tongue center and tongue root. However, in specific clinical practice applications, due to individual differences between patients, shooting conditions, and different types and pathogenesis of diseases, a large number of tongue images are not completely standard. Some tongue images show an irregular tongue shape that is approximately triangular. At the same time, many images will have slight deviations, and even pathological skewed tongues. In the face of these common "special cases", traditional tongue image analysis algorithms cannot adapt well to these rule changes. When the algorithm mechanically partitions according to the standard segmentation method, it will cause a large number of partition dislocations and errors.

[0017] Problems and shortcomings of existing technologies:

[0018] Prior art background: Existing tongue image partitioning algorithms are mostly based on rectangular partitioning rules, using symmetrical and evenly distributed rectangular areas to achieve tongue partitioning. Although this method can work effectively under ideal conditions, it encounters some problems in practical applications.

[0019] Individual differences: Different patients have different tongue shapes, and due to different disease types and pathogenesis, the actual tongue image is often not very ideal. In this case, traditional algorithms are prone to partition dislocation and errors, resulting in inaccurate results of quantitative feature analysis of tongue images. For example, some tongue images show irregular tongue shapes that are approximately triangular, or slightly offset or even pathologically skewed tongues. These special tongue shapes are difficult to handle in traditional algorithms, further affecting the accuracy of partitioning and the reliability of tongue image analysis.

[0020] In summary, for this purpose, we provide a method for organ partitioning in TCM tongue images based on edge detection. Summary of the invention

[0021] 1. Technical issues to be resolved

[0022] In view of the shortcomings of the prior art, the present invention provides a method for organ partitioning of traditional Chinese medicine tongue images based on edge detection, which has the advantages of solving the problems of accuracy, adaptability and reliability of analysis results under the existing rectangular partitioning rules, and solves the problems in the above-mentioned background technology.

[0023] (II) Technical solution

[0024] In order to achieve the above-mentioned purpose of solving the problems of accuracy, adaptability and reliability of analysis results under the existing rectangular partitioning rules, the present invention provides the following technical solutions:

[0025] A method for partitioning organs of a tongue image in traditional Chinese medicine based on edge detection comprises the following steps:

[0026] S1: Use the built-in high-definition camera of the tongue diagnostic instrument to collect tongue images;

[0027] S2: To avoid interference of human face on tongue segmentation, based on manual annotation of tongue, DeeplabV3+ semantic segmentation model is used to separate the tongue from the background, determine the minimum bounding rectangle and complete image cropping to remove redundant invalid areas.

[0028] S3: Customized algorithm for automated batch processing. After the tongue is segmented and processed, the minimum circumscribed rectangle of the tongue is determined, the upper, lower, left and right edges of the tongue are detected, the left and right boundary points, top and bottom boundary key points of the tongue in the image are determined, and four tangents are drawn according to the edge shape. The tangents are used as boundaries, and masks are created according to the corresponding polygonal areas to complete the area division and extraction, which are used to distinguish the tongue into the root, middle, inter-tongue and edge parts.

[0029] A method for viscera partitioning of a tongue image in traditional Chinese medicine based on edge detection comprises the following steps:

[0030] Step S1: image preprocessing;

[0031] Step S11: Identify the image and convert it into a grayscale image;

[0032] Step S12: image binarization;

[0033] Step S13: Determine the maximum circumscribed rectangular outline;

[0034] Step 2: Determine the key points;

[0035] Step 21: Calculate the average row coordinates of the first 20 columns of non-zero pixels on the left side to determine the ordinate of the left edge key point;

[0036] Step 22: Calculate the average row coordinates of the first 20 columns of non-zero pixels on the right side to determine the ordinate of the key point on the right edge;

[0037] Step 23: Calculate the average column coordinates of the non-zero pixels in the bottom 50 rows to determine the horizontal coordinate of the bottom of the tongue;

[0038] Step 3: Define slope and intercept auxiliary functions;

[0039] Step 4: tangent fitting of the left and right edges;

[0040] Step 41: Calculate the left and right edge slopes;

[0041] Step 42: traverse the left and right edge points and find the point with the maximum intercept, and determine the horizontal coordinates of the left and right edges by reference;

[0042] Step S43: Update the left and right slopes and fit;

[0043] Step 5: Calculate the left and right vertices and bottom points;

[0044] Step 51: According to the slope and key points of the left and right edges, calculate the horizontal coordinate at 1 / 5 of the height and determine the left and right vertices lt 1 and rt 1 ;

[0045] Step 52: According to the slopes and key points of the left and right edges, calculate the horizontal coordinates at the 4 / 5 height and determine the left and right bottom points lb 1 and rb 1 ;

[0046] Step 6: Calculate the intermediate transition point;

[0047] Step 61: Perform linear interpolation between the left vertex and the right vertex at a ratio of 1 / 5 and 4 / 5 to calculate the new left and right vertices lt 2 and rt 2 ;

[0048] Step 62: Perform linear interpolation between the left vertex and the left bottom point at a ratio of 1 / 5 and 4 / 5 to calculate the new left bottom point lb 2 ;

[0049] Step 63: Perform linear interpolation between the right vertex and the right bottom point at a ratio of 1 / 5 and 4 / 5 to calculate the new left bottom point rb 2 ;

[0050] Step 7: Update the slope;

[0051] Step 8: Calculate the new slope using the horizontal coordinate difference and height difference of the intermediate transition point to avoid the error that may be caused by directly using the original slope;

[0052] Step 8: Determine the final left and right vertices;

[0053] According to the new slope and intercept, calculate the horizontal coordinate of the top of the tongue (y=0) and determine the new left and right vertex positions lt 3 and rt 3 ;

[0054] Step 9: Extract area;

[0055] Create masks and extract according to the corresponding polygonal areas;

[0056] Finally, save the data.

[0057] Preferably, S1 further includes reading an image from a given path and converting it into a grayscale image. The image is usually stored in a color format, and the grayscale image only contains brightness information, no color information. Converting the image to a grayscale image can simplify calculations and increase processing speed because only one channel of data needs to be processed instead of three; converting the grayscale image to a binary image. The binarization process converts the pixel values ​​in the image into one of two values ​​based on a set threshold. Here, all pixel values ​​greater than 1 are set to 255, and the rest are set to 0. This can effectively highlight the object in the image and remove the background. The formula is as follows:

[0058]

[0059] Preferably, S2 further includes searching for contours and finding the largest contour. Contour detection is the process of extracting boundaries from a binary image. Each contour is a sequence of points, which represent a closed curve in the image. The function cv2.findContours provided by OpenCV can be used to find contours in the image. The area of ​​the bounding rectangle of each contour is calculated through the (x, y) contour, and the contour with the largest area is selected. For each contour, the cv2.boundingRect() function is used to obtain the upper left corner coordinates (x, y), width w and height h of the minimum rectangle enclosing the contour, and then the area of ​​the rectangle is calculated. The formula is as follows:

[0060] Area = w*h

[0061] When traversing all contours, record the largest area value and the corresponding rectangle coordinates, and finally select the rectangle with the largest area as the main contour.

[0062] Crop the image to the largest contour area. The bounding rectangle of the largest contour provides the minimum rectangular area containing the contour. Use the coordinates of this rectangular area to crop the original image, retaining only the tongue part and removing the background and other irrelevant parts.

[0063] Preferably, S3 further includes calculating left and right boundary points and a bottom boundary point. For the left boundary point, the average value of non-zero pixels in each column of the first 20 columns on the left side of the image is calculated. For the right boundary point, the average value of non-zero pixels in each column of the first 20 columns on the right side of the image is calculated. For the bottom boundary point, the average value of non-zero pixels in each row of the bottom 50 rows of the image is calculated. The above average values ​​are used to determine the boundary points of the tongue. The calculation formula is as follows:

[0064] Left boundary point:

[0065] leftPoint = [average non-zero pixel row position of the 20 columns to the left, 0]

[0066] Right boundary point:

[0067] rightPoint = [average non-zero pixel row position of the 20 columns on the right, image width]

[0068] Bottom boundary point:

[0069] bottomPoint = [image height, average non-zero pixel column position of the bottom 50 rows]

[0070] Compute the intercept and new x-coordinate, given a slope m and a point (x 1 ,y 1 ), calculate the intercept of the straight line on the y-axis, the formula is as follows:

[0071] Intercept = y 1 -m*x 1

[0072] Given the slope m and the point (x 1 ,y 1 ), and the new y coordinate y new , calculate the corresponding x coordinate, the formula is as follows:

[0073]

[0074] Calculate the slope and find the point with the maximum intercept, calculate the slope from the bottom boundary point to the left boundary point and the right boundary point, traverse the range of image height, use the calculate_intercept function to calculate the intercept of the left and right boundaries at each height, and select the point with the maximum intercept as the new boundary point. The formula is as follows:

[0075] Slope:

[0076]

[0077] Maximum intercept:

[0078] max_intercept=max(calculate_intercept(m,x,y))

[0079] Calculate the new upper and lower boundary points, use the slope and intercept calculated previously to determine the new left and right boundary points corresponding to the 1 / 5 height and 4 / 5 height, and use the calculate_x_for_y function to calculate the new x coordinate based on the slope, the given point coordinates, and the new y coordinate. The formula is as follows:

[0080] New upper boundary point:

[0081]

[0082] New lower boundary point:

[0083]

[0084] According to the calculated boundary points, the tongue is divided into different regions and saved in the corresponding folders. A polygon is created for each region, and a mask is generated using the polygon filling method. The mask is used to extract the corresponding region in the original image and saved in the corresponding folder.

[0085] Iterate over all images in the input path and call the main function to process each image. Use the glob function to find all file paths that match a specific pattern, iterate over these file paths, and call the main function to process each image.

[0086] (III) Beneficial effects

[0087] Compared with the prior art, the present invention provides a method for viscera segmentation of TCM tongue images based on edge detection, which has the following beneficial effects:

[0088] The method for viscera partitioning of TCM tongue images based on edge detection solves the problems of insufficient accuracy, adaptability and reliability of analysis results under the existing rectangular partitioning rules, and is more in line with TCM theoretical norms and the actual situation of tongue image morphology, and has significant advantages. These advantages provide important support for the modernization, standardization and quantitative development of TCM tongue diagnosis, and have important scientific research and clinical application value.

[0089] The tongue image trapezoidal viscera partitioning rule proposed by the present invention is the first and only one in the TCM diagnosis industry, and is proposed completely independently. This new partitioning rule is more in line with the TCM tongue viscera partitioning theory actually needed in the field of tongue image objectification research, and is adapted to the actual situation of standardized tongue image pictures collected by tongue diagnosis instruments, and can replace the traditional rectangular partitioning method. This method is well adapted to the diversity of image morphology, further promotes the objectification, standardization, and quantification of tongue diagnosis, and improves the reliability of analysis results.

[0090] The present invention solves the problem that the traditional algorithm-based tongue image partitioning rules cannot correctly partition the internal organs for tongue images of various shapes and sizes. The trapezoidal partitioning rules and automated algorithms proposed in the present invention can greatly avoid the deviation of tongue internal organs partitioning caused by individual differences. Through accurate tongue segmentation, repeated external trapezoidal contours and key point definitions, on the basis of the feasibility of algorithmic rules, the traditional Chinese medicine tongue image internal organs partitioning rules are restored to the greatest extent, which greatly ensures the accuracy and rigor of the subsequent quantitative feature analysis of tongue images in different regions.

[0091] The present invention implements the trapezoidal partitioning rule based on Python language. The algorithm includes steps such as image acquisition and processing, tongue segmentation, tongue edge clipping, and boundary point calculation, which ensures the accuracy of the results of quantitative feature analysis of tongue images. Through a series of image processing steps (including grayscale conversion, binarization, image clipping, and semantic segmentation) and repeated adjustment and refinement of boundary point calculation, the key boundary lines are determined. On the basis of adapting to the outer contour of the tongue shape, the actual segmentation line is defined, and the tongue image is segmented into five major areas: the root of the tongue, the middle of the tongue, the sides of the tongue, and the tip of the tongue, which improves the accuracy of the partition and the adaptability to complex shapes. BRIEF DESCRIPTION OF THE DRAWINGS

[0092] Figure 1 It is a schematic diagram of the method of the present invention;

[0093] Figure 2 This is a schematic diagram of the traditional rules for dividing organs in tongue images;

[0094] Figure 3 This is a schematic diagram of the inapplicability of the traditional tongue image organ partitioning rules;

[0095] Figure 4 A schematic diagram of the organ partitioning rules of tongue images according to the present invention;

[0096] Figure 5 It is a detailed flow chart of the technical method of the present invention;

[0097] Figure 6 A schematic diagram of the steps for determining the trapezoidal contour of the tongue body according to the present invention;

[0098] Figure 7 The effect diagram of determining the segmentation line for tongue image partitioning of the present invention;

[0099] Figure 8 This is a schematic diagram of the operation results of the tongue image internal organs partitioning algorithm of the present invention. DETAILED DESCRIPTION

[0100] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0101] Embodiment 1:

[0102] like Figure 1-8 As shown, the present invention provides a technical solution: a method for viscera partitioning of a tongue image in traditional Chinese medicine based on edge detection, comprising the following steps:

[0103] S1: Preprocessing the standardized tongue images collected by the tongue diagnostic instrument;

[0104] Unify the file format and resolution of all images to ensure data consistency and facilitate subsequent analysis; compress images to reduce storage space and processing time while retaining the highest possible image quality; perform color correction, using the standard whiteboard area as a reference to eliminate color deviations caused by differences in shooting conditions and ensure image color consistency; perform image denoising to eliminate noise caused by the shooting environment or equipment, thereby improving image quality and providing a reliable data basis for subsequent feature extraction and partitioning.

[0105] S2: To avoid interference of human face on tongue segmentation, based on manual annotation of tongue, DeeplabV3+ semantic segmentation model is used to separate the tongue from the background, determine the minimum bounding rectangle and complete image cropping to remove redundant invalid areas.

[0106] The technical process is as follows: manually select some sample images and accurately annotate the tongue area to generate a data set for training. Then, use these annotated data to train the DeeplabV3+ semantic segmentation model so that it can learn the morphology and boundary features of the tongue. After the training is completed, the tongue image to be processed is input into the model, and the model automatically predicts and generates a segmentation mask for the tongue area, accurately separating the tongue area from the background.

[0107] Find contours and find the largest contour. Contour detection is the process of extracting boundaries from a binary image. Each contour is a sequence of points that represent a closed curve in the image. The function cv2.findContours provided by OpenCV can be used to find contours in an image. By traversing all found contours, calculating the area of ​​the bounding rectangle of each contour, and selecting the contour with the largest area, for each contour, use the cv2.boundingRect() function to obtain the upper left corner coordinates (x, y), width w, and height h of the minimum rectangle that encloses the contour, and then calculate the area of ​​the rectangle. The formula is as follows:

[0108] Area = w*h

[0109] When traversing all contours, record the largest area value and the corresponding rectangle coordinates, and finally select the rectangle with the largest area as the minimum circumscribed rectangle contour.

[0110] S3: Customized algorithm for automated batch processing. After the tongue is segmented and processed, the minimum circumscribed rectangle of the tongue is determined, the upper, lower, left and right edges of the tongue are detected, the left and right boundary points, top and bottom boundary key points of the tongue in the image are determined, and four tangents are drawn according to the edge shape. The tangents are used as boundaries, and masks are created according to the corresponding polygonal areas to complete the area division and extraction, which are used to distinguish the tongue into the root, middle, inter-tongue and edge parts.

[0111] Calculate the left and right boundary points and the bottom boundary point. For the left boundary point, calculate the average value of the non-zero pixels in each column of the first 20 columns on the left side of the image. For the right boundary point, calculate the average value of the non-zero pixels in each column of the first 20 columns on the right side of the image. For the bottom boundary point, calculate the average value of the non-zero pixels in each row of the bottom 50 rows of the image. The above average values ​​are used to determine the boundary points of the tongue. The calculation formula is as follows:

[0112] Left boundary point:

[0113] leftPoint = [average non-zero pixel row position of the 20 columns to the left, 0]

[0114] Right boundary point:

[0115] rightPoint = [average non-zero pixel row position of the 20 columns on the right, image width]

[0116] Bottom boundary point:

[0117] bottomPoint = [image height, average non-zero pixel column position of the bottom 50 rows]

[0118] Compute the intercept and new x-coordinate, given a slope m and a point (x 1 ,y 1 ), calculate the intercept of the straight line on the y-axis, the formula is as follows:

[0119] Intercept = y 1 -m*x 1

[0120] Given the slope m and the point (x 1 ,y 1 ), and the new y coordinate y new , calculate the corresponding x coordinate, the formula is as follows:

[0121]

[0122] Calculate the slope and find the point with the maximum intercept, calculate the slope from the bottom boundary point to the left boundary point and the right boundary point, traverse the range of image height, use the calculate_intercept function to calculate the intercept of the left and right boundaries at each height, and select the point with the maximum intercept as the new boundary point. The formula is as follows:

[0123] Slope:

[0124]

[0125] Maximum intercept:

[0126] max_intercept=max(calculate_intercept(m,x,y))

[0127] Calculate the new upper and lower boundary points, use the slope and intercept calculated previously to determine the new left and right boundary points corresponding to the 1 / 5 height and 4 / 5 height, and use the calculate_x_for_y function to calculate the new x coordinate based on the slope, the given point coordinates, and the new y coordinate. The formula is as follows:

[0128] New upper boundary point:

[0129]

[0130] New lower boundary point:

[0131]

[0132] According to the calculated boundary points, the tongue is divided into different regions and saved in the corresponding folders. A polygon is created for each region, and a mask is generated using the polygon filling method. The mask is used to extract the corresponding region in the original image and saved in the corresponding folder.

[0133] Iterate over all images in the input path and call the main function to process each image. Use the glob function to find all file paths that match a specific pattern, iterate over these file paths, and call the main function to process each image.

[0134] Embodiment 2:

[0135] A method for viscera partitioning of a tongue image in traditional Chinese medicine based on edge detection comprises the following steps:

[0136] Step S1: image preprocessing;

[0137] Step S11: Identify the image and convert it into a grayscale image;

[0138] Step S12: image binarization;

[0139] Step S13: Determine the maximum circumscribed rectangular outline;

[0140] Step 2: Determine the key points;

[0141] Step 21: Calculate the average row coordinates of the first 20 columns of non-zero pixels on the left side to determine the ordinate of the left edge key point;

[0142] Step 22: Calculate the average row coordinates of the first 20 columns of non-zero pixels on the right side to determine the ordinate of the key point on the right edge;

[0143] Step 23: Calculate the average column coordinates of the non-zero pixels in the bottom 50 rows to determine the horizontal coordinate of the bottom of the tongue;

[0144] Step 3: Define slope and intercept auxiliary functions;

[0145] Step 4: left and right edge tangent fitting;

[0146] Step 41: Calculate the slopes of the left and right edges;

[0147] Step 42: traverse the left and right edge points and find the point with the maximum intercept, and determine the horizontal coordinates of the left and right edges by reference;

[0148] Step S43: Update the left and right slopes and fit;

[0149] Step 5: Calculate the left and right vertices and bottom points;

[0150] Step 51: According to the slope and key points of the left and right edges, calculate the horizontal coordinate at 1 / 5 of the height and determine the left and right vertices lt 1 and rt 1 ;

[0151] Step 52: According to the slopes and key points of the left and right edges, calculate the horizontal coordinates at the 4 / 5 height and determine the left and right bottom points lb 1 and rb 1 ;

[0152] Step 6: Calculate the intermediate transition point;

[0153] Step 61: Perform linear interpolation between the left vertex and the right vertex at a ratio of 1 / 5 and 4 / 5 to calculate the new left and right vertices lt 2 and rt 2 ;

[0154] Step 62: Perform linear interpolation between the left vertex and the left bottom point at a ratio of 1 / 5 and 4 / 5 to calculate the new left bottom point lb 2 ;

[0155] Step 63: Perform linear interpolation between the right vertex and the right bottom point at a ratio of 1 / 5 and 4 / 5 to calculate the new left bottom point rb 2 ;

[0156] Step 7: Update the slope;

[0157] Step 8: Calculate the new slope using the horizontal coordinate difference and height difference of the intermediate transition point to avoid the error that may be caused by directly using the original slope;

[0158] Step 8: Determine the final left and right vertices;

[0159] According to the new slope and intercept, calculate the horizontal coordinate of the top of the tongue (y=0) and determine the new left and right vertex positions lt 3 and rt 3 ;

[0160] Step 9: Extract area;

[0161] Create masks and extract according to the corresponding polygonal areas;

[0162] Finally, save the data.

[0163] Embodiment 3:

[0164] This trapezoidal partitioning rule is implemented based on Python language. The algorithm performs well. The details of the algorithm are as follows:

[0165] (1) Read the image and convert it into grayscale

[0166] Purpose: Read an image from a given path and convert it to a grayscale image to simplify subsequent image processing steps.

[0167] Implementation principle:

[0168] Images are usually stored in color formats (such as RGB or BGR format), while grayscale images only contain brightness information and no color information.

[0169] Converting the image to grayscale can simplify calculations and increase processing speed because only one channel of data needs to be processed instead of three (RGB).

[0170] (2) Binarization

[0171] Purpose: Convert grayscale images to binary images for easier contour detection.

[0172] Implementation principle:

[0173] Binarization converts the pixel values ​​in an image to one of two values ​​(usually 0 and 255), based on a set threshold.

[0174] Here, all pixel values ​​greater than 1 are set to 255 (white) and the rest are set to 0 (black). This effectively highlights the object (tongue) in the image and removes the background.

[0175] (3) Find the contour and find the largest contour

[0176] Purpose: Find all contours in a binary image and determine the largest contour that contains the tongue.

[0177] Implementation principle:

[0178] Contour detection is the process of extracting boundaries from a binary image. Each contour is a sequence of points that represent a closed curve in the image.

[0179] The function cv2.findContours provided by OpenCV can be used to find contours in an image.

[0180] By iterating over all found contours, calculating the area of ​​the bounding rectangle of each contour and selecting the one with the largest area, which usually corresponds to the main object in the image (in this case, the tongue).

[0181] (4) Crop the image to the largest contour area

[0182] Purpose: Crop the image based on the bounding rectangle of the largest contour to keep only the tongue part.

[0183] Implementation principle:

[0184] The bounding rectangle of the largest contour is the minimum circumscribed rectangular area of ​​the contour.

[0185] Use the coordinates of this rectangular area to crop the image after tongue segmentation, retaining only the tongue part and removing the redundant invalid area.

[0186] (5) Calculate the left and right boundary points and the bottom boundary point

[0187] Purpose: To determine the left and right boundary points and bottom boundary points of the tongue in the image for subsequent segmentation.

[0188] Implementation principle:

[0189] The positions of the left and right boundary points are determined by calculating the average value of the non-zero pixels (white pixels) in each column of the binary image.

[0190] By counting the non-zero pixels in each row, determine the location of the bottom boundary point.

[0191] These boundary points are used to define the shape and position of the tongue.

[0192] (6) Calculate the intercept and new x-coordinate function

[0193] Purpose: Define some helper functions so that in subsequent steps you can calculate the intercept of a line and the x-coordinate at a specific y-coordinate.

[0194] Implementation principle:

[0195] calculate_intercept: Calculates the intercept of a line based on its slope and the coordinates of a point.

[0196] calculate_x_for_y: Calculates the corresponding x-coordinate based on the slope, the coordinates of a point, and the new y-coordinate.

[0197] These functions are used in subsequent steps to calculate the slope and intercept of the tongue boundary.

[0198] (7) Calculate the slope and find the point of maximum intercept

[0199] Purpose: To determine the slope of the left and right borders of the tongue and find the point with the maximum intercept.

[0200] Implementation principle:

[0201] Calculate the slope from the base of the tongue to the left and right borders.

[0202] Traverse the height of the tongue, calculate the intercept of the left and right boundaries at each height, and select the point with the largest intercept as the new boundary point.

[0203] These boundary points are used to further subdivide the tongue region.

[0204] (8) Calculate the new upper and lower boundary points

[0205] Purpose: Calculate new upper and lower boundary points to segment the image more accurately.

[0206] Implementation principle:

[0207] Using the calculated slope and intercept, determine the locations of the new upper and lower boundary points.

[0208] These new boundary points are used to further refine the segmentation of the tongue region.

[0209] (9) Display the image and save different parts of the image

[0210] Purpose: According to the calculated boundary points, the tongue is divided into different areas (tongue root, left tongue edge, right tongue edge, tongue center, tongue tip) and saved in the corresponding folder.

[0211] Implementation principle:

[0212] Create a polygon for each region and use the fill polygon method to generate the mask.

[0213] Use the mask to extract the corresponding area in the original image and save it to the corresponding folder.

[0214] (10) Process all images

[0215] Purpose: Iterate over all images in the input path and call the main function to process each image.

[0216] Implementation principle:

[0217] Use the glob function to find all file paths that match a certain pattern.

[0218] Iterate through these file paths, calling the main function to process each image.

[0219] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.

[0220] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A method for viscera partitioning of TCM tongue images based on edge detection, characterized in that: The following steps are involved: S1: Use the built-in high-definition camera of the tongue diagnostic instrument to collect tongue images; S2: To avoid interference of human face on tongue segmentation, based on manual annotation of tongue, DeeplabV3+ semantic segmentation model is used to separate the tongue from the background, determine the minimum bounding rectangle and complete image cropping to remove redundant invalid areas. S3: Customized algorithm for automated batch processing. After the tongue is segmented and processed, the minimum enclosing rectangle of the tongue is determined, the upper, lower, left and right edges of the tongue are detected, the left and right boundary points, top and bottom boundary key points of the tongue in the image are determined, and four tangents are drawn according to the edge shape. The tangents are used as boundaries, and masks are created according to the corresponding polygonal areas to complete the area division and extraction.

2. The method for viscera partitioning of TCM tongue images based on edge detection according to claim 1, characterized in that: The specific steps include: Step S1: image preprocessing; Step S11: Identify the image and convert it into a grayscale image; Step S12: image binarization; Step S13: Determine the maximum circumscribed rectangular outline; Step 2: Determine the key points; Step 21: Calculate the average row coordinates of the first 20 columns of non-zero pixels on the left side to determine the ordinate of the left edge key point; Step 22: Calculate the average row coordinates of the first 20 columns of non-zero pixels on the right side to determine the ordinate of the key point on the right edge; Step 23: Calculate the average column coordinates of the non-zero pixels in the bottom 50 rows to determine the horizontal coordinate of the bottom of the tongue; Step 3: Define slope and intercept auxiliary functions; Step 4: tangent fitting of the left and right edges; Step 41: Calculate the left and right edge slopes; Step 42: traverse the left and right edge points and find the point with the maximum intercept, and determine the horizontal coordinates of the left and right edges by reference; Step S43: Update the left and right slopes and fit; Step 5: Calculate the left and right vertices and bottom points; Step 51: Calculate the horizontal coordinate at 1 / 5 of the height according to the slopes and key points of the left and right edges, and determine the left and right vertices lt1 and rt1; Step 52: Calculate the horizontal coordinate at the 4 / 5 height according to the slopes and key points of the left and right edges, and determine the left and right bottom points lb1 and rb1; Step 6: Calculate the intermediate transition point; Step 61: Perform linear interpolation between the left vertex and the right vertex at a ratio of 1 / 5 and 4 / 5 to calculate new left and right vertices lt2 and rt2; Step 62: Perform linear interpolation between the left vertex and the left bottom point according to the ratio 1 / 5 and 4 / 5 to calculate a new left bottom point lb2; Step 63: Perform linear interpolation between the right vertex and the right bottom point at a ratio of 1 / 5 and 4 / 5 to calculate a new left bottom point rb2; Step 7: Update the slope; Step 8: Calculate the new slope using the horizontal coordinate difference and height difference of the intermediate transition point to avoid the error that may be caused by directly using the original slope; Step 8: Determine the final left and right vertices; According to the new slope and intercept, the horizontal coordinate of the top of the tongue (y=0) is calculated to determine the new left and right vertex positions lt3 and rt3; Step 9: Extract area; Create masks and extract according to the corresponding polygonal areas; Finally, save the data.

3. The method for viscera partitioning of TCM tongue images based on edge detection according to claim 1 is characterized in that: Said S1 further comprises: Read the image from the given path and convert it to a grayscale image. Images are usually stored in color format, while grayscale images only contain brightness information, no color information. Converting an image to a grayscale image can simplify calculations and increase processing speed, because only one channel of data needs to be processed instead of three. Convert a grayscale image to a binary image. Binarization converts the pixel values ​​in an image to one of two values, based on a set threshold. Here, all pixel values ​​greater than 1 are set to 255, and the rest are set to 0. This can effectively highlight objects in the image and remove the background.

4. The method for viscera partitioning of TCM tongue images based on edge detection according to claim 1 is characterized in that: The S2 further comprises: Find contours and find the largest contour. Contour detection is the process of extracting boundaries from a binary image. Each contour is a sequence of points that represent a closed curve in the image. The function cv2.findContours provided by OpenCV can be used to find contours in an image. By traversing all found contours, calculating the area of ​​the bounding rectangle of each contour, and selecting the contour with the largest area, for each contour, use the cv2.boundingRect() function to obtain the upper left corner coordinates (x, y), width w, and height h of the minimum rectangle that encloses the contour, and then calculate the area of ​​the rectangle. The formula is as follows: Area = w*h When traversing all contours, record the largest area value and the corresponding rectangle coordinates, and finally select the rectangle with the largest area as the main contour. Crop the image to the largest contour area. The bounding rectangle of the largest contour provides the minimum rectangular area containing the contour. Use the coordinates of this rectangular area to crop the original image, retaining only the tongue part and removing the background and other irrelevant parts.

5. The method for viscera partitioning of TCM tongue images based on edge detection according to claim 1, characterized in that: The S3 further comprises: Calculate the left and right boundary points and the bottom boundary point. For the left boundary point, calculate the average value of the non-zero pixels in each column of the first 20 columns on the left side of the image. For the right boundary point, calculate the average value of the non-zero pixels in each column of the first 20 columns on the right side of the image. For the bottom boundary point, calculate the average value of the non-zero pixels in each row of the bottom 50 rows of the image. The above average values ​​are used to determine the boundary points of the tongue. The calculation formula is as follows: Left boundary point: leftPoint = [average non-zero pixel row position of the 20 columns to the left, 0] Right boundary point: rightPoint = [average non-zero pixel row position of the 20 columns on the right, image width] Bottom boundary point: bottomPoint = [image height, average non-zero pixel column position of the bottom 50 rows] Calculate the intercept and new x-coordinate. Given a slope m and a point (x1, y1), calculate the intercept of the line on the y-axis. The formula is as follows: Intercept = y1-m*x1 Given the slope m and the point (x1, y1), and the new y coordinate y new , calculate the corresponding x coordinate, the formula is as follows: Calculate the slope and find the point with the maximum intercept, calculate the slope from the bottom boundary point to the left boundary point and the right boundary point, traverse the range of image height, use the calculate_intercept function to calculate the intercept of the left and right boundaries at each height, and select the point with the maximum intercept as the new boundary point. The formula is as follows: Slope: Maximum intercept: max_intercept=max(calculate_intercept(m,x,y)) Calculate the new upper and lower boundary points, use the slope and intercept calculated previously to determine the new left and right boundary points corresponding to the 1 / 5 height and 4 / 5 height, and use the calculate_x_for_y function to calculate the new x coordinate based on the slope, the given point coordinates, and the new y coordinate. The formula is as follows: New upper boundary point: New lower boundary point: According to the calculated boundary points, the tongue is divided into different regions and saved in the corresponding folders. A polygon is created for each region, and a mask is generated using the polygon filling method. The mask is used to extract the corresponding region in the original image and saved in the corresponding folder. Iterate over all images in the input path and call the main function to process each image. Use the glob function to find all file paths that match a specific pattern, iterate over these file paths, and call the main function to process each image.

Citation Information

Cited By

  • Adaptive lingual surface partitioning method and system and medium

    CN121353290A

  • A lingual surface adaptive partitioning method, system, and medium

    CN121353290B