{"id":619,"date":"2017-11-22T15:42:07","date_gmt":"2017-11-22T14:42:07","guid":{"rendered":"https:\/\/eaa-online.org\/arc\/blog\/blog\/use-python-calculate-facial-width-height-ratio-fwhr\/"},"modified":"2022-10-17T15:23:03","modified_gmt":"2022-10-17T13:23:03","slug":"use-python-calculate-facial-width-height-ratio-fwhr","status":"publish","type":"post","link":"https:\/\/eaa-online.org\/arc\/blog\/2017\/11\/22\/use-python-calculate-facial-width-height-ratio-fwhr\/","title":{"rendered":"Use Python to calculate the facial width to height ratio (fWHR)"},"content":{"rendered":"<p>There is a rise of papers that calculate the Facial Width-to-Height ratio (fWHR) as a proxy for the personal\/physical traits (&#8220;facial masculinity&#8221;) of executives such as CEOs.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" size-full wp-image-611\" style=\"width: 300px; height: 264px;\" src=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fwhr_example_2_0.png\" alt=\"\" width=\"445\" height=\"391\" srcset=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fwhr_example_2_0.png 445w, https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fwhr_example_2_0-300x264.png 300w\" sizes=\"(max-width: 445px) 100vw, 445px\" \/><\/p>\n<p>There is no perfect definition on what the fWHR captures, but most papers interpret the fWHR to be associated with traits such as aggression, risk-seeking, and egocentrism. For a more comprehensive discussion I recommend reading Lefevre, et al. (2013) and Jia, van Lent, and Zeng (2014), available here:<\/p>\n<p><a href=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/www.larspenke.eu_pdfs_Lefevre_Lewis_Perrett_Penke_in_press_-_fWHR_and_reactive_T.pdf\">http:\/\/www.larspenke.eu\/pdfs\/Lefevre_Lewis_Perrett_Penke_in_press_-_fWHR_and_reactive_T.pdf<\/a><\/p>\n<p><a href=\"http:\/\/onlinelibrary.wiley.com\/doi\/10.1111\/1475-679X.12065\/abstract\">http:\/\/onlinelibrary.wiley.com\/doi\/10.1111\/1475-679X.12065\/abstract<\/a><\/p>\n<p><span style=\"font-size: 18px;\"><strong>How do these papers calculate the fWHR?<\/strong><\/span><\/p>\n<p>The common procedure to calculate the fWHR is to manually determine the bizygomatic width and the upper-face height based on a picture of the person. This procedure has several difficulties:<\/p>\n<ol>\n<li>Manual calculation is very labor intensive leading to small samples sizes. This is especially problematic if cross-validation is desired as multiple raters need to calculate the fWHR for the same picture.<\/li>\n<li>There are multiple definitions available as to what the correct points of the face are that need to be used to calculate the fWHR. For example, some papers determine the upper horizontal line by placing it below the eyebrows, whereas other papers place it above the eyebrows.<\/li>\n<li>The calculated fWHR is sensitive to misalignment of the face in the picture, calculating the fWHR of one person based on multiple images in different scenarios is likely to result in different values for the fWHR. In a real-life scenario, it is preferred to use multiple images of the same person, and aggregate the calculated fWHR to yield one fWHR for each person. This procedure is largely unfeasible if the fWHR is calculated manually because it substantially increases the amount of labor per observation.<\/li>\n<\/ol>\n<p><span style=\"font-size: 18px;\"><strong>Automatically calculate the fWHR using Python<\/strong><\/span><\/p>\n<p><span style=\"font-size: 16px;\"><u>Step 1: face and facial feature recognition\u00a0<\/u><\/span><\/p>\n<p>The first step to be able to automatically calculate the fWHR is to detect the face and facial features required to determine the corners of the &#8220;fWHR box&#8221;.<\/p>\n<p>Recent developments in machine learning have greatly advanced our ability to use trained algorithms to detect faces (&#8220;face recognition&#8221;) and to automatically find facial features such as the eyes, mouth, and nose.<\/p>\n<p>One recent Python packages (named &#8220;Face Recognition&#8221;) in particular has received a lot of attention because it provides an easy-to-use higher level interface build on the state-of-the-art dlib face recognition algorithm build using deep learning. The dlib algorithm is able to detect faces in pictures with an impressive 99.38% benchmark accuracy. Both can be found at the following links:<\/p>\n<p><a href=\"https:\/\/github.com\/ageitgey\/face_recognition\">https:\/\/github.com\/ageitgey\/face_recognition<\/a>,\u00a0<a href=\"http:\/\/dlib.net\/\">http:\/\/dlib.net\/<\/a><\/p>\n<p>The &#8220;Face Recognition&#8221; package allows us to identify faces and to get the locations and outlines of each person&#8217;s eyes, nose, mouth and chin:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" size-full wp-image-613\" style=\"width: 400px; height: 291px;\" src=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_1.png\" alt=\"\" width=\"571\" height=\"416\" srcset=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_1.png 571w, https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_1-300x219.png 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/p>\n<p><u style=\"font-size: 16px;\">Step 2: calculate the fWHR<\/u><\/p>\n<p>I have created a Jupyter Notebook containing experimental code that will use the &#8220;Face Recognition&#8221; package to automatically calculate the fWHR.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" size-full wp-image-614\" style=\"width: 400px; height: 220px;\" src=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_2.png\" alt=\"\" width=\"848\" height=\"467\" srcset=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_2.png 848w, https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_2-300x165.png 300w, https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_2-768x423.png 768w\" sizes=\"(max-width: 848px) 100vw, 848px\" \/><\/p>\n<p>As provided it has the following features:<\/p>\n<ol>\n<li>Images can be entered through a URL or by providing the path to a local image<\/li>\n<li>Using the <em>top<\/em> argument it is possible to use the <em>eyelid<\/em> or <em>eyebrow<\/em> as point for the top line<\/li>\n<li>By default it will show the box used to calculate the fWHR ratio, this is controlled by the <em>show<\/em> argument<\/li>\n<li>It will use the different facial characteristics to determine whether a picture is unsuitable for calculating the fWHR, allowing to automatically feed multiple images without pre-classifying them as suitable:<img decoding=\"async\" loading=\"lazy\" class=\" size-full wp-image-615\" style=\"width: 400px; height: 187px;\" src=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_3.png\" alt=\"\" width=\"964\" height=\"450\" srcset=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_3.png 964w, https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_3-300x140.png 300w, https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_3-768x359.png 768w\" sizes=\"(max-width: 964px) 100vw, 964px\" \/><\/li>\n<\/ol>\n<p><span style=\"font-size: 18px;\"><strong>The code is available on GitHub:<\/strong><\/span><\/p>\n<p><a href=\"https:\/\/github.com\/TiesdeKok\/fWHR_calculator\">https:\/\/github.com\/TiesdeKok\/fWHR_calculator<\/a><\/p>\n<p><a href=\"https:\/\/nbviewer.jupyter.org\/github\/TiesdeKok\/fWHR_calculator\/blob\/master\/FWHR_calculator.ipynb\">https:\/\/nbviewer.jupyter.org\/github\/TiesdeKok\/fWHR_calculator\/blob\/master\/FWHR_calculator.ipynb<\/a><\/p>\n<p><span style=\"font-size: 18px;\"><strong>How does it work?<\/strong><\/span><\/p>\n<p>The &#8220;Face Recognition&#8221; package determines the following points &#8220;under the hood&#8221;:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" size-full wp-image-616\" style=\"width: 300px; height: 273px;\" src=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_4.png\" alt=\"\" width=\"435\" height=\"396\" srcset=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_4.png 435w, https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_4-300x273.png 300w\" sizes=\"(max-width: 435px) 100vw, 435px\" \/><\/p>\n<p>My codes uses these points to determine the different corner points of the fWHR box:<\/p>\n<p><em>Note, this code requires the &#8220;Face Recognition&#8221; package which currently only works on UNIX systems.<\/em><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" size-full wp-image-617\" style=\"width: 700px; height: 466px;\" src=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_5.png\" alt=\"\" width=\"1167\" height=\"777\" srcset=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_5.png 1167w, https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_5-300x200.png 300w, https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_5-1024x682.png 1024w, https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_5-768x511.png 768w\" sizes=\"(max-width: 1167px) 100vw, 1167px\" \/><\/p>\n<p>Once the corner points have been determined, it is a matter of performing a basic calculation to get the fWHR:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" size-full wp-image-618\" style=\"width: 400px; height: 125px;\" src=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_6.png\" alt=\"\" width=\"598\" height=\"187\" srcset=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_6.png 598w, https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fr_code_6-300x94.png 300w\" sizes=\"(max-width: 598px) 100vw, 598px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is a rise of papers that calculate the Facial Width-to-Height ratio (fWHR) as a proxy for the personal\/physical traits (&#8220;facial masculinity&#8221;) of executives such as CEOs. There is no perfect definition on what the fWHR captures, but most papers interpret the fWHR to be associated with traits such as aggression, risk-seeking, and egocentrism. For [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":620,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[125],"tags":[4],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.12 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Use Python to calculate the facial width to height ratio (fWHR) - ARC<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Use Python to calculate the facial width to height ratio (fWHR) - ARC\" \/>\n<meta property=\"og:description\" content=\"There is a rise of papers that calculate the Facial Width-to-Height ratio (fWHR) as a proxy for the personal\/physical traits (&#8220;facial masculinity&#8221;) of executives such as CEOs. There is no perfect definition on what the fWHR captures, but most papers interpret the fWHR to be associated with traits such as aggression, risk-seeking, and egocentrism. For [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eaa-online.org\/arc\/blog\/2017\/11\/22\/use-python-calculate-facial-width-height-ratio-fwhr\/\" \/>\n<meta property=\"og:site_name\" content=\"ARC\" \/>\n<meta property=\"article:published_time\" content=\"2017-11-22T14:42:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-17T13:23:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fwhr_example.png\" \/>\n\t<meta property=\"og:image:width\" content=\"445\" \/>\n\t<meta property=\"og:image:height\" content=\"391\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ties de Kok\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ties de Kok\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eaa-online.org\/arc\/blog\/2017\/11\/22\/use-python-calculate-facial-width-height-ratio-fwhr\/\",\"url\":\"https:\/\/eaa-online.org\/arc\/blog\/2017\/11\/22\/use-python-calculate-facial-width-height-ratio-fwhr\/\",\"name\":\"Use Python to calculate the facial width to height ratio (fWHR) - ARC\",\"isPartOf\":{\"@id\":\"https:\/\/eaa-online.org\/arc\/#website\"},\"datePublished\":\"2017-11-22T14:42:07+00:00\",\"dateModified\":\"2022-10-17T13:23:03+00:00\",\"author\":{\"@id\":\"https:\/\/eaa-online.org\/arc\/#\/schema\/person\/22bbbc46473ac498a1a1015c02482474\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eaa-online.org\/arc\/blog\/2017\/11\/22\/use-python-calculate-facial-width-height-ratio-fwhr\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/eaa-online.org\/arc\/#website\",\"url\":\"https:\/\/eaa-online.org\/arc\/\",\"name\":\"ARC\",\"description\":\"Advanced Resources Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/eaa-online.org\/arc\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/eaa-online.org\/arc\/#\/schema\/person\/22bbbc46473ac498a1a1015c02482474\",\"name\":\"Ties de Kok\",\"sameAs\":[\"https:\/\/www.tiesdekok.com\"],\"url\":\"https:\/\/eaa-online.org\/arc\/blog\/members\/10\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Use Python to calculate the facial width to height ratio (fWHR) - ARC","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Use Python to calculate the facial width to height ratio (fWHR) - ARC","og_description":"There is a rise of papers that calculate the Facial Width-to-Height ratio (fWHR) as a proxy for the personal\/physical traits (&#8220;facial masculinity&#8221;) of executives such as CEOs. There is no perfect definition on what the fWHR captures, but most papers interpret the fWHR to be associated with traits such as aggression, risk-seeking, and egocentrism. For [&hellip;]","og_url":"https:\/\/eaa-online.org\/arc\/blog\/2017\/11\/22\/use-python-calculate-facial-width-height-ratio-fwhr\/","og_site_name":"ARC","article_published_time":"2017-11-22T14:42:07+00:00","article_modified_time":"2022-10-17T13:23:03+00:00","og_image":[{"width":445,"height":391,"url":"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fwhr_example.png","type":"image\/png"}],"author":"Ties de Kok","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ties de Kok","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/eaa-online.org\/arc\/blog\/2017\/11\/22\/use-python-calculate-facial-width-height-ratio-fwhr\/","url":"https:\/\/eaa-online.org\/arc\/blog\/2017\/11\/22\/use-python-calculate-facial-width-height-ratio-fwhr\/","name":"Use Python to calculate the facial width to height ratio (fWHR) - ARC","isPartOf":{"@id":"https:\/\/eaa-online.org\/arc\/#website"},"datePublished":"2017-11-22T14:42:07+00:00","dateModified":"2022-10-17T13:23:03+00:00","author":{"@id":"https:\/\/eaa-online.org\/arc\/#\/schema\/person\/22bbbc46473ac498a1a1015c02482474"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eaa-online.org\/arc\/blog\/2017\/11\/22\/use-python-calculate-facial-width-height-ratio-fwhr\/"]}]},{"@type":"WebSite","@id":"https:\/\/eaa-online.org\/arc\/#website","url":"https:\/\/eaa-online.org\/arc\/","name":"ARC","description":"Advanced Resources Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eaa-online.org\/arc\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/eaa-online.org\/arc\/#\/schema\/person\/22bbbc46473ac498a1a1015c02482474","name":"Ties de Kok","sameAs":["https:\/\/www.tiesdekok.com"],"url":"https:\/\/eaa-online.org\/arc\/blog\/members\/10\/"}]}},"jetpack_featured_media_url":"https:\/\/eaa-online.org\/app\/uploads\/sites\/3\/2017\/11\/fwhr_example.png","_links":{"self":[{"href":"https:\/\/eaa-online.org\/arc\/wp-json\/wp\/v2\/posts\/619"}],"collection":[{"href":"https:\/\/eaa-online.org\/arc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eaa-online.org\/arc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eaa-online.org\/arc\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/eaa-online.org\/arc\/wp-json\/wp\/v2\/comments?post=619"}],"version-history":[{"count":1,"href":"https:\/\/eaa-online.org\/arc\/wp-json\/wp\/v2\/posts\/619\/revisions"}],"predecessor-version":[{"id":3964,"href":"https:\/\/eaa-online.org\/arc\/wp-json\/wp\/v2\/posts\/619\/revisions\/3964"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eaa-online.org\/arc\/wp-json\/wp\/v2\/media\/620"}],"wp:attachment":[{"href":"https:\/\/eaa-online.org\/arc\/wp-json\/wp\/v2\/media?parent=619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eaa-online.org\/arc\/wp-json\/wp\/v2\/categories?post=619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eaa-online.org\/arc\/wp-json\/wp\/v2\/tags?post=619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}