{"id":15659708,"url":"https://github.com/rayraegah/dhash","last_synced_at":"2025-05-05T19:44:11.910Z","repository":{"id":119164276,"uuid":"175535893","full_name":"Rayraegah/dhash","owner":"Rayraegah","description":"Perceptual hashing algorithm (dhash) to find similar images","archived":false,"fork":false,"pushed_at":"2019-06-06T02:43:11.000Z","size":4,"stargazers_count":25,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T23:11:09.492Z","etag":null,"topics":["dhash","image-comparison","image-processing","karmadecay","reddit-bot"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rayraegah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-14T02:44:05.000Z","updated_at":"2025-02-11T03:47:10.000Z","dependencies_parsed_at":"2023-07-10T01:51:32.482Z","dependency_job_id":null,"html_url":"https://github.com/Rayraegah/dhash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rayraegah%2Fdhash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rayraegah%2Fdhash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rayraegah%2Fdhash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rayraegah%2Fdhash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rayraegah","download_url":"https://codeload.github.com/Rayraegah/dhash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252564105,"owners_count":21768589,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dhash","image-comparison","image-processing","karmadecay","reddit-bot"],"created_at":"2024-10-03T13:18:18.865Z","updated_at":"2025-05-05T19:44:11.863Z","avatar_url":"https://github.com/Rayraegah.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Perceptual hashing algorithm\n\nPerceptual hashing algorithm is a general term for a class of algorithms, including `aHash`, `pHash`, and `dHash`. As the name suggests, perceptual hashing does not calculate hash values ​​in a strict way, but rather computes hash values ​​in a more relative way, because \"similarity\" or not is a relative decision.\n\n| **algorithm** |       **hash**        | **speed** | **accuracy** |\n| :-----------: | :-------------------: | :-------: | :----------: |\n|     aHash     |     average hash      |   fast    |     low      |\n|     pHash     |    perceived hash     |   slow    |     high     |\n|     dHash     | difference value hash |   high    |     high     |\n\n## Difference value hash (dHash)\n\nSteps to compare images with dHash algorithm\n\n1.  The fastest way to remove high frequencies and detail is to shrink the image. 72 pixels works best, so 9x8 is ideal dimensions\n\n2.  Reduce the color of the image. Convert the image to a grayscale picture. This changes the hash from 72 pixels to a total of 72 colors.\n\n3.  Compute the difference. The dHash algorithm works on the difference between adjacent pixels. This identifies the relative gradient direction. In this case, the 9 pixels per row yields 8 differences between adjacent pixels. Eight rows of eight differences becomes 64 bits.\n\n4.  Assign bits. Each bit is simply set based on whether the left pixel is brighter than the right pixel. The order does not matter.\n\nIf the Hamming distance is less than 5, it is the same image.\n\n### Usage\n\nI use dHash algorithms to find reposts in the subreddits I moderate.\n\ncalculate the dHash value of an image\n\n```python\nhash = dhash.calculate_hash(image)\n```\n\ncalculate the hamming distance between two images\n\n```python\nhamming_distance = dhash.hamming_distance(image1, image2)\n```\n\ncalculate the hamming distance between two dHash values\n\n```python\nhamming_distance = dhash.hamming_distance(dHash1, dHash2)\n```\n\n## License\n\ndhash.py is released under MIT license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frayraegah%2Fdhash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frayraegah%2Fdhash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frayraegah%2Fdhash/lists"}