A method for measuring hair diameter based on deep learning and digital image processing
By using deep learning and digital image processing technologies, the system identifies the hair root region and performs image analysis, solving the problem of inconvenient hair diameter detection and enabling convenient and low-cost hair health monitoring.
Patent Information
- Application Number
- CN202111485267.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-07
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2041-12-07
AI Technical Summary
Existing technologies cannot easily quantify hair health status, especially the detection of hair diameter, making it impossible to achieve real-time and long-term hair health monitoring.
A method based on deep learning and digital image processing is used to identify the hair root region by training a model, and to calculate the hair diameter by combining KMEANS clustering segmentation, CANNY edge detection and HOUGH transform line detection.
It enables rapid and efficient detection of hair diameter, supports operation on portable devices, and allows for convenient and low-cost monitoring of hair health.
Smart Images

Figure CN116245785B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of hair health status indicator monitoring, and relates to a method for measuring hair diameter based on deep learning and digital image processing. Background Technology
[0002] In today's fast-paced work and life environment, with the increasing number of people experiencing hair loss, people's attention to hair health is also growing daily. A plethora of hair growth and care products and methods have emerged; however, the long hair growth cycle means that noticeable results are difficult to observe with the naked eye in the short term. Therefore, the need for quantifying hair health indicators is urgent in the monitoring of hair health. Hair diameter, as an important indicator of hair health, is therefore particularly important.
[0003] The diameter of a hair strand itself cannot be measured using ordinary measuring tools. For the general public, the usual method is to go to a hospital for testing, which only provides information on the hair's health status at a specific moment, making it inconvenient and unsuitable as a real-time, long-term monitoring solution. For research institutions, this requires purchasing expensive testing equipment, significantly increasing costs. Therefore, we propose a hair diameter measurement method based on deep learning and digital image processing. This method enables the testing process to be completed on inexpensive portable devices, solving the problem of inconvenient hair health monitoring. Summary of the Invention
[0004] To address the shortcomings of current conventional hair quality testing methods, a hair diameter calculation method based on deep learning and digital image processing is proposed, which solves the problem of inconvenient hair diameter detection.
[0005] This invention provides a rapid and efficient method for detecting hair diameter, employing the following technical solution: In traditional deep learning-based target detection, hair is dense and intersecting, making feature extraction difficult. Therefore, this invention innovatively selects the hair root region as the feature region to be detected. A model file capable of correctly identifying the hair root region is trained through deep learning, and based on this model, target detection and hair data analysis are performed on the image data. The specific implementation includes the following steps:
[0006] Step 1:
[0007] Data collection and model training: Approximately 10,000 images of thick hair and sparse hair in the hair loss area were collected from different groups of people. The hair root area was labeled and trained on the YOLOV5 model to obtain a model file that can effectively detect the hair root area. The model file was then converted into param and bin files supported by the NCNN network and proceeded to step two.
[0008] Step Two:
[0009] Hair image acquisition: Under the premise of ensuring image clarity, an image acquisition device can be used to acquire an image of any size and resolution, and the image is Gaussian blurred before proceeding to step three;
[0010] Step 3:
[0011] Object detection: Under the NCNN network architecture, object detection is performed on the acquired image to obtain the rectangular coordinates of the hair root region. Steps four to twelve are executed iteratively for each detected hair root region.
[0012] Step Four:
[0013] KMEANS Clustering Segmentation: Perform KMEANS clustering segmentation on each pixel in the detected hair root region image data. Set the number of categories to any integer value >=2, and calculate the sum of the mean values of all pixels represented by different labels in the original image data on the RGB three channels. Take the category with the smaller sum of mean values as the hair data label, and perform a masking operation on the original image data according to the hair data label to generate new image data, and then proceed to step five;
[0014] Step 5:
[0015] CANNY edge detection: Perform CANNY edge detection on the newly generated image data, taking the parameter ratio as 2 or 3 and minThreshold as any suitable value between 100 and 250 to obtain the edge point set, and then proceed to step six;
[0016] Step Six:
[0017] Hough Transform Line Detection: For the edge point set, perform Hough transform line detection. The default threshold is any value count greater than or equal to 5. Perform Hough transform line detection. If the number of lines obtained is greater than count, then threshold = threshold + 1. Repeat this operation until the number of lines obtained is less than or equal to count, then exit the loop. Under this threshold, perform Hough transform line detection to obtain the set of lines to be selected. Each line in the line set contains three parameters: rho, theta, and votes. Compare the angle value theta in the line set with the threshold thetaThreshold. The threshold thetaThreshold can be any integer multiple of PI / 180. If it is, proceed to step eight; otherwise, proceed to step seven.
[0018] Step Seven:
[0019] Line parameter transformation: Reset the theta value of the line to 0, and perform the following transformation on the corresponding rho value: The original line intersects the upper and lower edges of the corresponding local region image at two points (x1, y1) and (x2, y2). Approximately take rho = (x1 + x2) / 2, and go to step eight.
[0020] Step 8:
[0021] Sort the lines by theta value: Arrange all lines in ascending order of theta value, then proceed to step nine;
[0022] Step Nine:
[0023] The lines are classified according to the theta difference: The theta value of the first sorted line is used as the comparison object compareTheta. The difference between the theta value of the remaining lines and compareTheta is compared with the threshold thetaThreshold. The threshold thetaThreshold can be any integer multiple of PI / 180. If the difference is less than the threshold thetaThreshold, they are classified into the same category. Otherwise, they are classified into a new category, and compareTheta is reset to the theta value of the line. This process is repeated until all lines are classified. For each group of lines, if the number of lines is >= 2, it is a valid category and the process proceeds to step ten. Otherwise, it is an invalid category and the group of lines is discarded.
[0024] Step 10:
[0025] Segmenting left and right edges: The lines are arranged in ascending order of rho value and divided into left and right categories, representing the left and right edge lines respectively. When there are a total of n lines with indices of 0 – (n-1), the compactness of the lines divided into left and right categories from index (0) to index (n-2) is iterated. The sum of the absolute values of the differences between the rho values of all lines in the left and right categories and the average rho value is taken as compactnessL and compactnessR. The overall compactness = compactnessL + compactnessR. The category index with the smallest compactness value is selected, and the group of lines is divided into left and right categories, representing the left and right edge line groups respectively. Proceed to step eleven.
[0026] Step Eleven:
[0027] Select edge lines: Select the optimal line as the left and right edge lines respectively, in order of priority from the line with the smallest angle difference to the line with the largest sum of votes; then proceed to step 12.
[0028] Step Twelve:
[0029] Calculate the diameter: the absolute value of the difference in rho values between straight lines multiplied by the conversion ratio of each pixel to the actual size, ultimately yielding the diameter of the hair. Attached Figure Description
[0030] Figure 1 A flowchart of a method for measuring hair diameter based on deep learning and digital image processing.
[0031] Figure 2 : A schematic diagram of the line parameter transformation process when the line angle is greater than the threshold. Detailed Implementation
[0032] Figure 1 This is a flowchart of the hair diameter measurement method based on deep learning and digital image processing according to the present invention. The following will describe the implementation details to be aware of during the specific implementation process, as well as optional solutions for some implementation steps, in conjunction with the flowchart.
[0033] Step 1:
[0034] Data collection and model training: Approximately 10,000 images of thick hair and sparse hair in the hair loss area were collected from different groups of people. The hair root area was labeled and trained on the YOLOV5 model to obtain a model file that can effectively detect the hair root area. The model file was then converted into param and bin files supported by the NCNN network and proceeded to step two.
[0035] Since the focus in the later stages will be on detecting the diameter of newly grown hairs, which are mostly fine, soft, and whitish in color, it is essential to collect sufficient data during the initial training dataset collection. Attention must be paid to focus, and the images taken must be clear. When marking the hair root area, the size of the rectangle should be appropriate. Only in this way can good detection results be achieved in the recognition of newly grown hairs.
[0036] Step Two:
[0037] Hair image acquisition: Under the premise of ensuring image clarity, an image acquisition device can be used to acquire an image of any size and resolution, and the image is Gaussian blurred before proceeding to step three;
[0038] When acquiring hair images, pay attention to focusing and adjusting the light brightness to avoid blurry images due to reflections or defocusing, which would prevent them from being detected correctly.
[0039] Step 3:
[0040] Object detection: Under the NCNN network architecture, object detection is performed on the acquired image to obtain the rectangular coordinates of the hair root region. Steps four to twelve are executed iteratively for each detected hair root region.
[0041] Since the hair detection results based on this invention are real-time and convenient, their advantages should be fully utilized, and the average value of multiple detection results from multiple regions should be used as the final result.
[0042] Step Four:
[0043] KMEANS Clustering Segmentation: Perform KMEANS clustering segmentation on each pixel in the detected hair root region image data. Set the number of categories to any integer value >=2, and calculate the sum of the mean values of all pixels represented by different labels in the original image data on the RGB three channels. Take the category with the smaller sum of mean values as the hair data label, and perform a masking operation on the original image data according to the hair data label to generate new image data, and then proceed to step five;
[0044] This invention is based on the classification number K=2. If the hair image data is noisy in actual situations, K=3 or K=4 can be set as appropriate to achieve good classification results.
[0045] Step 5:
[0046] CANNY edge detection: Perform CANNY edge detection on the newly generated image data, taking the parameter ratio as 2 or 3 and minThreshold as any suitable value between 100 and 250 to obtain the edge point set, and then proceed to step six;
[0047] In some cases, due to reflections or defocusing of the source image, the color of the captured hair image may be slightly whitish, resulting in ghosting on both the left and right edges of the hair after KMEANS classification. In this case, consider removing the operation in step four, with a preset ratio of 2 and minThreshold of 5, and directly perform Canny detection on the source image. Compare the total number of pixels at the detected edge points to the total number of pixels in the hair root region image. If it is greater than a certain threshold, then minThreshold is increased by 1. Repeat this operation until it is less than or equal to the threshold. After extensive experimental comparison, setting this value to 6% can achieve very good results.
[0048] Step Six:
[0049] Hough Transform Line Detection: For the edge point set, perform Hough transform line detection. The default threshold is any value count greater than or equal to 5. Perform Hough transform line detection. If the number of lines obtained is greater than count, then threshold = threshold + 1. Repeat this operation until the number of lines obtained is less than or equal to count, then exit the loop. Under this threshold, perform Hough transform line detection to obtain the set of lines to be selected. Each line in the line set contains three parameters: rho, theta, and votes. Compare the angle value theta in the line set with the threshold thetaThreshold. The threshold thetaThreshold can be any integer multiple of PI / 180. If it is, proceed to step eight; otherwise, proceed to step seven.
[0050] After Hough transform line detection, lines passing through a certain number of edge points can be detected. In this invention, the number of lines selected is 5, considering the case where the detection area has at most two evenly distributed hairs. Alternatively, in reality, there are often cases where a single hair follicle contains three or more hairs; in such cases, the number of HoughLines should be increased accordingly. It is recommended to use the method of HoughLine number = maximum number of hairs x 2.5. Conversely, if such a situation does not exist, the number of HoughLines can be appropriately increased, but it should not be too large, otherwise it will generate too much noisy line data.
[0051] Step Seven:
[0052] Line parameter transformation: Reset the theta value of the line to 0, and perform the following transformation on the corresponding rho value: The original line intersects the upper and lower edges of the corresponding local region image at two points (x1, y1) and (x2, y2). Approximately take rho = (x1 + x2) / 2, and go to step eight.
[0053] Figure 2 The example illustrates the principle of line transformation. The reason for transforming lines close to PI is that when the angle of a line is close to 0 or PI, they are close in terms of actual position information. However, if we compare the angle values of the lines, the difference is large, and the lines cannot be correctly classified.
[0054] Step 8:
[0055] Sort the lines by theta value: Arrange all lines in ascending order of theta value, then proceed to step nine;
[0056] The purpose of sorting is to facilitate the comparison of angle values and group similar lines into the same category.
[0057] Step Nine:
[0058] The lines are classified according to the theta difference: The theta value of the first sorted line is used as the comparison object compareTheta. The difference between the theta value of the remaining lines and compareTheta is compared with the threshold thetaThreshold. The threshold thetaThreshold can be any integer multiple of PI / 180. If the difference is less than the threshold thetaThreshold, they are classified into the same category. Otherwise, they are classified into a new category, and compareTheta is reset to the theta value of the line. This process is repeated until all lines are classified. For each group of lines, if the number of lines is >= 2, it is a valid category and the process proceeds to step ten. Otherwise, it is an invalid category and the group of lines is discarded.
[0059] This invention considers comparing each group of straight line classifications with the minimum theta value of that group. When there are intersecting hairs and the intersection angle is small, or when there are too many hairs, it is advisable to consider using the current maximum angle (i.e., the angle value of the current last straight line) of each group of straight line classifications as the comparison value during cyclic grouping.
[0060] Step 10:
[0061] Segmenting left and right edges: The lines are arranged in ascending order of rho value and divided into left and right categories, representing the left and right edge lines respectively. When there are a total of n lines with indices of 0 – (n-1), the compactness of the lines divided into left and right categories from index (0) to index (n-2) is iterated. The sum of the absolute values of the differences between the rho values of all lines in the left and right categories and the average rho value is taken as compactnessL and compactnessR. The overall compactness = compactnessL + compactnessR. The category index with the smallest compactness value is selected, and the group of lines is divided into left and right categories, representing the left and right edge line groups respectively. Proceed to step eleven.
[0062] When calculating compactness, this invention takes into account the large difference in rho values between the left and right lines, and uses the sum of the absolute values of the differences between each rho value and the average rho value to achieve good results. Alternatively, methods such as variance can also be considered.
[0063] Step Eleven:
[0064] Select edge lines: Select the optimal line as the left and right edge lines respectively, in order of priority from the line with the smallest angle difference to the line with the largest sum of votes; then proceed to step 12.
[0065] When the number of HoughLines selected in step six is large, each group of left and right edge lines may contain a large number of lines. The strategy adopted in this invention is to first compare the differences in angles of the left and right lines in a cyclical manner, and take the two lines with the smallest difference, i.e., the most parallel lines. When there are multiple results in this case, consider the case with the largest sum of left and right votes, i.e., the line that passes through the most edge points. If there are still cases with the same priority after two rounds of priority comparison, the optimal result can be obtained by averaging the theta and rho values.
[0066] Step Twelve:
[0067] Calculate the diameter: the absolute value of the difference in rho values between straight lines multiplied by the conversion ratio of each pixel to the actual size, ultimately yielding the diameter of the hair.
[0068] Considering that the normal size of healthy hair ranges from 40-90 microns, and that newly grown hair may be significantly smaller than 40 microns, the difference in rho values between the two straight lines at the left and right edges calculated in this step, multiplied by the pixel conversion factor, should be considered. Values that are too small or too large should be discarded. The pixel conversion ratio is determined by both the selected image resolution and the actual area captured.
Claims
1. A method for measuring hair diameter based on deep learning and digital image processing, comprising the following steps: Step 1: Data collection and model training: Ten thousand images of thick hair and sparse hair in the hair loss area were collected from different groups of people. The hair root area was labeled and trained on the YOLOV5 model to obtain a model file that can effectively detect the hair root area. The model file was then converted into param and bin files supported by the NCNN network and proceeded to step two. Step Two: Hair image acquisition: Under the premise of ensuring image clarity, select an image acquisition device to acquire an image of any size and resolution, and apply Gaussian blur to the image before proceeding to step three; Step 3: Object detection: Under the NCNN network architecture, object detection is performed on the acquired image to obtain the rectangular coordinates of the hair root region. Steps four to twelve are executed iteratively for each detected hair root region. Step Four: KMEANS Clustering Segmentation: Perform KMEANS clustering segmentation on each pixel in the detected hair root region image data, set the number of categories to N, N≥2, calculate the sum of the mean values of all pixels corresponding to each label in the RGB three channels, sort all labels in ascending order according to the value of the sum of the mean values, determine the first label after sorting as the hair data label, and perform a masking operation on the original image data according to the hair data label to generate new image data, and then proceed to step five; Step 5: CANNY edge detection: Perform CANNY edge detection on the newly generated image data, taking the parameter ratio as 2 or 3 and minThreshold as any value between 100 and 250 to obtain the edge point set, and then proceed to step six; Step Six: Hough Transform Line Detection: In the Hough transform algorithm, a polar coordinate system is established with the top left corner of the image as the origin. rho represents the distance from the origin to the line, in pixels; theta represents the angle between the line and the x-axis of the image, in radians; and votes is the number of pixels contained in the detected line. The input of this algorithm is the image and the threshold for the minimum number of pixels that a line should contain. The output is a set of detected lines, and each line in the set contains the corresponding rho, theta, and votes values. For the edge point set, perform Hough transform line detection. The preset value of the number of lines to be detected, count, is 5. The threshold of the Hough detection algorithm is 5. Perform Hough transform line detection. If the number of lines obtained is greater than count, then threshold = threshold + 1. Repeat this operation until the number of lines is less than or equal to count, then exit the loop. Under this threshold, perform Hough transform line detection to obtain the set of lines to be selected. Each line in the set of lines contains three parameters: rho, theta, and votes. Compare the angle value theta in the set of lines to see if it is less than the threshold thetaThreshold. The threshold thetaThreshold is set to any integer multiple of PI / 180. If it is, proceed to step eight; otherwise, proceed to step seven. Step Seven: Line parameter transformation: Reset the theta value of the line to 0, and perform the following transformation on the corresponding rho value: The original line intersects the upper and lower edges of the corresponding local region image at two points (x1, y1) and (x2, y2), take rho = (x1 + x2) / 2, and go to step eight; Step 8: Sort the lines by theta value: Arrange all lines in ascending order of theta value, then proceed to step nine; Step Nine: The lines are classified according to the theta difference: The theta value of the first sorted line is used as the comparison object compareTheta. The difference between the theta value of the remaining lines and compareTheta is compared with the threshold thetaThreshold. The threshold thetaThreshold is set to any integer multiple of PI / 180. If the difference is less than the threshold thetaThreshold, they are classified into the same category. Otherwise, they are classified into a new category, and compareTheta is reset to the theta value of the line. This process is repeated until all lines are classified. For each group of lines, if the number of lines is greater than or equal to 2, it is considered a valid category and the process proceeds to step ten. Otherwise, it is considered an invalid category and the group of lines is discarded. Step 10: Segmenting left and right edges: The lines are arranged in ascending order of rho value and divided into left and right categories, representing the left and right edge lines respectively. When there are a total of n lines with indices of 0–(n-1), the compactness of the lines from index (0) to index (n-2) when they are divided into left and right categories is executed in a loop. The sum of the absolute values of the differences between the rho values of all lines in the left and right categories and the average rho value is taken as compactnessL and compactnessR. The overall compactness = compactnessL + compactnessR. The category index with the smallest compactness value is selected, and the group of lines is divided into left and right categories, representing the left and right edge line groups respectively. Proceed to step eleven. Step Eleven: Select edge lines: Select the optimal line as the left and right edge lines respectively, in order of priority from the line with the smallest angle difference to the line with the largest sum of votes; then proceed to step 12. Step Twelve: Calculate the diameter: Multiply the absolute value of the difference between the rho values of the left and right edge lines by the conversion ratio of each pixel to the actual size to obtain the diameter of the hair.
Citation Information
Patent Citations
System and method for measuring hair diameter
CN107645925A
Hair type recognition method and device, electronic equipment and storage medium
CN111325173A