Exploiting the Similarity of Top 100 Beauties for Hairstyle Recommendation via Perceptual Hash

. In recent years, with the fast development of the fashion industry, the definition of beauty is constantly changing and the diversity of women's hair-styles always gives us a dazzling feeling. Most young female would like to pursue the varying fashion trend and change a hairstyle to meet the fashion requirements. How to choose an appropriate fashion hairstyle has become a critical issue for modern fashion women. In this paper, we design and implement a C++ based female hairstyle recommendation system. At first, the selected top 100 beauties per year in the world are collected for building the beauty standard. Then, considering the changing female status (e.g., age, weight), perceptual hash algorithm (pHash) is used to calculate the global similarity between the user and 100 beauties for selecting the appropriate hairstyle. Finally, the comprehensive rank results from more than 350 demonstrate the recommended hairstyle is preferred.


Introduction
Modern women pay more and more attention to fashion experience.Fashion expression is not only on clothing, but also on hairstyle.The common recommendation modules include Amazon's "guessing you like" block, and so on.It uses an object based collaborative filtering algorithm [1].The key is that the system will record the user's previous search records to understand the user's preferences.At present, there is no recommendation system software for users to recommend hairstyles, most of them are similar to Meitu and other beauty software included in the wearing hairstyle model, users to speculate whether the hairstyle is suitable for itself.Obviously, there is a problem that the accuracy of hairdressing after face beauty treatment.This paper discusses the techniques of recommendation based on machine learning, image data processing and image similarity calculation, which are recommended by the data set with the similarity of the user's face, which is more pertinent, and can solve the current problem which is difficult to personalized recommendation for the user's hair.The implementation of the hairstyle recommendation system can provide a quick hairstyle choice for female users.
This paper is organized as follow: Section 1 introduces the brief information and Section 2 presents the related work.Section 3 provides the detailed hairstyle recommendation design.Section 4 describes the implementation for hairstyle recommendation and Section 5 is the results analysis, and Section 6 concludes the entire work.

Related Work
A perfect hairstyle could enhance anyone's self-confidence, especially women.However, in order to choose a good hairstyle, one was limited to rely on knowledge of a beauty expert.Wisuwat Sunhem, et.al presented a hairstyle recommendation system for women based on hairstyle experts' knowledge and a face shape classification scheme [2].The system classified the user's face shape into five categories which were suitable for hairstyle recommendation using Support Vector Machine algorithms.
The hairstyle e rules were based on beauty experts' suggestions.The system is based on the fine grained similarity of face shape.However, human face shape change over time.For example, getting fat due to higher work pressure can change the shape of a person's face.Therefore, our focus is to design and implement a coarse-grain similarity of face shape for hairstyle recommendation.
Everyone has different understanding of the concept of beauty.It is difficult to define most of the things that most people think of beauty.However, at this stage, there are many media widely selected beauty.The result of the selection makes people have a certain grasp of the fashion trend.Because of the social effect, women will choose the hair, makeup, dress and so on, which makes the hairstyle recommendation have the standard of beauty.Therefore, how to define and verify the beauty is also our important work in the hairstyle recommendation.

3
Proposed Hairstyle Recommendation System

Overall framework
The three parts of the design of the hairstyle recommendation system based on machine learning are functional requirement analysis, module analysis and algorithm design analysis.Functional requirement analysis mainly explains the modules needed by the system and the functions that each module needs to achieve.Module analysis is also the structural division of the system.At the present stage, data acquisition, data updating, face detection, recommendation processing and recommendation results display are divided into three parts.Algorithm analysis is mainly about the content of image similarity.The overall design idea of the system is shown in Figure .1.User function modules include registration, login, password modification, uploading and saving pictures, face detection, hairstyle data set update, user view of recommended hairstyle results and data collection material display.

Data collection and pre-handling
Although people can feel beauty and recognize beauty, there are many different answers to the question of "what is beauty".Beauty is a subjective feeling.If something is in line with people's aesthetic sense, then it is said that this thing is beautiful.Similarly, the beauty of the world elected annually is most commonly recognized as "beauty".Beauty is the effect produced by all things.A person is beautiful, and we can think that the hairstyle that she owns is beautiful.Therefore, the 2013-2017 years of the TC Candle website [7] recommended by the hairstyle recommender system is selected as a dataset.The acquisition of data sets adopts the way of intercepting and saving video frames in a fixed time interval.Female users recommend different data sets according to their favorite trends.For example, some people like retro wind and some like new trends.The advantage of the system data set design is to provide users with more varied choices of hairstyles.
The data sets are used for face detection, and the face part is detected and preserved.This step completes the image preprocessing operation, and the final recommendation results are based on the similarity ratio between the user's face and the beautiful face of the data set.

