{"id":24370625,"url":"https://github.com/pgrho/phash","last_synced_at":"2026-01-22T02:35:31.874Z","repository":{"id":65414039,"uuid":"75841106","full_name":"pgrho/phash","owner":"pgrho","description":"C# Implementation of pHash","archived":false,"fork":false,"pushed_at":"2022-12-07T18:38:04.000Z","size":1912,"stargazers_count":79,"open_issues_count":2,"forks_count":11,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-12-06T01:49:38.500Z","etag":null,"topics":["phash"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pgrho.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}},"created_at":"2016-12-07T13:59:06.000Z","updated_at":"2025-11-17T08:11:57.000Z","dependencies_parsed_at":"2023-01-24T20:30:14.342Z","dependency_job_id":null,"html_url":"https://github.com/pgrho/phash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pgrho/phash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgrho%2Fphash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgrho%2Fphash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgrho%2Fphash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgrho%2Fphash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgrho","download_url":"https://codeload.github.com/pgrho/phash/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgrho%2Fphash/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28651809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["phash"],"created_at":"2025-01-19T04:42:04.874Z","updated_at":"2026-01-22T02:35:31.859Z","avatar_url":"https://github.com/pgrho.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# priHash #\n\nC# Implementation of pHash (\u003chttp://phash.org\u003e).\nBased on phash-0.9.4 for Windows.\n\n## NuGet packages ##\n\n- [Shipwreck.Phash](https://www.nuget.org/packages/Shipwreck.Phash/) - C# Implementation of phash-0.9.4.\n\nThe `Shipwreck.Phash` accepts only `IByteImage` interface. The package does not contain any method to load an image.\nSo additional packages provide extension methods to instantiate `ByteImage`\n\n- [Shipwreck.Phash.Bitmaps](https://www.nuget.org/packages/Shipwreck.Phash.Bitmaps/) - for System.Drawing.dll including Mono implementation.\n- [Shipwreck.Phash.PresentationCore](https://www.nuget.org/packages/Shipwreck.Phash.PresentationCore/) - for PresentationCore.dll. Used for WPF, ASP.NET or Windows Service.\n\nThere are some more packages for uncommon usage.\n\n- [Shipwreck.Phash.Data](https://www.nuget.org/packages/Shipwreck.Phash.Data/) - Provides Stored Function Implementations for pHash Digests\n- [Shipwreck.Phash.CrossCorrelation](https://www.nuget.org/packages/Shipwreck.Phash.CrossCorrelation/) - C# Implementation of phash-0.9.4 that provides Only GetCrossCorrelation functionality. Intended to be referenced from SQL CLR.\n\n## Compatibility Notice ##\n\nFollowing methods contains breaking changes at versions below.\n Hashes computed by older versions cannot be compared with the new one:\n\n- `ImagePhash.ComputeDctHash`: at `0.5.0`.\n\n## Hashing an image (Bitmap) ##\n\n```C#\nvar bitmap = (Bitmap)Image.FromFile(fullPathToImage);\nvar hash = ImagePhash.ComputeDigest(bitmap.ToLuminanceImage());\n```\n\n## Hashing an image (BitmapSource) ##\n\n```C#\nvar bitmapSource = BitmapFrame.Create(stream);\nvar hash = ImagePhash.ComputeDigest(bitmapSource.ToLuminanceImage());\n```\n\n## Image similarity score ##\n\n```C#\nvar score = ImagePhash.GetCrossCorrelation(hash1, hash2);\n```\n\n## Multithreaded hashing of all images in a folder ##\n\nExample below required .NET 4.7+ since the function returns a tuple of results.\n\n```C#\npublic static (ConcurrentDictionary\u003cstring, Digest\u003e filePathsToHashes, ConcurrentDictionary\u003cDigest, HashSet\u003cstring\u003e\u003e hashesToFiles) GetHashes(string dirPath, string searchPattern)\n{\n    var filePathsToHashes = new ConcurrentDictionary\u003cstring, Digest\u003e();\n    var hashesToFiles = new ConcurrentDictionary\u003cDigest, HashSet\u003cstring\u003e\u003e();\n\n    var files = Directory.GetFiles(dirPath, searchPattern);\n\n    Parallel.ForEach(files, (currentFile) =\u003e\n    {\n        var bitmap = (Bitmap)Image.FromFile(currentFile);\n        var hash = ImagePhash.ComputeDigest(bitmap);\n        filePathsToHashes[currentFile] = hash;\n\n        HashSet\u003cstring\u003e currentFilesForHash;\n\n        lock (hashesToFiles)\n        {\n            if (!hashesToFiles.TryGetValue(hash, out currentFilesForHash))\n            {\n                currentFilesForHash = new HashSet\u003cstring\u003e();\n                hashesToFiles[hash] = currentFilesForHash;\n            }\n        }\n\n        lock (currentFilesForHash)\n        {\n            currentFilesForHash.Add(currentFile);\n        }\n    });\n\n    return (filePathsToHashes, hashesToFiles);\n}\n```\n\nThen you can call it like this:\n\n```C#\n(ConcurrentDictionary\u003cstring, Digest\u003e gilePathsToHashes, ConcurrentDictionary\u003cDigest, HashSet\u003cstring\u003e\u003e hashesToFiles) =\n    GetHashes(\n        dirPath: @\"C:\\some\\path\\\",\n        searchPattern: \"*.jpg\");\n```\n\n## TestApp ##\n\nDownload Image sets from \u003chttp://phash.org/download/\u003e and extract into the `/data/compr`, `/data/blur`, `/data/rotd`, `/data/misc` directories.\nOr you can create test Image sets by yourself.\n\n## License ##\n\nGNU General Public License version 3 or later\n\u003chttp://www.gnu.org/licenses/\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgrho%2Fphash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgrho%2Fphash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgrho%2Fphash/lists"}