{"id":76,"date":"2017-11-02T13:40:03","date_gmt":"2017-11-02T13:40:03","guid":{"rendered":"http:\/\/paradysz.pl\/?p=76"},"modified":"2018-11-23T22:08:54","modified_gmt":"2018-11-23T22:08:54","slug":"perceptual-hashing","status":"publish","type":"post","link":"https:\/\/paradysz.pl\/index.php\/2017\/11\/02\/perceptual-hashing\/","title":{"rendered":"Perceptual Hashing"},"content":{"rendered":"<p style=\"text-align: justify;\">Perceptual hashing? Has anyone ever heard about it? Not many people, I think, although it&#8217;s a really interesting and useful algorithm. Before I get to the point I strongly recommend reading the following terms which can help you with understanding the Perceptual Hashing algorithm implementation:<\/p>\n<ol>\n<li>Hash function<\/li>\n<li>Average\u00a0hashing<\/li>\n<li>Hamming distance<\/li>\n<li>Discrete cosine transform<\/li>\n<\/ol>\n<p style=\"text-align: justify;\">Perceptual Hashing is an algorithm which converts various forms of multimedia (i.e. video, audio, image) to a hash format. The most important difference between a common hash function is the fact that during the execution of the Perceptual Hash function for two very similar input hashes will be very\u00a0close to each other in contrast to the usual hash function. This property is to be applied to finding cases online of copyright infringement. Additionally, the algorithm is resistance to simple modifications like shifts, rotations or noises which can be considered a way to calculate image\u00a0similarity in some cases.<\/p>\n<p><strong>Perceptual Hashing algorithm steps for images:<\/strong><\/p>\n<ol>\n<li>Image scaling<br \/>\nReduce original image to small size e.g 32&#215;32 px using one of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Image_scaling\">scaling algorithm.<br \/>\n<\/a><br \/>\n<img loading=\"lazy\" class=\"aligncenter wp-image-86 size-medium\" src=\"http:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-1-300x129.png\" alt=\"\" width=\"300\" height=\"129\" srcset=\"https:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-1-300x129.png 300w, https:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-1.png 578w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/li>\n<li>Greyscale transformation<br \/>\nTransform the reduced image to a grey scale using one of the\u00a0<a href=\"http:\/\/www.tannerhelland.com\/3643\/grayscale-image-algorithm-vb6\/\">greyscale conversion method.<br \/>\n<\/a><br \/>\n<img loading=\"lazy\" class=\"aligncenter size-medium wp-image-88\" src=\"http:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-2-300x37.png\" alt=\"\" width=\"300\" height=\"37\" srcset=\"https:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-2-300x37.png 300w, https:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-2.png 556w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/li>\n<li style=\"text-align: justify;\">Discrete cosine transform<br \/>\nKey step. The previous step causes each pixel to be represented as one value, hence, the image can be represented as a two-dimensional matrix. So now we can compute the DCT of the image following <a href=\"https:\/\/en.wikipedia.org\/wiki\/JPEG#Discrete_cosine_transform\">Wikipedia\u00a0description<\/a>.<img loading=\"lazy\" class=\"aligncenter wp-image-101 size-full\" src=\"http:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-3.png\" alt=\"\" width=\"1011\" height=\"217\" srcset=\"https:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-3.png 1011w, https:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-3-300x64.png 300w, https:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-3-768x165.png 768w\" sizes=\"(max-width: 1011px) 100vw, 1011px\" \/><\/li>\n<li>Left-top block<br \/>\nTake the 8&#215;8 (this parameter can be changed) left-top block of output from the previous step.<img loading=\"lazy\" class=\"aligncenter wp-image-102 size-medium\" src=\"http:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-4-300x208.png\" alt=\"\" width=\"300\" height=\"208\" srcset=\"https:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-4-300x208.png 300w, https:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-4.png 595w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/li>\n<li>Calculate average<br \/>\nFrom the block taken earlier, calculate the average\u00a0of all values skipping the first one.<br \/>\n<img loading=\"lazy\" class=\"aligncenter size-medium wp-image-105\" src=\"http:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-5-300x186.png\" alt=\"\" width=\"300\" height=\"186\" srcset=\"https:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-5-300x186.png 300w, https:\/\/paradysz.pl\/wp-content\/uploads\/2018\/02\/PH-5.png 376w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/li>\n<li style=\"text-align: justify;\">Calculate the bits<br \/>\nTake the output matrix from step 4 and the average\u00a0from step 5. Next, set the bits in the following way: if the value is greater then the calculated\u00a0average in the previous step then set 1 if less than 0.<\/li>\n<li>Create hash<br \/>\nCalculated bit sequence can convert to Big Endian system.<\/li>\n<\/ol>\n<p style=\"text-align: justify;\">To sum up, Perceptual\u00a0Hashing is a very interesting algorithm which can be used in many various cases, not only for copyright infringement. I recommend tweaking it and keeping in mind when you run into an image similarity problem.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Perceptual hashing? Has anyone ever heard about it? Not many people, I think, although it&#8217;s a really interesting and useful algorithm. Before I get to the point I strongly recommend reading the following terms which can help you with understanding the Perceptual Hashing algorithm implementation: Hash function Average\u00a0hashing Hamming distance Discrete cosine transform Perceptual Hashing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":281,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,4],"tags":[],"_links":{"self":[{"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/posts\/76"}],"collection":[{"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":25,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":165,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/posts\/76\/revisions\/165"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/media\/281"}],"wp:attachment":[{"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}