Perceptual hash based recommendation
When most pictures are converted to frequency domain, their coefficients are basically 0, which is determined by the redundancy and relevance of pictures.The key technique for the search of similar pictures in Google or Baidu's map function is called "perceptual Hash algorithm" [3].The function is to generate a "fingerprint" string for each picture, and to compare the similarity of the picture by comparing the fingerprints produced by different pictures.The common perceptual hashing algorithm is divided into low frequency perceptual hashing algorithm, dHash algorithm and pHash algorithm.The pHash algorithm is used in this system.
Although the mean hash algorithm based on low frequency is simple, there are many factors that can affect the mean value, and the reliability is reduced.In each step of perceptual hash algorithm, histogram equalization is needed, which will affect the mean size and affect the hash value.Then, the enhanced version of pHash algorithm can solve this problem well, and get low-frequency components with DCT transform.The working process of the pHash algorithm is shown in Figure .3.• Calculate the hash value: if the DCT value of the pixel is greater than or equal to the DCT mean, then it is set to "1", and the less than DCT mean is set to "0".In this way, a 64 bit binary number, the hash value of a picture, is formed by comparison.

Figure. 3. pHash algorithm flow chart
When most pictures are converted to frequency domain, their coefficients are basically 0, which is determined by the redundancy and relevance of pictures.The more similar the pictures' hash value is, the more similar the picture is.the system uses the perceptual Hash algorithm to find the largest image of the person's face in a number of data sets and recommends it.In the perceptual Hash algorithm, the pHash algorithm is improved on the original low frequency perception Hash algorithm.In summary, the system uses the pHash algorithm to convert the data to a hash value. (

2) Similarity algorithm
The core of recommendation algorithm is to measure the similarity of faces between users and data sets.Here we use the pHash algorithm in perceptual hashing algorithm to get hash value.Next, we need to compare the similarity of hash values produced by different images.The following is the image Hash similarity measure method.Let S 1 , S 2 be a hash sequence of length N, where S 1 (i) and S 2 (i) are the i elements in S 1 and S 2 sequences, respectively, D (S 1 , S 2 ) is a similar measure of hash S 1 and S 2.

1) Hamming distance.
Hamming distance, also called Hing distance, requires hash sequence as a 0/1 form.The method of measuring the difference is by comparing the number of different values of the corresponding position 0/1 of the two sequences.The size of the Hamming distance is proportional to the size of the corresponding image difference, that is, the larger the value is, the larger the image difference is, the more novel the value is, the more novel a map is.The smaller the difference in content is [12].The formula of Hamming distance described in equation (1):

2) Correlation coefficient
Correlation coefficient is used to distinguish the linear degree between the hash sequences obtained by the image.The calculation formula of correlation coefficient is equation (2).The larger value represents the higher similarity.
C(s ,s ) D(s , s ) V(s ) V(s ) 3) Euclidean distance Euclidean distance, also known as Euclidean distance, measures the absolute distance between two hash sequences.The Euclidean distance of the two images of hash S1 and S2 is as follows in equation(3): Generally, the smaller the value, the more similar between the two images; on the contrary, the greater the value, the greater the difference in the image, but the Euclidean distance measurement has a very obvious disadvantage, which is influenced by the scale of different units of the index.

4) Norm
The norm is also the Minkowski distance.The norm between the two image hash sequences is defined as follows in equation ( 4), where P is a parameter.

5) Angle cosine
The angle cosine method compares the degree of difference in the two vector directions, takes the Hash sequence as a vector, and uses the angle cosine method to make the qualitative measure.The definition of the angle cosine is shown in equation ( 5): ( ) (5) The angle of the angle is from 0 to 90 degrees.The bigger the angle cosine value is, the greater the difference is.
In the process of similarity measurement, pHash chooses Hamming distance [4].The advantage is that the algorithm runs fast and ignores image scaling.Therefore, Hairstyle recommendation system adopts Hamming distance to measure similarity due to its simple idea and high efficiency.

Haar feature classified
The program uses the haar feature classifier [5] in OpenCV to realize the face detection function.OpenCV provides a set of object detection function.After training, it can detect any object you need.The library has many test parameters that can be directly used for many scenes, such as face, eyes, mouth, body, upper body, lower body and smiling face.The detection engine consists of a very simple detector cascade.These detectors are called Haar feature detectors, each of which has different scales and weights.In the training phase, the decision tree is optimized by known correct and wrong pictures.After initializing the face detector with the required parameters, it can be used for face detection.In the detection process, the trained classifier traverses each pixel of the input image with different scales to detect faces of different sizes.

Programming language
The system uses the C++ language [6] to develop, the hair recommendation system mainly uses the image processing technology.Because of the large amount of data, the time consumption of image processing is more than that of the general algorithm.Then, it is very important to improve the processing efficiency for improving the time consumption.The C++ language has the following advantages: 1)high flexibility.For example, C++ language uses pointer and pointer to realize dynamic memory allocation.2) the rate of memory utilization is improved.There is a limit to the memory of the computer.Large quantities of images take up a lot of memory resources.However, the C++ language can achieve direct allocation and release of memory, thus improving the memory utilization.3)it has rapid execution efficiency.The compiled language generated by the C++ language is the executable code.It can run directly on the processor.

Critical persuade code for hairstyle recommendation
As Figure4 shows, the hairstyle recommendation module recommends the corresponding hairstyle pictures based on the name of the input user picture, and the fifth line pseudo code calls the CalHashValue function to transform the picture into a string by using the pHash algorithm.In line 3 to line7, pseudo code realizes the Hamming distance value of the string corresponding to the user picture and the string corresponding to each picture in the dataset.The operation of pseudo code in line 8 to line 13 is to find out the smallest picture with Hamming distance.The corresponding picture is finally displayed.

Results and Analysis
The system is composed of six main parts.The system login interface, as shown in Figure .5(a), is successfully entered into the main interface of the system through the login system after the login account.In the main interface shown in Figure.After the completion of the system design and the test work, in order to understand the satisfaction of the user to the results of the recommendation, an online questionnaire is set up.The content of the questionnaire is to give a user picture as a topic, and let the investigators anonymous to the user's hairstyle recommended by the hairstyle recommendation system (in this case, the recommended hairstyle 1) and the other two hairstyle pictures (recommended hairstyle 2 and recommended hairstyle 3) are sorted.After the online questionnaire was released, a total of 352 questionnaires were collected.The wide range of respondents has enhanced the credibility of the survey results.After recommending the system to test the user's picture, the recommended hairstyle is recommended hairstyle 1.The average comprehensive score of the options is calculated automatically according to the sorting of all the candidates.It reflects the comprehensive ranking of the options, and the higher the score is, the better the comprehensive ranking is.The calculation method is as follows in eq (6): (frequency* weight) Averagescore Number = ∑ (6) The variable Number refers to the number of people filling in the questionnaire and the weight is determined by the position of the option being arranged.For example, there are 3 options for sorting, the weight in the first place is 3, the second position is 2, and the third position is 1.The results of the statistical analysis of the questionnaire are shown in Figure .6(a)and the ratio of the recommended hairstyle 1 to the first is shown in Figure .6(b).From the graph, we can see that the user satisfaction of hairstyle recommendation system recommended is high, which proves that the hairstyle recommendation system has great application prospects.Considering the disagreement between people in different regions, the survey of online questionnaires is widely distributed, accounting for 88.6% of China's region, as shown in Figure .Average score

Conclusion
The hairstyle recommendation system recommends is based on the face coarsegrain global similarity, the benefit lies in ignoring the external influence factors of the face change, and can provide the hair recommendation reference for the fashionable female users quickly and effectively.Based on a lot of survey work and analysis, this paper has stipulated the standard of hairstyle beauty.The dataset is updatable and scalable, so that users can choose different data sets according to their preferences.The user uploads the picture to be recommended.Then, face detection module keeps only the valid face information of the user's picture.Finally, the system compares the face part of the user picture with the data set, and draws the most similar face, and recommends its corresponding hairstyle.In addition, user satisfaction surveys were conducted on the results of the system hairstyle recommendation, and the user satisfaction rate of the recommended hairstyle was 23.4% higher than the average satisfaction.

•
Reduce the size: use small pictures, but at least more than 8*8, where 32*32 is the best size.Reducing the size of the picture simplifies the calculation of DCT.• Simplify the color: transform the image into grayscale image, discard the color factors of the image, and further simplify the computation.• Calculate DCT: DCT transform and get the DCT coefficient matrix of 32*32.• Reduce DCT: just keep the 8*8 matrix in the upper left corner, because this part presents the lowest frequency in the picture.• Calculate the mean value: the mean of DCT is calculated.

Figure. 6 .
Figure. 6. Survey results of user satisfaction.(a)Comprehensive ranking results;(b) Recommended hairstyle for the first place;(c) Geographic distribution map of the respondents.